Skip to content

Commit

Permalink
[RegulatoryAreas] update trigger function to add a simplified geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Nov 22, 2024
1 parent 86e04b3 commit 49cce8e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE regulations_cacem
ADD COLUMN geometry_simplified public.geometry(Geometry,4326);
4 changes: 2 additions & 2 deletions frontend/src/api/regulatoryLayersAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions frontend/src/domain/entities/regulatory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions infra/cacem/contraintes_table_reglementation.sql
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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();

0 comments on commit 49cce8e

Please sign in to comment.