SPlit up
This commit is contained in:
parent
cf39ad754e
commit
f59d01227b
91 changed files with 10370 additions and 7562 deletions
|
|
@ -13,7 +13,7 @@ from pathlib import Path
|
|||
import osmium
|
||||
import polars as pl
|
||||
from pyproj import Transformer
|
||||
from shapely import wkb
|
||||
from shapely import make_valid, wkb
|
||||
from shapely.errors import GEOSException
|
||||
from shapely.geometry import MultiPolygon, Polygon
|
||||
from tqdm import tqdm
|
||||
|
|
@ -56,6 +56,22 @@ def _to_bng_polygon(geom):
|
|||
return geom
|
||||
|
||||
|
||||
def _polygonal_part(geom):
|
||||
"""The Polygon/MultiPolygon content of a geometry, or None if there is none."""
|
||||
if geom.geom_type in ("Polygon", "MultiPolygon"):
|
||||
return geom
|
||||
if geom.geom_type == "GeometryCollection":
|
||||
polygons = []
|
||||
for part in geom.geoms:
|
||||
if part.geom_type == "Polygon":
|
||||
polygons.append(part)
|
||||
elif part.geom_type == "MultiPolygon":
|
||||
polygons.extend(part.geoms)
|
||||
if polygons:
|
||||
return MultiPolygon(polygons)
|
||||
return None
|
||||
|
||||
|
||||
def _matches_tags(tags):
|
||||
"""Check if an OSM element's tags match our greenspace/water criteria."""
|
||||
for key, values in GREENSPACE_TAGS.items():
|
||||
|
|
@ -91,7 +107,13 @@ class GreenspaceHandler(osmium.SimpleHandler):
|
|||
)
|
||||
return
|
||||
|
||||
if geom.is_empty or not geom.is_valid:
|
||||
# Invalid geometries are often the largest, most complex park/water
|
||||
# multipolygons (self-touching rings from OSM) — repair like pois.py
|
||||
# rather than silently dropping them. make_valid may return a
|
||||
# GeometryCollection with stray lines/points; keep only the polygons.
|
||||
if not geom.is_valid:
|
||||
geom = _polygonal_part(make_valid(geom))
|
||||
if geom is None or geom.is_empty:
|
||||
return
|
||||
|
||||
# Reproject to BNG for area calculation
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue