Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Carte] Amélioration des performances grâce aux géométries simplifiées #1880

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -7,7 +7,7 @@ data class RegulatoryAreaWithMetadataDataOutput(
val id: Int,
val entity_name: String? = null,
val facade: String? = null,
val geom: MultiPolygon? = null,
val geometry_simplified: MultiPolygon? = null,
val layer_name: String? = null,
val ref_reg: String? = null,
val thematique: String? = null,
Expand All @@ -20,7 +20,7 @@ data class RegulatoryAreaWithMetadataDataOutput(
id = regulatoryArea.id,
entity_name = regulatoryArea.entity_name,
facade = regulatoryArea.facade,
geom = regulatoryArea.geom,
geometry_simplified = regulatoryArea.geometry_simplified,
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,68 +14,74 @@ import org.n52.jackson.datatype.jts.GeometrySerializer
@Entity
@Table(name = "regulations_cacem")
data class RegulatoryAreaModel(
@Id @Column(name = "id") val id: Int,
@Column(name = "date") val date: String?,
@Column(name = "date_fin") val date_fin: String?,
@Column(name = "duree_validite") val duree_validite: 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 = "observation") val observation: String?,
@Column(name = "ref_reg") val ref_reg: 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?,
@Id @Column(name = "id") val id: Int,
@Column(name = "date") val date: String?,
@Column(name = "date_fin") val date_fin: String?,
@Column(name = "duree_validite") val duree_validite: 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?,
@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 = "observation") val observation: String?,
@Column(name = "ref_reg") val ref_reg: 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(
id = id,
date = date,
date_fin = date_fin,
duree_validite = duree_validite,
editeur = editeur,
edition = edition,
entity_name = entity_name,
facade = facade,
geom = geom,
layer_name = layer_name,
observation = observation,
ref_reg = ref_reg,
source = source,
temporalite = temporalite,
thematique = thematique,
type = type,
url = url,
)
RegulatoryAreaEntity(
id = id,
date = date,
date_fin = date_fin,
duree_validite = duree_validite,
editeur = editeur,
edition = edition,
entity_name = entity_name,
facade = facade,
geom = geom,
geometry_simplified = geometry_simplified,
layer_name = layer_name,
observation = observation,
ref_reg = ref_reg,
source = source,
temporalite = temporalite,
thematique = thematique,
type = type,
url = url,
)

companion object {
fun fromRegulatoryAreaEntity(regulatoryArea: RegulatoryAreaEntity) =
RegulatoryAreaModel(
id = regulatoryArea.id,
date = regulatoryArea.date,
date_fin = regulatoryArea.date_fin,
duree_validite = regulatoryArea.duree_validite,
editeur = regulatoryArea.editeur,
edition = regulatoryArea.edition,
entity_name = regulatoryArea.entity_name,
facade = regulatoryArea.facade,
geom = regulatoryArea.geom,
layer_name = regulatoryArea.layer_name,
observation = regulatoryArea.observation,
ref_reg = regulatoryArea.ref_reg,
source = regulatoryArea.source,
temporalite = regulatoryArea.temporalite,
thematique = regulatoryArea.thematique,
type = regulatoryArea.type,
url = regulatoryArea.url,
)
RegulatoryAreaModel(
id = regulatoryArea.id,
date = regulatoryArea.date,
date_fin = regulatoryArea.date_fin,
duree_validite = regulatoryArea.duree_validite,
editeur = regulatoryArea.editeur,
edition = regulatoryArea.edition,
entity_name = regulatoryArea.entity_name,
facade = regulatoryArea.facade,
geom = regulatoryArea.geom,
geometry_simplified = regulatoryArea.geometry_simplified,
layer_name = regulatoryArea.layer_name,
observation = regulatoryArea.observation,
ref_reg = regulatoryArea.ref_reg,
source = regulatoryArea.source,
temporalite = regulatoryArea.temporalite,
thematique = regulatoryArea.thematique,
type = regulatoryArea.type,
url = regulatoryArea.url,
)
}
}
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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UPDATE public.regulations_cacem
SET geometry_simplified = ST_multi(ST_MakeValid(ST_SimplifyPreserveTopology(ST_CurveToLine(geom), 0.0001)));
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.geometry_simplified.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.geometry_simplified.coordinates.flat().flat() as Coordinate[])

return {
...regulatoryLayer,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/domain/entities/regulatory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type RegulatoryLayerWithMetadataFromAPI = {
entity_name: string
facade: string
geom: GeoJSON.MultiPolygon
geometry_simplified: GeoJSON.MultiPolygon
id: number
layer_name: string
ref_reg: string
Expand All @@ -15,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
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();
Loading