This commit is contained in:
2026-05-11 04:38:44 +03:30
parent 17628f503f
commit c2b6052e5c
69 changed files with 3073 additions and 57 deletions
+22 -2
View File
@@ -411,8 +411,7 @@ def build_spatial_extent(cells: list[AnalysisGridCell]) -> dict[str, float]:
south = None
north = None
for cell in cells:
coordinates = ((cell.geometry or {}).get("coordinates") or [[]])[0]
for lon, lat in coordinates:
for lon, lat in _iter_geometry_lon_lat_pairs(cell.geometry):
west = lon if west is None else min(west, lon)
east = lon if east is None else max(east, lon)
south = lat if south is None else min(south, lat)
@@ -426,6 +425,27 @@ def build_spatial_extent(cells: list[AnalysisGridCell]) -> dict[str, float]:
}
def _iter_geometry_lon_lat_pairs(geometry: dict[str, Any] | None):
geometry = dict(geometry or {})
geometry_type = geometry.get("type")
coordinates = geometry.get("coordinates") or []
if geometry_type == "Polygon":
for ring in coordinates:
for point in ring or []:
if len(point) >= 2:
yield point[0], point[1]
return
if geometry_type == "MultiPolygon":
for polygon in coordinates:
for ring in polygon or []:
for point in ring or []:
if len(point) >= 2:
yield point[0], point[1]
return
def build_empty_metric_payload() -> dict[str, Any]:
return {metric_name: None for metric_name in METRIC_NAMES}