Skip to content

Commit

Permalink
[Regulatory] display simplified geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Nov 25, 2024
1 parent 49cce8e commit b6ece20
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
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.simplify_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.simplify_geom.coordinates.flat().flat() as Coordinate[])
const bbox = boundingExtent(regulatoryLayer.geometry_simplified.coordinates.flat().flat() as Coordinate[])

return {
...regulatoryLayer,
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/domain/entities/regulatory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
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

0 comments on commit b6ece20

Please sign in to comment.