diff --git a/backend/src/Service/Ingestion/IngestionService.php b/backend/src/Service/Ingestion/IngestionService.php index e8ba90f..47ac937 100644 --- a/backend/src/Service/Ingestion/IngestionService.php +++ b/backend/src/Service/Ingestion/IngestionService.php @@ -222,19 +222,23 @@ class IngestionService private function updateSpatialMeta(string $id): void { - // 1) Filtrer les micro-polygones < MIN_POLYGON_AREA_M2 avant simplification - // Un fragment < 1 km² en plein océan est du bruit ou un artefact atmo. + // 1) Filtrer les micro-polygones < MIN_POLYGON_AREA_M2 avant simplification. + // ST_CollectionExtract(..., 3) extrait uniquement les Polygon pour éviter + // que ST_Collect retourne une GeometryCollection incompatible avec la colonne. + // ST_Multi force le type MultiPolygon même pour un seul polygone résiduel. $this->em->getConnection()->executeStatement( "UPDATE sargassum_observation SET geometry = ( SELECT COALESCE( - ST_Collect(geom), - 'GEOMETRYCOLLECTION EMPTY'::geometry + ST_Multi(ST_CollectionExtract(ST_Collect(geom), 3)), + ST_GeomFromText('MULTIPOLYGON EMPTY', 4326) ) FROM ( SELECT (ST_Dump(geometry)).geom AS geom + FROM sargassum_observation + WHERE id = :id ) parts - WHERE ST_Area(geom::geography) >= :minArea + WHERE ST_Area(parts.geom::geography) >= :minArea ) WHERE id = :id", ['id' => $id, 'minArea' => self::MIN_POLYGON_AREA_M2]