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

Rheinland Pfalz quick test

parent 5322da2d
...@@ -3,4 +3,73 @@ ...@@ -3,4 +3,73 @@
# ©GeoBasis-DE / LVermGeoRP <Jahr des Datenbezugs>, dl-de/by-2-0, www.lvermgeo.rlp.de [Daten bearbeitet] # ©GeoBasis-DE / LVermGeoRP <Jahr des Datenbezugs>, dl-de/by-2-0, www.lvermgeo.rlp.de [Daten bearbeitet]
# {"id":"dl-by-de/2.0","name":"Datenlizenz Deutschland Namensnennung 2.0","url":"https://www.govdata.de/dl-de/by-2-0","quelle":"© GeoBasis-DE / LVermGeoRP<Jahr des Datenbezugs>, dl-de/by-2-0, www.lvermgeo.rlp.de [Daten bearbeitet]"} # {"id":"dl-by-de/2.0","name":"Datenlizenz Deutschland Namensnennung 2.0","url":"https://www.govdata.de/dl-de/by-2-0","quelle":"© GeoBasis-DE / LVermGeoRP<Jahr des Datenbezugs>, dl-de/by-2-0, www.lvermgeo.rlp.de [Daten bearbeitet]"}
import random
import xml.etree.ElementTree as ET
from pathlib import Path
# Metalink https://geobasis-rlp.de/data/geb3dlo/current/meta4/geb3dlo_gml_07.meta4 # Metalink https://geobasis-rlp.de/data/geb3dlo/current/meta4/geb3dlo_gml_07.meta4
from citygml_download import TMP_DIR, Bundesland, CityGMLWithHash, download_all_files, download_file
RHEINLAND_PFALZ = Bundesland(
"Rheinland-Pfalz",
source="https://geobasis-rlp.de/data/geb3dlo/current/meta4/geb3dlo_gml_07.meta4",
info="https://lvermgeo.rlp.de/produktinformationen/geotopografie/3d-geodaten/3d-gebaeudemodell",
)
# TODO: DRY WITH BAYERN!
def download_metalink(metalink_url: str, tmp_path: Path = TMP_DIR) -> Path:
"""Download metalink file to temporary directory."""
print(f"Downloading {metalink_url}")
basename = metalink_url.split("/")[-1] or "metalink.xml"
metalink_path = tmp_path / basename
download_file(metalink_url, metalink_path)
return metalink_path
def parse_metalink(metalink_path: Path, bundesland: Bundesland) -> list[CityGMLWithHash]:
"""Parse metalink XML file and return CityGMLWithHash objects."""
print(f"Parsing metalink file: {metalink_path}")
tree = ET.parse(metalink_path)
root = tree.getroot()
# Handle namespace
ns = {"ml": "urn:ietf:params:xml:ns:metalink"}
files = []
for file_elem in root.findall("ml:file", ns):
filename = file_elem.get("name")
if filename is None:
raise ValueError(f"Not enough information from {file_elem}")
hash_node = file_elem.find('ml:hash[@type="sha-256"]', ns)
if hash_node is None or hash_node.text is None:
raise ValueError(f"{filename} has no sha256")
urls = [url.text for url in file_elem.findall("ml:url", ns) if url.text]
if len(urls) == 0:
raise ValueError(f"No URL for {file_elem}")
else:
# Randomize URL order to distribute load across servers
random.shuffle(urls)
url = urls[0]
files.append(
CityGMLWithHash(
url=url,
coordinate_reference_system="EPSG:25832",
bundesland=bundesland,
expected_sha256=hash_node.text,
)
)
return files
if __name__ == "__main__":
metalink_path = download_metalink(RHEINLAND_PFALZ.source)
citygmls = parse_metalink(metalink_path, RHEINLAND_PFALZ)
# Download all files
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