From b6ece2044d550029062e15c3b6ee6e373de2fbb4 Mon Sep 17 00:00:00 2001 From: Claire Dagan Date: Mon, 25 Nov 2024 10:10:21 +0100 Subject: [PATCH] [Regulatory] display simplified geometry --- .../bff/outputs/RegulatoryAreaWithMetadataDataOutput.kt | 6 ++---- ...66.20__add_column_simplified_geometry_to_regulations.sql | 2 ++ frontend/src/api/regulatoryLayersAPI.ts | 4 ++-- frontend/src/domain/entities/regulatory.ts | 3 ++- .../map/layers/Regulatory/RegulatoryPreviewLayer.ts | 2 +- .../map/layers/Regulatory/regulatoryGeometryHelpers.ts | 2 +- 6 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 backend/src/main/resources/db/testdata/V666.20__add_column_simplified_geometry_to_regulations.sql diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/RegulatoryAreaWithMetadataDataOutput.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/RegulatoryAreaWithMetadataDataOutput.kt index 14d079db8..ef8c03ae7 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/RegulatoryAreaWithMetadataDataOutput.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/api/adapters/bff/outputs/RegulatoryAreaWithMetadataDataOutput.kt @@ -7,8 +7,7 @@ data class RegulatoryAreaWithMetadataDataOutput( val id: Int, val entity_name: String? = null, val facade: String? = null, - val geom: MultiPolygon? = null, - // val simplify_geom: MultiPolygon? = null, + val geometry_simplified: MultiPolygon? = null, val layer_name: String? = null, val ref_reg: String? = null, val thematique: String? = null, @@ -21,8 +20,7 @@ data class RegulatoryAreaWithMetadataDataOutput( id = regulatoryArea.id, entity_name = regulatoryArea.entity_name, facade = regulatoryArea.facade, - geom = regulatoryArea.geom, - // simplify_geom = regulatoryArea.simplify_geom, + geometry_simplified = regulatoryArea.geometry_simplified, layer_name = regulatoryArea.layer_name, ref_reg = regulatoryArea.ref_reg, thematique = regulatoryArea.thematique, diff --git a/backend/src/main/resources/db/testdata/V666.20__add_column_simplified_geometry_to_regulations.sql b/backend/src/main/resources/db/testdata/V666.20__add_column_simplified_geometry_to_regulations.sql new file mode 100644 index 000000000..32584a712 --- /dev/null +++ b/backend/src/main/resources/db/testdata/V666.20__add_column_simplified_geometry_to_regulations.sql @@ -0,0 +1,2 @@ +UPDATE public.regulations_cacem +SET geometry_simplified = ST_multi(ST_MakeValid(ST_SimplifyPreserveTopology(ST_CurveToLine(geom), 0.0001))); \ No newline at end of file diff --git a/frontend/src/api/regulatoryLayersAPI.ts b/frontend/src/api/regulatoryLayersAPI.ts index 22145552c..6d587330c 100644 --- a/frontend/src/api/regulatoryLayersAPI.ts +++ b/frontend/src/api/regulatoryLayersAPI.ts @@ -27,7 +27,7 @@ export const regulatoryLayersAPI = monitorenvPrivateApi.injectEndpoints({ query: id => `/v1/regulatory/${id}`, transformErrorResponse: response => new FrontendApiError(GET_REGULATORY_LAYER_ERROR_MESSAGE, response), transformResponse: (response: RegulatoryLayerWithMetadataFromAPI) => { - const bbox = boundingExtent(response.simplify_geom.coordinates.flat().flat() as Coordinate[]) + const bbox = boundingExtent(response.geometry_simplified.coordinates.flat().flat() as Coordinate[]) return { ...response, @@ -42,7 +42,7 @@ export const regulatoryLayersAPI = monitorenvPrivateApi.injectEndpoints({ RegulatoryLayersAdapter.setAll( regulatoryLayersInitialState, response.map(regulatoryLayer => { - const bbox = boundingExtent(regulatoryLayer.simplify_geom.coordinates.flat().flat() as Coordinate[]) + const bbox = boundingExtent(regulatoryLayer.geometry_simplified.coordinates.flat().flat() as Coordinate[]) return { ...regulatoryLayer, diff --git a/frontend/src/domain/entities/regulatory.ts b/frontend/src/domain/entities/regulatory.ts index 1023c65ab..acf080a22 100644 --- a/frontend/src/domain/entities/regulatory.ts +++ b/frontend/src/domain/entities/regulatory.ts @@ -4,10 +4,10 @@ export type RegulatoryLayerWithMetadataFromAPI = { entity_name: string facade: string geom: GeoJSON.MultiPolygon + geometry_simplified: GeoJSON.MultiPolygon id: number layer_name: string ref_reg: string - simplify_geom: GeoJSON.MultiPolygon thematique: string type: string url: string @@ -16,6 +16,7 @@ export type RegulatoryLayerWithMetadataFromAPI = { export type RegulatoryLayerCompactFromAPI = { entity_name: string geom: GeoJSON.MultiPolygon + geometry_simplified: GeoJSON.MultiPolygon id: number layer_name: string ref_reg: string diff --git a/frontend/src/features/map/layers/Regulatory/RegulatoryPreviewLayer.ts b/frontend/src/features/map/layers/Regulatory/RegulatoryPreviewLayer.ts index d3ac87d4b..7075e83d9 100644 --- a/frontend/src/features/map/layers/Regulatory/RegulatoryPreviewLayer.ts +++ b/frontend/src/features/map/layers/Regulatory/RegulatoryPreviewLayer.ts @@ -48,7 +48,7 @@ export function RegulatoryPreviewLayer({ map }: BaseMapChildrenProps) { regulatoryFeatures = regulatoryAreasToDisplay?.reduce((regulatorylayers, id) => { const layer = regulatoryLayers?.entities[id] - if (layer && layer.geom) { + if (layer && layer.geometry_simplified) { const feature = getRegulatoryFeature({ code: Layers.REGULATORY_ENV_PREVIEW.code, layer }) if (feature) { diff --git a/frontend/src/features/map/layers/Regulatory/regulatoryGeometryHelpers.ts b/frontend/src/features/map/layers/Regulatory/regulatoryGeometryHelpers.ts index 32043a469..dac80ee35 100644 --- a/frontend/src/features/map/layers/Regulatory/regulatoryGeometryHelpers.ts +++ b/frontend/src/features/map/layers/Regulatory/regulatoryGeometryHelpers.ts @@ -2,7 +2,7 @@ import { getFeature } from '@utils/getFeature' import { getArea } from 'ol/sphere' export function getRegulatoryFeature({ code, layer }) { - const feature = getFeature(layer.geom) + const feature = getFeature(layer.geometry_simplified) if (!feature) { return undefined }