Skip to content

Commit 74fdd73

Browse files
submarcosjuggler31
authored andcommitted
enhance blurred views to get sensitive config from ref_geo tables
1 parent 8830dc0 commit 74fdd73

File tree

2 files changed

+54
-35
lines changed

2 files changed

+54
-35
lines changed

data/atlas/11.vm_cor_area_synthese.sql

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,63 @@ IMPORT FOREIGN SCHEMA gn_synthese
22
LIMIT TO (gn_synthese.cor_area_synthese)
33
FROM SERVER geonaturedbserver INTO synthese;
44

5+
IMPORT FOREIGN SCHEMA gn_sensitivity
6+
LIMIT TO (cor_sensitivity_area_type) FROM SERVER geonaturedbserver INTO synthese;
7+
58
CREATE MATERIALIZED VIEW atlas.vm_cor_area_synthese
69
TABLESPACE pg_default
710
AS
8-
WITH info_tmp AS (
9-
SELECT
10-
sa.id_synthese,
11-
sa.id_area,
12-
a.centroid,
13-
a.id_type,
14-
s.id_nomenclature_sensitivity,
15-
st_transform(a.geom, 4326) AS geom
16-
FROM synthese.synthese s
17-
JOIN synthese.cor_area_synthese sa ON sa.id_synthese = s.id_synthese
18-
JOIN ref_geo.l_areas a ON sa.id_area = a.id_area
19-
JOIN atlas.t_layer_territoire ON st_intersects(a.geom_4326, t_layer_territoire.geom)-- AND NOT ST_Touches(t_layer_territoire.geom, a.geom_4326)
20-
)
21-
SELECT info.id_synthese,
22-
info.id_area,
23-
info.centroid,
24-
info.geom AS geom,
25-
st_asgeojson(info.geom) AS geojson_4326,
26-
st_transform(info.centroid, 4326) AS centroid_4326,
27-
t.type_code,
28-
sensi.cd_nomenclature,
29-
CASE
30-
WHEN sensi.cd_nomenclature = '1' AND t.type_code = :'sensibility1' THEN true
31-
WHEN sensi.cd_nomenclature = '2' AND t.type_code = :'sensibility2' THEN true
32-
WHEN sensi.cd_nomenclature = '3' AND t.type_code = :'sensibility3' THEN true
33-
WHEN (sensi.cd_nomenclature = '0' OR sensi.cd_nomenclature IS NULL) AND t.type_code::text = :'sensibility0' THEN true
34-
ELSE false
35-
END AS is_blurred_geom
36-
FROM info_tmp info
37-
JOIN ref_geo.bib_areas_types t ON info.id_type = t.id_type
38-
LEFT JOIN synthese.t_nomenclatures sensi ON info.id_nomenclature_sensitivity = sensi.id_nomenclature
39-
WHERE (t.type_code IN (:'sensibility0', :'sensibility1', :'sensibility2', :'sensibility3'))
40-
AND (NOT sensi.cd_nomenclature = '4'::TEXT OR sensi.cd_nomenclature IS NULL )
11+
WITH sensitive_area_type AS (
12+
SELECT distinct(synthese.cor_sensitivity_area_type.id_area_type)
13+
FROM
14+
synthese.cor_sensitivity_area_type
15+
), info_tmp AS (
16+
SELECT
17+
sa.id_synthese,
18+
sa.id_area,
19+
a.centroid,
20+
a.id_type,
21+
s.id_nomenclature_sensitivity,
22+
a.geom_4326,
23+
a.geom
24+
FROM
25+
synthese.synthese s
26+
JOIN
27+
synthese.cor_area_synthese sa
28+
ON sa.id_synthese = s.id_synthese
29+
JOIN
30+
ref_geo.l_areas a
31+
ON sa.id_area = a.id_area
32+
JOIN
33+
ref_geo.bib_areas_types t
34+
ON a.id_type = t.id_type
35+
JOIN sensitive_area_type sat ON t.id_type = sat.id_area_type -- should be an area_type
36+
WHERE a.enable = TRUE
37+
)
38+
SELECT
39+
info.id_synthese,
40+
info.id_area,
41+
info.centroid,
42+
info.geom,
43+
st_asgeojson(info.geom_4326) AS geojson_4326,
44+
st_transform(info.centroid,
45+
4326) AS centroid_4326,
46+
t.type_code,
47+
n.cd_nomenclature
48+
FROM
49+
info_tmp info
50+
JOIN
51+
ref_geo.bib_areas_types t
52+
ON info.id_type = t.id_type
53+
JOIN synthese.cor_sensitivity_area_type csat ON t.id_type = csat.id_area_type
54+
55+
LEFT JOIN
56+
synthese.t_nomenclatures n
57+
ON info.id_nomenclature_sensitivity = n.id_nomenclature
4158

4259
WITH DATA;
60+
4361
CREATE UNIQUE INDEX i_vm_cor_area_synthese ON atlas.vm_cor_area_synthese USING btree (id_synthese, id_area );
4462

45-
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_cor_area_synthese;
63+
64+
SELECT count(*) FROM atlas.vm_cor_area_synthese;

data/atlas/13.atlas.vm_observations_mailles.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
ARRAY_AGG(o.id_observation) AS id_observations,
88
cor.type_code
99
FROM atlas.vm_observations AS o
10-
JOIN atlas.vm_cor_area_synthese cor ON cor.id_synthese = o.id_observation AND cor.is_blurred_geom IS TRUE
10+
JOIN atlas.vm_cor_area_synthese cor ON cor.id_synthese = o.id_observation
1111
GROUP BY o.cd_ref, cor.id_area, cor.type_code, annee
1212
ORDER BY o.cd_ref
1313
WITH DATA;

0 commit comments

Comments
 (0)