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
from datetime import datetime
......@@ -15,13 +9,10 @@ SACHSEN = Bundesland(
"Sachsen",
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/",
license="Landesamt für Geobasisinformation Sachsen (GeoSN), DL-DE->BY-2.0"
)
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:
......@@ -44,14 +35,17 @@ def get_lod2_key(url: str) -> str:
return "AyJqXpJAZJXomCb"
keep_downloading = True
citygmls = []
if __name__ == "__main__":
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")
DOWNLOAD_SERVER = f"https://geocloud.landesvermessung.sachsen.de/public.php/dav/files/{KEY}/"
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}/"
while keep_downloading:
QUERY_PARAMS = {
while keep_downloading:
query_params = {
"where": "1=1",
"outFields": "Kachel,Download_CityGML,Stand",
"f": "json",
......@@ -61,7 +55,7 @@ while keep_downloading:
}
try:
response = requests.get(SACHSEN.source, params=QUERY_PARAMS)
response = requests.get(SACHSEN.source, params=query_params)
response.raise_for_status()
data = response.json()
keep_downloading = data.get("exceededTransferLimit", False)
......@@ -71,17 +65,10 @@ while keep_downloading:
break
if "features" in data and data["features"]:
import rich
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(
......@@ -93,7 +80,6 @@ while keep_downloading:
)
)
break
current_offset += PAGE_SIZE
else:
......@@ -101,4 +87,4 @@ while keep_downloading:
print(f"❌ Error in response: {data['error']['message']}")
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