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

Don't stop at first download error

parent c500031c
......@@ -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='')
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("")
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)
......
Markdown is supported
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