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,61 +35,56 @@ def get_lod2_key(url: str) -> str: ...@@ -44,61 +35,56 @@ 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
KEY = get_lod2_key("https://www.geodaten.sachsen.de/batch-download-4719.html") keep_downloading = True
DOWNLOAD_SERVER = f"https://geocloud.landesvermessung.sachsen.de/public.php/dav/files/{KEY}/" citygmls = []
while keep_downloading: KEY = get_lod2_key("https://www.geodaten.sachsen.de/batch-download-4719.html")
QUERY_PARAMS = { DOWNLOAD_SERVER = f"https://geocloud.landesvermessung.sachsen.de/public.php/dav/files/{KEY}/"
"where": "1=1",
"outFields": "Kachel,Download_CityGML,Stand", while keep_downloading:
"f": "json", query_params = {
"returnGeometry": "false", "where": "1=1",
"resultOffset": current_offset, "outFields": "Kachel,Download_CityGML,Stand",
"resultRecordCount": PAGE_SIZE, "f": "json",
} "returnGeometry": "false",
"resultOffset": current_offset,
"resultRecordCount": PAGE_SIZE,
}
try:
response = requests.get(SACHSEN.source, params=query_params)
response.raise_for_status()
data = response.json()
keep_downloading = data.get("exceededTransferLimit", False)
except requests.exceptions.RequestException as e:
print(f"❌ Error during request at offset {current_offset}: {e}")
break
try: if "features" in data and data["features"]:
response = requests.get(SACHSEN.source, params=QUERY_PARAMS) for feature in data["features"]:
response.raise_for_status() attributes = feature["attributes"]
data = response.json() filename = attributes["Download_CityGML"].split("/")[-1]
keep_downloading = data.get("exceededTransferLimit", False) year = int(attributes["Stand"].split("(")[0])
except requests.exceptions.RequestException as e: citygmls.append(
print(f"❌ Error during request at offset {current_offset}: {e}") CityGMLWithDate(
break url=DOWNLOAD_SERVER + filename,
bundesland=SACHSEN,
if "features" in data and data["features"]: # NOTE: No information is given about month or day, so assume end of year to be sure files get updated
import rich source_date=datetime(year, 12, 31),
# coordinate_reference_system ?
print() )
for feature in data["features"]:
attributes = feature["attributes"]
import rich
rich.print(feature)
filename = attributes["Download_CityGML"].split("/")[-1]
year = int(attributes["Stand"].split("(")[0])
rich.print(feature, filename, year)
citygmls.append(
CityGMLWithDate(
url=DOWNLOAD_SERVER + filename,
bundesland=SACHSEN,
# NOTE: No information is given about month or day, so assume end of year to be sure files get updated
source_date=datetime(year, 12, 31),
# coordinate_reference_system ?
) )
)
break current_offset += PAGE_SIZE
current_offset += PAGE_SIZE
else: else:
if data.get("error"): if data.get("error"):
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