fix: relation с одним внешним кольцом — Polygon с depth-3 coordinates
Второй баг той же семьи: polygons.append(poly['coordinates'][0]) клал ring на уровень полигона — у relation с ОДНИМ outer member'ом coordinates получались depth-2 ([[pair],...]) при type=Polygon. Это 5 крупнейших водных объектов (Камсамольскае возера и др.) — фронтовый toLatLngs строил [[undefined,undefined]...] → Leaflet 'latlngs[0] undefined' → белый экран страницы анализа. Теперь relation собирает список Polygon'ов (coordinates=[ring]) и: 1 кольцо → отдаётся как Polygon; 2+ → MultiPolygon из polygon.coordinates.
This commit is contained in:
@@ -165,19 +165,23 @@ def _water_geoms(elements: list[dict]) -> list[dict]:
|
||||
poly = _way_to_polygon({'geometry': mg})
|
||||
if poly is None:
|
||||
continue
|
||||
polygons.append(poly['coordinates'][0])
|
||||
# Кладём Polygon целиком (coordinates = [ring]), не сам ring —
|
||||
# иначе у одиночного кольца coordinates получатся depth-2.
|
||||
polygons.append(poly['coordinates'])
|
||||
area, lat, lon = _polygon_centroid_area(mg)
|
||||
areas.append(area)
|
||||
lats.append(lat)
|
||||
lons.append(lon)
|
||||
if not polygons:
|
||||
continue
|
||||
geom = (
|
||||
# GeoJSON MultiPolygon: [[ring0], [ring1]] — каждый полигон = список колец.
|
||||
{'type': 'MultiPolygon', 'coordinates': [[p] for p in polygons]}
|
||||
if len(polygons) > 1 else
|
||||
{'type': 'Polygon', 'coordinates': polygons[0]}
|
||||
)
|
||||
if len(polygons) == 1:
|
||||
geom = polygons[0] # {'type': 'Polygon', 'coordinates': [ring]}
|
||||
else:
|
||||
# GeoJSON MultiPolygon: собираем полигоны в один Multi.
|
||||
geom = {
|
||||
'type': 'MultiPolygon',
|
||||
'coordinates': [p['coordinates'] for p in polygons],
|
||||
}
|
||||
out.append({'layer': layer, 'name': name, 'geom': geom,
|
||||
'area_m2': sum(areas),
|
||||
'lat': sum(lats) / len(lats), 'lon': sum(lons) / len(lons)})
|
||||
|
||||
Reference in New Issue
Block a user