Commit d2e3f935 authored by Eric Duminil's avatar Eric Duminil
Browse files

refactor

parent ea94b15c
# https://www.geodaten.sachsen.de/batch-download-4719.html
# https://geocloud.landesvermessung.sachsen.de/public.php/dav/files/AyJqXpJAZJXomCb/lod2_33278_5590_2_sn_citygml.zip
# https://geodienste.sachsen.de/ags-relay/ArcGISServer/guest/arcgis/rest/services/geosn/rest_geosn_downloadlinks/MapServer/3
import json import json
from datetime import datetime from datetime import datetime
...@@ -15,13 +9,10 @@ SACHSEN = Bundesland( ...@@ -15,13 +9,10 @@ SACHSEN = Bundesland(
"Sachsen", "Sachsen",
source="https://geodienste.sachsen.de/ags-relay/ArcGISServer/guest/arcgis/rest/services/geosn/rest_geosn_downloadlinks/MapServer/3/query", source="https://geodienste.sachsen.de/ags-relay/ArcGISServer/guest/arcgis/rest/services/geosn/rest_geosn_downloadlinks/MapServer/3/query",
info="https://www.geodaten.sachsen.de/", info="https://www.geodaten.sachsen.de/",
license="Landesamt für Geobasisinformation Sachsen (GeoSN), DL-DE->BY-2.0"
) )
PAGE_SIZE = 1000 # Max amount for Sachsen Server PAGE_SIZE = 1000 # Max amount for Sachsen Server
all_tiles = []
current_offset = 0
print(f"Starting paged query to retrieve all tiles (page size: {PAGE_SIZE})...")
def get_lod2_key(url: str) -> str: def get_lod2_key(url: str) -> str:
...@@ -44,14 +35,17 @@ def get_lod2_key(url: str) -> str: ...@@ -44,14 +35,17 @@ def get_lod2_key(url: str) -> str:
return "AyJqXpJAZJXomCb" return "AyJqXpJAZJXomCb"
keep_downloading = True if __name__ == "__main__":
citygmls = [] print(f"Starting paged query to retrieve all tiles (page size: {PAGE_SIZE})...")
current_offset = 0
keep_downloading = True
citygmls = []
KEY = get_lod2_key("https://www.geodaten.sachsen.de/batch-download-4719.html") KEY = get_lod2_key("https://www.geodaten.sachsen.de/batch-download-4719.html")
DOWNLOAD_SERVER = f"https://geocloud.landesvermessung.sachsen.de/public.php/dav/files/{KEY}/" DOWNLOAD_SERVER = f"https://geocloud.landesvermessung.sachsen.de/public.php/dav/files/{KEY}/"
while keep_downloading: while keep_downloading:
QUERY_PARAMS = { query_params = {
"where": "1=1", "where": "1=1",
"outFields": "Kachel,Download_CityGML,Stand", "outFields": "Kachel,Download_CityGML,Stand",
"f": "json", "f": "json",
...@@ -61,7 +55,7 @@ while keep_downloading: ...@@ -61,7 +55,7 @@ while keep_downloading:
} }
try: try:
response = requests.get(SACHSEN.source, params=QUERY_PARAMS) response = requests.get(SACHSEN.source, params=query_params)
response.raise_for_status() response.raise_for_status()
data = response.json() data = response.json()
keep_downloading = data.get("exceededTransferLimit", False) keep_downloading = data.get("exceededTransferLimit", False)
...@@ -71,17 +65,10 @@ while keep_downloading: ...@@ -71,17 +65,10 @@ while keep_downloading:
break break
if "features" in data and data["features"]: if "features" in data and data["features"]:
import rich
print()
for feature in data["features"]: for feature in data["features"]:
attributes = feature["attributes"] attributes = feature["attributes"]
import rich
rich.print(feature)
filename = attributes["Download_CityGML"].split("/")[-1] filename = attributes["Download_CityGML"].split("/")[-1]
year = int(attributes["Stand"].split("(")[0]) year = int(attributes["Stand"].split("(")[0])
rich.print(feature, filename, year)
citygmls.append( citygmls.append(
CityGMLWithDate( CityGMLWithDate(
...@@ -93,7 +80,6 @@ while keep_downloading: ...@@ -93,7 +80,6 @@ while keep_downloading:
) )
) )
break
current_offset += PAGE_SIZE current_offset += PAGE_SIZE
else: else:
...@@ -101,4 +87,4 @@ while keep_downloading: ...@@ -101,4 +87,4 @@ while keep_downloading:
print(f"❌ Error in response: {data['error']['message']}") print(f"❌ Error in response: {data['error']['message']}")
break break
download_all_files(citygmls) download_all_files(citygmls)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment