"src/led_effects.cpp" did not exist on "443cf3bffb0875f1516b3bee2fe68e60cefce418"
Commit bea0bc87 authored by Eric Duminil's avatar Eric Duminil
Browse files

define Bundesland

parent fddcc0d1
...@@ -13,9 +13,13 @@ import random ...@@ -13,9 +13,13 @@ import random
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from pathlib import Path from pathlib import Path
from citygml_download import CityGMLWithHash, download_all_files, download_file, SCRIPT_DIR, TMP_DIR from citygml_download import TMP_DIR, Bundesland, CityGMLWithHash, download_all_files, download_file
BAYERN_METALINK = "https://geodaten.bayern.de/odd/a/lod2/citygml/meta/metalink/09.meta4" BAYERN = Bundesland(
"Bayern",
source="https://geodaten.bayern.de/odd/a/lod2/citygml/meta/metalink/09.meta4",
info="https://www.ldbv.bayern.de/",
)
def download_metalink(metalink_url: str, tmp_path: Path = TMP_DIR) -> Path: def download_metalink(metalink_url: str, tmp_path: Path = TMP_DIR) -> Path:
...@@ -27,7 +31,7 @@ def download_metalink(metalink_url: str, tmp_path: Path = TMP_DIR) -> Path: ...@@ -27,7 +31,7 @@ def download_metalink(metalink_url: str, tmp_path: Path = TMP_DIR) -> Path:
return metalink_path return metalink_path
def parse_metalink(metalink_path: Path, download_dir: Path) -> list[CityGMLWithHash]: def parse_metalink(metalink_path: Path, bundesland: Bundesland) -> list[CityGMLWithHash]:
"""Parse metalink XML file and return CityGMLWithHash objects.""" """Parse metalink XML file and return CityGMLWithHash objects."""
print(f"Parsing metalink file: {metalink_path}") print(f"Parsing metalink file: {metalink_path}")
tree = ET.parse(metalink_path) tree = ET.parse(metalink_path)
...@@ -58,10 +62,8 @@ def parse_metalink(metalink_path: Path, download_dir: Path) -> list[CityGMLWithH ...@@ -58,10 +62,8 @@ def parse_metalink(metalink_path: Path, download_dir: Path) -> list[CityGMLWithH
files.append( files.append(
CityGMLWithHash( CityGMLWithHash(
url=url, url=url,
path=download_dir / filename,
coordinate_reference_system="EPSG:25832", coordinate_reference_system="EPSG:25832",
source="https://geodaten.bayern.de", bundesland=bundesland,
bundesland="Bayern",
expected_sha256=hash_node.text, expected_sha256=hash_node.text,
) )
) )
...@@ -70,13 +72,9 @@ def parse_metalink(metalink_path: Path, download_dir: Path) -> list[CityGMLWithH ...@@ -70,13 +72,9 @@ def parse_metalink(metalink_path: Path, download_dir: Path) -> list[CityGMLWithH
if __name__ == "__main__": if __name__ == "__main__":
# Should be from CityGML
download_dir = SCRIPT_DIR / "citygml" / "bayern"
download_dir.mkdir(parents=True, exist_ok=True) metalink_path = download_metalink(BAYERN.source)
citygmls = parse_metalink(metalink_path, BAYERN)
metalink_path = download_metalink(BAYERN_METALINK)
citygmls = parse_metalink(metalink_path, download_dir)
# Download all files # Download all files
download_all_files(citygmls) download_all_files(citygmls)
...@@ -18,6 +18,7 @@ from urllib.request import urlopen ...@@ -18,6 +18,7 @@ from urllib.request import urlopen
SCRIPT_DIR = Path(__file__).resolve().parent SCRIPT_DIR = Path(__file__).resolve().parent
TMP_DIR = SCRIPT_DIR / "tmp" TMP_DIR = SCRIPT_DIR / "tmp"
DOWNLOAD_DIR = SCRIPT_DIR / "citygml"
TMP_DIR.mkdir(parents=True, exist_ok=True) TMP_DIR.mkdir(parents=True, exist_ok=True)
...@@ -74,6 +75,21 @@ def download_file(url: str, dest_path: Path, sleep: int = 0, chunk_size: int = 8 ...@@ -74,6 +75,21 @@ def download_file(url: str, dest_path: Path, sleep: int = 0, chunk_size: int = 8
return False return False
@dataclass
class Bundesland:
name: str
source: str ="Unknown"
info: str ="Unknown"
license: str = "CC BY 4.0."
def __post_init__(self):
self.download_folder.mkdir(parents=True, exist_ok=True)
@property
def download_folder(self) -> Path:
return DOWNLOAD_DIR / self.name.lower().replace("-", "_").replace("ü", "ue")
@dataclass @dataclass
class CityGML(ABC): class CityGML(ABC):
""" """
...@@ -84,11 +100,16 @@ class CityGML(ABC): ...@@ -84,11 +100,16 @@ class CityGML(ABC):
""" """
url: str url: str
path: Path bundesland: Bundesland
bundesland: str
coordinate_reference_system: str = "Unknown" coordinate_reference_system: str = "Unknown"
source: str = "Unknown"
license: str = "CC BY 4.0." @property
def download_folder(self) -> Path:
return self.bundesland.download_folder
@property
def path(self) -> Path:
return self.download_folder / self.filename
@property @property
def filename(self) -> str: def filename(self) -> str:
...@@ -180,7 +201,6 @@ class CityGML(ABC): ...@@ -180,7 +201,6 @@ class CityGML(ABC):
if self.verify(tmp_path): if self.verify(tmp_path):
# Move to final location # Move to final location
self.path.parent.mkdir(parents=True, exist_ok=True)
tmp_path.rename(self.path) tmp_path.rename(self.path)
print(f"✓ {self.filename} downloaded and verified successfully") print(f"✓ {self.filename} downloaded and verified successfully")
return True return True
......
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