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

Allow to specify ZipCodes too

parent b2b2b958
......@@ -25,10 +25,13 @@ import zipfile
from pyproj import CRS
from pyproj import Transformer
from get_coordinates_by_zipcode import get_coordinates_by_zipcode
COORDINATES_REGEX = re.compile(r"(\-?\d+\.\d*) (\-?\d+\.\d*)")
###### User input ##########
POLYGONS = {
# Values can be either a WKT POLYGON or MULTIPOLYGON, a Zipcode, or Zipcodes separated by a comma.
REGIONS = {
"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))",
# "AnotherRegion": "Another WKT Polygon...",
}
......@@ -168,13 +171,27 @@ def extract_region(output_dir: Path, location_name: str, wkt: str) -> None:
print(" DONE!")
def main(polygons: dict[str, str]) -> None:
def get_wkt(wkt_or_zipcode: str) -> str:
"""Returns WKT string for a given region, either specified as a POLYGON, or Zipcode(s).
"POLYGON((...))"
"MULTIPOLYGON(((...)))"
"70567"
"70567,70569"
"""
if 'POLYGON' in wkt_or_zipcode:
return wkt_or_zipcode
else:
return get_coordinates_by_zipcode(wkt_or_zipcode.split(','))
# raise ValueError(f"Unknown region format: {wkt_or_zipcode}")
def main(regions: dict[str, str]) -> None:
"""Downloads ZIP files, extracts CityGML files, and selects desired region."""
for location_name, wkt in polygons.items():
for location_name, wkt_or_zipcode in regions.items():
if ' ' in location_name:
raise ValueError("Location name should not contain spaces: 'Some City' -> 'SomeCity'")
output_dir = SCRIPT_DIR / (location_name + '.proj')
output_dir.mkdir(parents=True, exist_ok=True)
wkt = get_wkt(wkt_or_zipcode)
x1, x2, y1, y2 = wkt_polygon_to_grid_coords(location_name, wkt)
download_rectangle(output_dir, x1, x2, y1, y2)
if EXTRACT_REGIONS:
......@@ -193,4 +210,4 @@ def convert_wkt_to_local(wkt):
if __name__ == '__main__':
main(POLYGONS)
main(REGIONS)
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