Commit 27896a9c authored by Eric Duminil's avatar Eric Duminil
Browse files

Trying to specify a custom name

parent c477b595
# https://geodaten.schleswig-holstein.de/gaialight-sh/_apps/dladownload/single.php?file=LOD2_SH_Massendownload.geojson&id=4 # https://geodaten.schleswig-holstein.de/gaialight-sh/_apps/dladownload/single.php?file=LOD2_SH_Massendownload.geojson&id=4
import json import json
import re
from datetime import datetime from datetime import datetime
from citygml_download import TMP_DIR, Bundesland, CityGMLWithDate, download_all_files, download_file from citygml_download import TMP_DIR, Bundesland, CityGMLWithDate, download_all_files, download_file
...@@ -13,6 +14,19 @@ SCHLESWIG_HOLSTEIN = Bundesland( ...@@ -13,6 +14,19 @@ SCHLESWIG_HOLSTEIN = Bundesland(
) )
class CityGMLWithCustomName(CityGMLWithDate):
# massen.php?file=LoD2_32_454_6068_1_SH.xml&id=4&live=2023&km=32450_6060
FILENAME_PATTERN = re.compile(r"lod2_.*?\.[xg]ml", re.IGNORECASE)
@property
def filename(self) -> str:
full_filename = super().filename
if m := self.FILENAME_PATTERN.search(full_filename):
short = m.group().replace(".xml", ".gml")
return short
raise ValueError(f"Couldn't recognize filename from {full_filename}")
if __name__ == "__main__": if __name__ == "__main__":
geojson_path = TMP_DIR / f"{SCHLESWIG_HOLSTEIN}.geojson" geojson_path = TMP_DIR / f"{SCHLESWIG_HOLSTEIN}.geojson"
download_file(SCHLESWIG_HOLSTEIN.source, TMP_DIR / geojson_path) download_file(SCHLESWIG_HOLSTEIN.source, TMP_DIR / geojson_path)
...@@ -26,7 +40,7 @@ if __name__ == "__main__": ...@@ -26,7 +40,7 @@ if __name__ == "__main__":
for feature in features: for feature in features:
properties = feature["properties"] properties = feature["properties"]
citygmls.append( citygmls.append(
CityGMLWithDate( CityGMLWithCustomName(
url=properties["link_data"], url=properties["link_data"],
bundesland=SCHLESWIG_HOLSTEIN, bundesland=SCHLESWIG_HOLSTEIN,
source_date=datetime.strptime(properties["datum"], "%Y-%m-%d"), source_date=datetime.strptime(properties["datum"], "%Y-%m-%d"),
......
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