-
Notifications
You must be signed in to change notification settings - Fork 48
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
Réimplémentation de la sensibilité #441
base: develop
Are you sure you want to change the base?
Changes from all commits
c571627
56dac33
16f83aa
15e5bff
fd8c979
bc3a976
eb2c73e
246639e
c05b02f
59146e5
f847c92
0482100
c0a66e8
f9aa473
1e43d77
dc551be
f85ef5b
ec88d60
5e91d4f
c486cdc
79218de
0a644cf
1163790
358bd88
44e7486
54ae9cc
1d110c0
a6bef1c
6a48d89
28d005f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,23 +14,69 @@ CREATE INDEX ON atlas.vm_taxref (nom_complet); | |
CREATE INDEX ON atlas.vm_taxref (nom_valide); | ||
|
||
|
||
CREATE MATERIALIZED VIEW atlas.vm_cor_area_synthese | ||
TABLESPACE pg_default | ||
AS SELECT sa.id_synthese, | ||
sa.id_area, | ||
a.centroid, | ||
st_transform(a.geom, 4326) AS geom, | ||
st_asgeojson(st_transform(a.geom, 4326)) AS geojson_4326, | ||
st_transform(a.centroid, 4326) AS centroid_4326, | ||
t.type_code, | ||
sensi.cd_nomenclature, | ||
CASE | ||
WHEN sensi.cd_nomenclature::text = '1'::text AND t.type_code::text = 'M1'::text THEN true | ||
WHEN sensi.cd_nomenclature::text = '2'::text AND t.type_code::text = 'M5'::text THEN true | ||
WHEN sensi.cd_nomenclature::text = '3'::text AND t.type_code::text = 'M10'::text THEN true | ||
WHEN (sensi.cd_nomenclature::text = '0'::TEXT OR sensi.cd_nomenclature::text IS NULL) AND t.type_code::text = :default_maille::text THEN true | ||
ELSE false | ||
END AS is_blurred_geom | ||
FROM synthese.synthese s | ||
JOIN synthese.cor_area_synthese sa ON sa.id_synthese = s.id_synthese | ||
JOIN ref_geo.l_areas a ON sa.id_area = a.id_area | ||
JOIN ref_geo.bib_areas_types t ON a.id_type = t.id_type | ||
LEFT JOIN synthese.t_nomenclatures sensi ON s.id_nomenclature_sensitivity = sensi.id_nomenclature | ||
WHERE (t.type_code::text = ANY (ARRAY['M1'::character varying, 'M5'::character varying, 'M10'::character varying]::text[])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ici, aussi, il serait peut être nécessaire d'utiliser une fonction pour pouvoir personnaliser les zones à utiliser. |
||
AND (NOT sensi.cd_nomenclature::text = '4'::TEXT OR sensi.cd_nomenclature IS NULL ) | ||
WITH DATA; | ||
CREATE UNIQUE INDEX i_vm_cor_area_synthese ON atlas.vm_cor_area_synthese USING btree (id_synthese, id_area ); | ||
|
||
--Toutes les observations | ||
|
||
--DROP materialized view atlas.vm_observations; | ||
CREATE MATERIALIZED VIEW atlas.vm_observations AS | ||
SELECT s.id_synthese AS id_observation, | ||
s.insee, | ||
s.dateobs, | ||
s.observateurs, | ||
s.altitude_retenue, | ||
s.the_geom_point::geometry('POINT',3857), | ||
s.effectif_total, | ||
tx.cd_ref, | ||
st_asgeojson(ST_Transform(ST_SetSrid(s.the_geom_point, 3857), 4326)) as geojson_point, | ||
diffusion_level | ||
FROM synthese.syntheseff s | ||
LEFT JOIN atlas.vm_taxref tx ON tx.cd_nom = s.cd_nom | ||
JOIN atlas.t_layer_territoire m ON ST_Intersects(m.the_geom, s.the_geom_point); | ||
|
||
CREATE MATERIALIZED VIEW atlas.vm_observations AS | ||
WITH centroid AS ( | ||
SELECT st_centroid(st_union(cor.geom)) AS geom_point, s.id_synthese | ||
FROM synthese.synthese s | ||
JOIN atlas.vm_cor_area_synthese cor ON cor.id_synthese = s.id_synthese | ||
WHERE cor.id_synthese = s.id_synthese AND cor.is_blurred_geom IS TRUE | ||
GROUP BY s.id_synthese | ||
) | ||
SELECT s.id_synthese AS id_observation, | ||
com.insee , | ||
s.date_min AS dateobs, | ||
(s.altitude_min + s.altitude_max) / 2 AS altitude_retenue, | ||
s.observers AS observateurs, | ||
tx.cd_ref, | ||
s.id_dataset, | ||
c.geom_point, | ||
CASE | ||
WHEN sensi.cd_nomenclature = '0' THEN st_transform(s.the_geom_point, 3857) | ||
ELSE st_transform(c.geom_point, 3857) | ||
END AS the_geom_point, | ||
CASE | ||
WHEN sensi.cd_nomenclature = '0' THEN st_asgeojson(st_transform(s.the_geom_point, 4326)) | ||
ELSE st_asgeojson(st_transform(c.geom_point, 4326)) | ||
END AS geojson_point, | ||
sensi.cd_nomenclature AS cd_sensitivity | ||
FROM synthese.synthese s | ||
JOIN atlas.vm_taxref tx ON tx.cd_nom = s.cd_nom | ||
LEFT JOIN synthese.t_nomenclatures sensi ON s.id_nomenclature_sensitivity = sensi.id_nomenclature | ||
JOIN centroid c ON c.id_synthese = s.id_synthese | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La sous-requête " There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'ai compris finalement que les mailles utilisées par défaut lorsqu'on force l'Atlas à afficher uniquement des mailles sont aussi comprises dans |
||
JOIN atlas.l_communes com ON st_intersects(st_transform(s.the_geom_point, 3857), com.the_geom) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Afin d'associer les observations à flouter à la commune correspondant au centroïde de la géométrie de l'observations, il me semble que le |
||
; | ||
|
||
|
||
CREATE UNIQUE INDEX ON atlas.vm_observations (id_observation); | ||
CREATE INDEX ON atlas.vm_observations (cd_ref); | ||
|
@@ -269,7 +315,7 @@ c.commune_maj, | |
c.the_geom, | ||
st_asgeojson(st_transform(c.the_geom, 4326)) as commune_geojson | ||
FROM atlas.l_communes c | ||
JOIN atlas.t_layer_territoire t ON ST_CONTAINS(ST_BUFFER(t.the_geom,200), c.the_geom); | ||
JOIN atlas.t_layer_territoire t ON ST_INTERSECTS(t.the_geom, c.the_geom); | ||
|
||
CREATE UNIQUE INDEX ON atlas.vm_communes (insee); | ||
CREATE INDEX index_gist_vm_communes_the_geom ON atlas.vm_communes USING gist (the_geom); | ||
|
@@ -454,6 +500,7 @@ CREATE OR REPLACE FUNCTION atlas.refresh_materialized_view_data() | |
RETURNS VOID AS $$ | ||
BEGIN | ||
|
||
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_cor_area_synthese; | ||
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_observations; | ||
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_observations_mailles; | ||
REFRESH MATERIALIZED VIEW CONCURRENTLY atlas.vm_mois; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Une suggestion, en mettant ce code SQL dans une fonction cela permettrait de facilement pouvoir changer la correspondance valeur de sensibilité et maille à utiliser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Je pense que c'est géré ou devrait être géré au niveau de la BDD source (GeoNature dans une majorité des cas), pas au niveau de GeoNature-atlas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui, idéalement. Mais avec l'utilisation de table via Foreign Data Wrapper, je ne sais pas si on peut utiliser des fonctions de la base de données source.