Commit 608f73c0 authored by Eric Duminil's avatar Eric Duminil
Browse files

Ignore tiles if they are too far away from region

parent a637a2ad
Showing with 13 additions and 5 deletions
+13 -5
......@@ -25,7 +25,9 @@ import zipfile
from pyproj import CRS
from pyproj import Transformer
import shapely
from shapely import wkt
from shapely.ops import transform
from shapely.geometry import Point
# TODO: Write tests
# TODO: Use logging
......@@ -49,6 +51,7 @@ EXTRACT_REGIONS = True
CITYGML_SERVER = "https://opengeodata.lgl-bw.de/data/lod2"
RASTER = 2 # [km]
KILOMETER = 1000 # [m]
BUNDESLAND = 'bw'
# UTM32N, used in BW. https://epsg.io/32632
......@@ -77,8 +80,8 @@ if EXTRACT_REGIONS:
def coordinates_to_grid(longitude: float, latitude: float) -> tuple[int, int]:
"""Returns (x, y) of the tile on CITYGML_SERVER containing a given point."""
x, y = TO_LOCAL_CRS.transform(longitude, latitude)
x = floor(x / 1000) - 1 # Odd x
y = floor(y / 1000) # Even y
x = floor(x / KILOMETER) - 1 # Odd x
y = floor(y / KILOMETER) # Even y
x -= x % RASTER
y -= y % RASTER
return (x + 1, y)
......@@ -106,11 +109,16 @@ def wkt_polygon_to_grid_coords(location_name: str, wkt: str) -> tuple[int, int,
return (x1, x2, y1, y2)
def download_whole_region(output_dir: Path, wkt: str, x1: int, x2: int, y1: int, y2: int) -> None:
def download_whole_region(output_dir: Path, wkt_region: str, x1: int, x2: int, y1: int, y2: int) -> None:
"""Downloads every zip of a given region, to output_dir, and extracts CityGML files."""
# FIXME: Too many uninteresting tiles for complex shapes. Check if the tile is interesecting with the polygon!
wgs84_region = wkt.loads(wkt_region)
local_region = transform(TO_LOCAL_CRS.transform, wgs84_region)
for x in range(x1, x2 + 1, RASTER):
for y in range(y1, y2 + 1, RASTER):
tile_center = Point((x + 1) * KILOMETER, (y + 1) * KILOMETER)
if local_region.distance(tile_center) > RASTER * KILOMETER:
continue
citygml_zip = f"LoD2_{UTM}_{x}_{y}_{RASTER}_{BUNDESLAND}.zip"
citygml_url = f"{CITYGML_SERVER}/{citygml_zip}"
local_zip = output_dir / citygml_zip
......
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