fix(map): make area analysis scale-aware
This commit is contained in:
@@ -51,17 +51,17 @@ class RasterPartitionAnalysisService:
|
||||
source_name: str,
|
||||
product_key: str,
|
||||
bbox: tuple[float, float, float, float],
|
||||
dataset_ids: list[UUID] | None = None,
|
||||
) -> list[Dataset]:
|
||||
rows = (
|
||||
db.query(Dataset)
|
||||
.filter(
|
||||
Dataset.project_id == project_id,
|
||||
Dataset.source_name == source_name,
|
||||
Dataset.dataset_type == "raster",
|
||||
Dataset.status == "ready",
|
||||
)
|
||||
.all()
|
||||
query = db.query(Dataset).filter(
|
||||
Dataset.project_id == project_id,
|
||||
Dataset.source_name == source_name,
|
||||
Dataset.dataset_type == "raster",
|
||||
Dataset.status == "ready",
|
||||
)
|
||||
if dataset_ids is not None:
|
||||
query = query.filter(Dataset.id.in_(dataset_ids))
|
||||
rows = query.all()
|
||||
candidates = [
|
||||
dataset
|
||||
for dataset in rows
|
||||
@@ -78,6 +78,13 @@ class RasterPartitionAnalysisService:
|
||||
details={"source_name": source_name, "product_key": product_key},
|
||||
status_code=404,
|
||||
)
|
||||
if dataset_ids is not None and {dataset.id for dataset in candidates} != set(dataset_ids):
|
||||
raise AppError(
|
||||
code="RASTER_PARTITION_SOURCE_MISMATCH",
|
||||
message="Every requested raster partition must match the governed source product and selection",
|
||||
details={"requested_count": len(dataset_ids), "eligible_count": len(candidates)},
|
||||
status_code=409,
|
||||
)
|
||||
if len(candidates) > RasterPartitionAnalysisService.MAX_PARTITIONS:
|
||||
raise AppError(
|
||||
code="RASTER_PARTITION_LIMIT_EXCEEDED",
|
||||
@@ -100,6 +107,7 @@ class RasterPartitionAnalysisService:
|
||||
selection_geometry_4326,
|
||||
nodata: float,
|
||||
max_pixels: int,
|
||||
dataset_ids: list[UUID] | None = None,
|
||||
) -> RasterPartitionSelection:
|
||||
try:
|
||||
import numpy as np
|
||||
@@ -120,6 +128,7 @@ class RasterPartitionAnalysisService:
|
||||
source_name=source_name,
|
||||
product_key=product_key,
|
||||
bbox=bbox,
|
||||
dataset_ids=dataset_ids,
|
||||
)
|
||||
transformer = Transformer.from_crs("EPSG:4326", "EPSG:31370", always_xy=True)
|
||||
selection_metric = shapely_transform(transformer.transform, selection_geometry_4326)
|
||||
|
||||
Reference in New Issue
Block a user