From 7778eb4c5fe146e1f682bd03154580c9971b3674 Mon Sep 17 00:00:00 2001 From: Claire Dagan Date: Wed, 11 Dec 2024 16:15:25 +0100 Subject: [PATCH] [Tech] use ST_Union to calculate facade and departement --- .../interfaces/IDBDepartmentAreaRepository.kt | 8 ++------ .../repositories/interfaces/IDBFacadeAreasRepository.kt | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBDepartmentAreaRepository.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBDepartmentAreaRepository.kt index 0c6b062a01..4a2ed6f435 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBDepartmentAreaRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBDepartmentAreaRepository.kt @@ -8,7 +8,7 @@ import org.springframework.data.repository.CrudRepository interface IDBDepartmentAreaRepository : CrudRepository { @Query( value = - """ + """ SELECT * FROM departments_areas WHERE insee_dep = :inseeCode @@ -20,11 +20,7 @@ interface IDBDepartmentAreaRepository : CrudRepository @Query( """ WITH geom AS ( - SELECT CASE - WHEN GeometryType(ST_SetSRID(:geometry, 4326)) IN ('ST_MultiPolygon', 'ST_Polygon') - THEN ST_Buffer(ST_SetSRID(:geometry, 4326), 0) - ELSE ST_SetSRID(:geometry, 4326) - END AS geom + SELECT ST_SetSRID(ST_Union(:geometry), 4326) AS geom ), departments_intersection_areas AS ( diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBFacadeAreasRepository.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBFacadeAreasRepository.kt index 9590692088..1d439b1ea4 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBFacadeAreasRepository.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/repositories/interfaces/IDBFacadeAreasRepository.kt @@ -9,9 +9,9 @@ interface IDBFacadeAreasRepository : CrudRepository { @Query( """ WITH geom AS ( - SELECT st_setsrid(:geometry, 4326) AS geom + SELECT st_setsrid(ST_Union(:geometry), 4326) AS geom ), - + facades_intersection_areas AS ( SELECT facade, @@ -30,7 +30,7 @@ interface IDBFacadeAreasRepository : CrudRepository { ON ST_Intersects(geom.geom, facade_areas_subdivided.geometry) GROUP BY facade ) - + SELECT facade FROM facades_intersection_areas ORDER BY intersection_area DESC