diff --git a/download_files_from_LGL_BW.py b/download_files_from_LGL_BW.py index bbb408b74a1d2dc216fb3d398dda2b44e9d5b25a..98d7d945e5562cf57fcdbfd61563bc72c163f734 100644 --- a/download_files_from_LGL_BW.py +++ b/download_files_from_LGL_BW.py @@ -17,13 +17,13 @@ from pathlib import Path from math import floor import subprocess import re -# pip install pyproj -from pyproj import CRS -from pyproj import Transformer import urllib.request import time import zipfile +from pyproj import CRS +from pyproj import Transformer + ###### User input ########## POLYGONS = { "StuttgartCenter": "POLYGON((9.175287 48.780916, 9.185501 48.777522, 9.181467 48.773704, 9.174429 48.768472, 9.168807 48.773902, 9.175287 48.780916))", @@ -101,12 +101,17 @@ def download_rectangle(output_dir: Path, x1: int, x2: int, y1: int, y2: int) -> print(f" {local_zip.name} already in {output_dir.name}/") else: print(f" Download {citygml_zip} to {output_dir.name}/ ", end='') - urllib.request.urlretrieve(citygml_url, local_zip) - time.sleep(WAIT_BETWEEN_DOWNLOADS) - print("✓") + try: + urllib.request.urlretrieve(citygml_url, local_zip) + except urllib.error.HTTPError as e: + print(f"⌠{e}") + continue + finally: + time.sleep(WAIT_BETWEEN_DOWNLOADS) + print("✅") print(f" Extract {citygml_zip} to {output_dir.name}/ ", end='') - print("✓") + print("✅") print("") with zipfile.ZipFile(local_zip, "r") as zip_ref: zip_ref.extractall(output_dir) @@ -118,9 +123,12 @@ def extract_region(output_dir: Path, location_name: str, wkt: str) -> None: if output_file.exists(): print(f" {output_file} already exists. Not extracting.") return - print(f" Extracting {output_file}.") region_chooser_libs = Path(SIMSTADT_FOLDER).expanduser() / 'lib/*' - gml_inputs = output_dir.glob(GML_GLOB) + gml_inputs = list(output_dir.glob(GML_GLOB)) + if len(gml_inputs) == 0: + print("Error: No CityGML found. At least part of the region should be in Baden-Württemberg!") + return + print(f" Extracting {output_file}.") result = subprocess.run(['java', '-classpath', f'{region_chooser_libs}', 'eu.simstadt.regionchooser.RegionChooserCLI', '--input', ','.join(str(gml) for gml in gml_inputs), @@ -129,7 +137,8 @@ def extract_region(output_dir: Path, location_name: str, wkt: str) -> None: ], input=wkt, text=True, - capture_output=True + capture_output=True, + check=True ) if (result.stderr): print(result.stderr)