Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • nfdi4earth/edutrain/content/extern/analysis-of-urban-transformation-processes-part-2
1 result
Show changes
Commits on Source (2)
%% Cell type:markdown id:fb053094-8052-4532-bfd1-1bd1dc249d9f tags:
### 📖Flooding in Germany: assessing damage by detecting affected buildings
%% Cell type:markdown id:75d6c38a-3124-42f4-8e3d-e7174d6c02c1 tags:
In this chapter, you will assess the damage of a flood by detecting the affected buildings in the area using the ohsome package.
%% Cell type:code id:24b70612 tags:
``` python
# import necessary packages
from ohsome import OhsomeClient
import pandas as pd
import json
import requests
```
%% Cell type:code id:6c5c26b9-52a6-4a01-8d19-da1955a163f2 tags:
``` python
client = OhsomeClient()
```
%% Cell type:markdown id:37d34fc4 tags:
Use the following code if the data is not stored on your local machine. If you already have it, you can skip this step.
%% Cell type:code id:743e2ef8 tags:
``` python
# You can convert a shapefile to a geojson for example in QGIS
# The AOI Geojson file needs to be a Feature Collection, meaning it contains several Polygons.
# You can also create geojson files with https://geojson.io/#map=2/20.0/0.0
# For more Information about how to use boundaries in ohsome, see : https://docs.ohsome.org/ohsome-api/v1/boundaries.html
# Open the file and extract the content as a string (text)
AOI_path = 'https://git.rwth-aachen.de/nfdi4earth/edutrain/content/extern/analysis-of-urban-transformation-processes-part-2/-/raw/main/Data/Flooding_Germany.geojson?ref_type=heads&inline=false' # Provide the path to your geojson file
response = requests.get(AOI_path)
aoi_json = response.json()
json_aoi_txt = json.dumps(aoi_json)
json_aoi_txt = json.dumps(aoi_json)
print(json_aoi_txt[:500]) # print the first 500 characters of the geojson string
```
%% Output
{"type": "FeatureCollection", "name": "Flooding_Germany_202107_FeatureCollection", "crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}}, "features": [{"type": "Feature", "properties": {"id": 1}, "geometry": {"type": "MultiPolygon", "coordinates": [[[[6.642126184000062, 49.84587318906443], [6.642126184000062, 49.84585135700007], [6.642119816298699, 49.84585135700007], [6.642100365000033, 49.84578466700003], [6.642076571000076, 49.84558003300003], [6.642036353000037, 49
%% Cell type:markdown id:86077ff7 tags:
Alternatively, if you prefer to store the data locally [(download)](https://git.rwth-aachen.de/nfdi4earth/edutrain/content/extern/analysis-of-urban-transformation-processes-part-2/-/raw/main/Data/Flooding_Germany.geojson?ref_type=heads&inline=false) or if you already have it, you can follow the step below:
%% Cell type:code id:42ff8ce7 tags:
``` python
# You can convert a shapefile to a geojson for example in QGIS
# The AOI Geojson file needs to be a Feature Collection, meaning it contains several Polygons.
# You can also create geojson files with https://geojson.io/#map=2/20.0/0.0
# For more Information about how to use boundaries in ohsome, see : https://docs.ohsome.org/ohsome-api/v1/boundaries.html
# Open the file and extract the content as a string (text)
AOI_path= R"path to your geojson file" # Provide the path to your geojson file
with open(AOI_path) as jsonAOI:
aoi_json = json.load(jsonAOI)
json_aoi_txt = json.dumps(aoi_json)
print(json_aoi_txt[:500]) # print the first 500 characters of the geojson string
```
%% Output
{"type": "FeatureCollection", "name": "Flooding_Germany_202107_FeatureCollection", "crs": {"type": "name", "properties": {"name": "urn:ogc:def:crs:OGC:1.3:CRS84"}}, "features": [{"type": "Feature", "properties": {"id": 1}, "geometry": {"type": "MultiPolygon", "coordinates": [[[[6.642126184000062, 49.84587318906443], [6.642126184000062, 49.84585135700007], [6.642119816298699, 49.84585135700007], [6.642100365000033, 49.84578466700003], [6.642076571000076, 49.84558003300003], [6.642036353000037, 49
%% Cell type:markdown id:d97da475 tags:
### 📖Count buildings affected by flooding
%% Cell type:code id:532a11f7 tags:
``` python
# Time of your investigation
time = "2021-06-15"
# Filter for a desired variable
fltr = "building=* and type:way"
response = client.elements.count.post(bpolys=json_aoi_txt, time=time, filter=fltr)
response.as_dataframe()
```
%% Cell type:markdown id:e26b4fd0 tags:
### 📖Download all Buildings in the affected area
%% Cell type:code id:5700244b tags:
``` python
response = client.elements.geometry.post(bpolys=json_aoi_txt, time=time, filter=fltr)
response.to_json("./Affected_buildings.json")
```
File added
This diff is collapsed.
This diff is collapsed.