Open pierre56 opened 1 month ago
Voir https://github.com/PnX-SI/GeoNature/issues/2955
et adapter pour ajouter les statuts supplémentaires demandés par les collègues
CREATE MATERIALIZED VIEW taxonomie.vm_custom_status_aggregation
TABLESPACE pg_default AS
WITH
protections as (
select *
from taxonomie.bdc_statut t
where
(t.cd_sig::text ='ETATFRA' or -- Etat Français
t.cd_sig::text = 'TERFXFR'::text -- Territoire Français
)
or
(t.cd_sig::text = 'INSEER53' or --BZH
t.cd_sig::text = 'INSEER53' -- PDL
)
or
(
t.cd_sig::text ='INSEED22' or
t.cd_sig::text ='INSEED29' or
t.cd_sig::text ='INSEED35' or
t.cd_sig::text ='INSEED44' or
t.cd_sig::text ='INSEED56' )
)
, protection_mond AS (
SELECT string_agg(concat(vbs_1.cd_type_statut, ' : ', vbs_1.code_statut, ' (', vbs_1.lb_adm_tr, ')'), ' - '::text) AS agg,
vbs_1.cd_nom
FROM protections vbs_1
WHERE vbs_1.cd_type_statut::text = ANY (ARRAY['BERN'::text, 'BONN'::text, 'OSPAR'::text])
GROUP BY vbs_1.cd_nom
)
, protection_eur AS (
SELECT string_agg(concat(vbs_1.cd_type_statut, ': ', vbs_1.code_statut::text, ' (', vbs_1.lb_adm_tr, ') '), ' - '::text) AS agg,
vbs_1.cd_nom
FROM protections vbs_1
WHERE vbs_1.cd_type_statut::text = ANY (ARRAY['DH'::text, 'DO'::text])
GROUP BY vbs_1.cd_nom
)
, protection_nat AS (
SELECT string_agg(concat(vbs_1.cd_type_statut, ': ', vbs_1.code_statut, ' (', vbs_1.lb_adm_tr, ') '), '- '::text) AS agg,
vbs_1.cd_nom
FROM protections vbs_1
WHERE vbs_1.cd_type_statut::text = ANY (ARRAY['REGLII'::text, 'REGLUTTE'::text, 'REGL'::text, 'PD'::text, 'PR'::text, 'PN'::text, 'REGLSO'::text])
GROUP BY vbs_1.cd_nom
)
, listes_rouges AS (
SELECT string_agg(concat(vbs_1.cd_type_statut, ' : ', vbs_1.code_statut, ' (', vbs_1.lb_adm_tr, ')'), ' - '::text) AS agg,
vbs_1.cd_nom
FROM protections vbs_1
WHERE (vbs_1.cd_type_statut::text = ANY (ARRAY['LRM'::text, 'LRN'::text, 'LRR'::text, 'LRE'::text])) AND (vbs_1.code_statut::text <> ALL (ARRAY['NA'::text, 'DD'::text]))
GROUP BY vbs_1.cd_nom
)
, protection_local AS (
SELECT string_agg(concat(vbs_1.cd_type_statut, ' : ', vbs_1.code_statut, ' (', vbs_1.lb_adm_tr, ')'), ' - '::text) AS agg,
vbs_1.cd_nom
FROM protections vbs_1
WHERE (vbs_1.cd_type_statut::text = ANY (ARRAY['ZDET'::text, 'SENSREG'::text, 'DO'::text, 'LRE'::text])) AND (vbs_1.code_statut::text <> ALL (ARRAY['NA'::text, 'DD'::text]))
GROUP BY vbs_1.cd_nom
)
SELECT DISTINCT vbs.cd_nom,
p.agg AS protections_nat,
d.agg AS protections_eur,
m.agg AS protections_mond,
r.agg AS listes_rouge
FROM gn_synthese.synthese vbs
LEFT JOIN protection_nat p ON p.cd_nom = vbs.cd_nom
LEFT JOIN protection_eur d ON d.cd_nom = vbs.cd_nom
LEFT JOIN protection_mond m ON m.cd_nom = vbs.cd_nom
LEFT JOIN listes_rouges r ON r.cd_nom = vbs.cd_nom
WITH DATA;
CREATE OR REPLACE VIEW gn_synthese.v_synthese_for_export_custom_status
AS SELECT s.id_synthese,
s.date_min::date AS date_debut,
s.date_max::date AS date_fin,
t.cd_nom,
t.cd_ref,
t.nom_valide,
t.nom_vern AS nom_vernaculaire,
s.nom_cite,
t.regne,
t.group2_inpn,
t.classe,
t.ordre,
t.famille,
t.id_rang AS rang_taxo,
status.protections_nat,
status.protections_eur,
status.protections_mond,
status.listes_rouge,
cta.valeur_attribut AS patrimonial,
s.count_min AS nombre_min,
s.count_max AS nombre_max,
s.altitude_min AS alti_min,
s.altitude_max AS alti_max,
s.observers AS observateurs,
sa.communes,
st_astext(s.the_geom_4326) AS geometrie_wkt_4326,
st_x(s.the_geom_point) AS x_centroid_4326,
st_y(s.the_geom_point) AS y_centroid_4326,
st_asgeojson(s.the_geom_4326) AS geojson_4326,
st_asgeojson(s.the_geom_local) AS geojson_local,
s.comment_context AS comment_releve,
s.comment_description AS comment_occurrence,
d.dataset_name AS jdd_nom,
af.acquisition_framework_name AS ca_nom,
s."precision" AS precision_geographique,
n1.label_default AS nature_objet_geo,
n3.label_default AS technique_observation,
n10.label_default AS stade_vie,
n11.label_default AS sexe,
s.unique_id_sinp AS uuid_perm_sinp,
s.unique_id_sinp_grp AS uuid_perm_grp_sinp
FROM gn_synthese.synthese s
JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom
LEFT JOIN taxonomie.cor_taxon_attribut cta ON cta.cd_ref = t.cd_nom AND cta.id_attribut = 1
JOIN gn_meta.t_datasets d ON d.id_dataset = s.id_dataset
JOIN gn_meta.t_acquisition_frameworks af ON d.id_acquisition_framework = af.id_acquisition_framework
LEFT JOIN LATERAL ( SELECT cas.id_synthese,
string_agg(DISTINCT concat(a_1.area_name, ' (', a_1.area_code, ')'), ', '::text) AS communes
FROM gn_synthese.cor_area_synthese cas
JOIN ref_geo.l_areas a_1 ON cas.id_area = a_1.id_area
JOIN ref_geo.bib_areas_types ta ON ta.id_type = a_1.id_type AND ta.type_code::text = 'COM'::text
WHERE cas.id_synthese = s.id_synthese
GROUP BY cas.id_synthese) sa ON true
LEFT JOIN ref_nomenclatures.t_nomenclatures n1 ON s.id_nomenclature_geo_object_nature = n1.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n3 ON s.id_nomenclature_obs_technique = n3.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n10 ON s.id_nomenclature_life_stage = n10.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n11 ON s.id_nomenclature_sex = n11.id_nomenclature
JOIN taxonomie.v_custom_status_aggregation status ON status.cd_nom = s.cd_nom;
Export des donnée sensibles floutées
Issues utiles
https://github.com/PnX-SI/GeoNature/issues/2558
Objectif
Ce que doit comporter cet export : anonymiser les observateurs, les validateurs et supprimer les colonnes commentaires. la geom calculée par la sensibilité
la vue de base est v_synthese_for_export et gn_synthese.synthese
Export par un membre BV
extrait des données des communes pour la période 2000-2023 pour les données sous statut "certain-très probable" ou "probable" (19 799 observations). Pour un projet d'ABC à l'échelle de ces communes. On a conventionné
Solution : export par un utilisateur avec permission limitée
a tester
Solution : export spécifique dans synthese
La requête suivante permet de renvoyer les géométries floutées en fonction du niveau de sensibilité :
Vue
Ces vues doivent obligatoirement avoir une colonne id_synthese, une colonne geojson_local représentant le geojson de la géometrie en projection locale (pour la génération du shapefile et geopackage) et une colonne geojson_4326 représentant le geojson de la géométrie en projection 4326 (pour la génération du geojson) (utilisez la fonction st_asgeojson - voir la vue par défaut gn_synthese.v_synthese_for_export)
Vue
Config
[SYNTHESE] ...
Export custom dans synthese
MAJ de geonature pour 2.14.2 ok