diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/regulatoryArea/RegulatoryAreaEntity.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/regulatoryArea/RegulatoryAreaEntity.kt index 51e4c5cd97..48fddc2fcb 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/regulatoryArea/RegulatoryAreaEntity.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/domain/entities/regulatoryArea/RegulatoryAreaEntity.kt @@ -5,6 +5,7 @@ import org.locationtech.jts.geom.MultiPolygon data class RegulatoryAreaEntity( val id: Int, val geom: MultiPolygon? = null, + val geometry_simplified: MultiPolygon? = null, val entity_name: String? = null, val url: String? = null, val layer_name: String? = null, 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 35ee9f98d5..14d079db85 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 @@ -8,6 +8,7 @@ data class RegulatoryAreaWithMetadataDataOutput( val entity_name: String? = null, val facade: String? = null, val geom: MultiPolygon? = null, + // val simplify_geom: MultiPolygon? = null, val layer_name: String? = null, val ref_reg: String? = null, val thematique: String? = null, @@ -21,6 +22,7 @@ data class RegulatoryAreaWithMetadataDataOutput( entity_name = regulatoryArea.entity_name, facade = regulatoryArea.facade, geom = regulatoryArea.geom, + // simplify_geom = regulatoryArea.simplify_geom, layer_name = regulatoryArea.layer_name, ref_reg = regulatoryArea.ref_reg, thematique = regulatoryArea.thematique, diff --git a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/RegulatoryAreaModel.kt b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/RegulatoryAreaModel.kt index cda487de89..7a66911060 100644 --- a/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/RegulatoryAreaModel.kt +++ b/backend/src/main/kotlin/fr/gouv/cacem/monitorenv/infrastructure/database/model/RegulatoryAreaModel.kt @@ -14,51 +14,34 @@ import org.n52.jackson.datatype.jts.GeometrySerializer @Entity @Table(name = "regulations_cacem") data class RegulatoryAreaModel( - @Id - @Column(name = "id") - val id: Int, - @Column(name = "action") - val action: String?, - @Column(name = "date") - val date: String?, - @Column(name = "date_fin") - val date_fin: String?, - @Column(name = "duree_validite") - val duree_validite: String?, - @Column(name = "echelle") - val echelle: String?, - @Column(name = "editeur") - val editeur: String?, - @Column(name = "edition") - val edition: String?, - @Column(name = "entity_name") - val entity_name: String?, - @Column(name = "facade") - val facade: String?, + @Id @Column(name = "id") val id: Int, + @Column(name = "action") val action: String?, + @Column(name = "date") val date: String?, + @Column(name = "date_fin") val date_fin: String?, + @Column(name = "duree_validite") val duree_validite: String?, + @Column(name = "echelle") val echelle: String?, + @Column(name = "editeur") val editeur: String?, + @Column(name = "edition") val edition: String?, + @Column(name = "entity_name") val entity_name: String?, + @Column(name = "facade") val facade: String?, @JsonSerialize(using = GeometrySerializer::class) @JsonDeserialize(contentUsing = GeometryDeserializer::class) @Column(name = "geom") val geom: MultiPolygon?, - @Column(name = "layer_name") - val layer_name: String?, - @Column(name = "objet") - val objet: String?, - @Column(name = "observation") - val observation: String?, - @Column(name = "ref_reg") - val ref_reg: String?, - @Column(name = "signataire") - val signataire: String?, - @Column(name = "source") - val source: String?, - @Column(name = "temporalite") - val temporalite: String?, - @Column(name = "thematique") - val thematique: String?, - @Column(name = "type") - val type: String?, - @Column(name = "url") - val url: String?, + @JsonSerialize(using = GeometrySerializer::class) + @JsonDeserialize(contentUsing = GeometryDeserializer::class) + @Column(name = "geometry_simplified") + val geometry_simplified: MultiPolygon?, + @Column(name = "layer_name") val layer_name: String?, + @Column(name = "objet") val objet: String?, + @Column(name = "observation") val observation: String?, + @Column(name = "ref_reg") val ref_reg: String?, + @Column(name = "signataire") val signataire: String?, + @Column(name = "source") val source: String?, + @Column(name = "temporalite") val temporalite: String?, + @Column(name = "thematique") val thematique: String?, + @Column(name = "type") val type: String?, + @Column(name = "url") val url: String?, ) { fun toRegulatoryArea() = RegulatoryAreaEntity( @@ -73,6 +56,7 @@ data class RegulatoryAreaModel( entity_name = entity_name, facade = facade, geom = geom, + geometry_simplified = geometry_simplified, layer_name = layer_name, objet = objet, observation = observation, @@ -99,6 +83,7 @@ data class RegulatoryAreaModel( entity_name = regulatoryArea.entity_name, facade = regulatoryArea.facade, geom = regulatoryArea.geom, + geometry_simplified = regulatoryArea.geometry_simplified, layer_name = regulatoryArea.layer_name, objet = regulatoryArea.objet, observation = regulatoryArea.observation, diff --git a/backend/src/main/resources/db/migration/internal/V0.161__add_column_geom_simplified_to_regulations_cacem.sql b/backend/src/main/resources/db/migration/internal/V0.161__add_column_geom_simplified_to_regulations_cacem.sql new file mode 100644 index 0000000000..e8a8cd26cf --- /dev/null +++ b/backend/src/main/resources/db/migration/internal/V0.161__add_column_geom_simplified_to_regulations_cacem.sql @@ -0,0 +1,2 @@ +ALTER TABLE regulations_cacem +ADD COLUMN geometry_simplified public.geometry(Geometry,4326); diff --git a/frontend/src/api/regulatoryLayersAPI.ts b/frontend/src/api/regulatoryLayersAPI.ts index b1bc706bfe..22145552ca 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.geom.coordinates.flat().flat() as Coordinate[]) + const bbox = boundingExtent(response.simplify_geom.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.geom.coordinates.flat().flat() as Coordinate[]) + const bbox = boundingExtent(regulatoryLayer.simplify_geom.coordinates.flat().flat() as Coordinate[]) return { ...regulatoryLayer, diff --git a/frontend/src/domain/entities/regulatory.ts b/frontend/src/domain/entities/regulatory.ts index 4d529c9f0f..1023c65ab9 100644 --- a/frontend/src/domain/entities/regulatory.ts +++ b/frontend/src/domain/entities/regulatory.ts @@ -7,6 +7,7 @@ export type RegulatoryLayerWithMetadataFromAPI = { id: number layer_name: string ref_reg: string + simplify_geom: GeoJSON.MultiPolygon thematique: string type: string url: string diff --git a/infra/cacem/contraintes_table_reglementation.sql b/infra/cacem/contraintes_table_reglementation.sql index d5a8889055..9ba36adf5f 100644 --- a/infra/cacem/contraintes_table_reglementation.sql +++ b/infra/cacem/contraintes_table_reglementation.sql @@ -1,7 +1,6 @@ -ALTER TABLE prod.reglementation_env ADD COLUMN geometry_simplified geometry(MULTYPOLYGON,4326); -UPDATE prod.reglementation_env SET geometry = ST_MakeValid(ST_CurveToLine(geometry)); -UPDATE prod.reglementation_env SET geometry_simplified = ST_SimplifyPreserveTopology(ST_CurveToLine(geometry), 0.0001); -ALTER TABLE prod.reglementation_env ADD CONSTRAINT geometry_is_valid_check CHECK (st_isvalid(geometry)); +ALTER TABLE prod."REG_ENV_V3" ADD COLUMN geometry_simplified geometry(MULTYPOLYGON,4326); +UPDATE prod."REG_ENV_V3" SET geometry_simplified = ST_SimplifyPreserveTopology(ST_CurveToLine(geometry), 0.0001); +ALTER TABLE prod."REG_ENV_V3" ADD CONSTRAINT geometry_is_valid_check CHECK (st_isvalid(geometry)); -- This trigger function -- * is triggered whenever a row in the local regulation database is inserted or modified @@ -20,6 +19,6 @@ CREATE FUNCTION prod.simplify_geometry() RETURNS trigger AS $$ $$ LANGUAGE plpgsql; CREATE TRIGGER simplify_geometry - BEFORE INSERT OR UPDATE OF geom ON prod.reglementation_env + BEFORE INSERT OR UPDATE OF geom ON prod."REG_ENV_V3" FOR EACH ROW EXECUTE PROCEDURE prod.simplify_geometry();