init depot renew

This commit is contained in:
2026-09-22 11:58:57 +02:00
commit e9fa6a7309
205 changed files with 39721 additions and 0 deletions
@@ -0,0 +1,213 @@
from pycen import con_gn
sql = '''
DROP VIEW IF EXISTS gn_exports.departement_export_ens_with_metadata;
CREATE VIEW gn_exports.departement_export_ens_with_metadata AS
WITH af_actors AS (
SELECT cafa.id_acquisition_framework,
json_build_object('type_role',
CASE
WHEN cafa.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cafa.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END,
'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cafa.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cafa.id_role IS NOT NULL THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_acquisition_framework_actor cafa
LEFT JOIN utilisateurs.bib_organismes borg ON cafa.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cafa.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cafa.id_nomenclature_actor_role = tn.id_nomenclature),
af AS (
SELECT taf.id_acquisition_framework,
jsonb_build_object('uuid', taf.unique_acquisition_framework_id, 'name',
taf.acquisition_framework_name,
'desc', taf.acquisition_framework_desc, 'start_date',
taf.acquisition_framework_start_date, 'end_date',
taf.acquisition_framework_end_date,
'initial_closing_date', taf.initial_closing_date, 'territorial_level',
ntl.cd_nomenclature, 'financing_type', nft.cd_nomenclature, 'target_description',
taf.target_description, 'ecologic_or_geologic_target',
taf.ecologic_or_geologic_target, 'actors',
json_agg(af_actors.json_data)) AS af_data
FROM gn_meta.t_acquisition_frameworks taf
JOIN af_actors ON af_actors.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN ref_nomenclatures.t_nomenclatures ntl
ON taf.id_nomenclature_territorial_level = ntl.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nft
ON taf.id_nomenclature_financing_type = nft.id_nomenclature
GROUP BY taf.id_acquisition_framework, taf.acquisition_framework_name, taf.acquisition_framework_desc,
taf.acquisition_framework_start_date, taf.acquisition_framework_end_date, taf.initial_closing_date,
ntl.cd_nomenclature, nft.cd_nomenclature),
ds_actors AS (
SELECT cda.id_dataset,
json_build_object('type_role',
CASE
WHEN cda.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cda.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cda.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cda.id_role IS NOT NULL THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_dataset_actor cda
LEFT JOIN utilisateurs.bib_organismes borg ON cda.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cda.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cda.id_nomenclature_actor_role = tn.id_nomenclature),
ds AS (SELECT tds.id_dataset,
tds.id_acquisition_framework,
-- tds.additional_data,
jsonb_build_object('uuid', tds.unique_dataset_id, 'name', tds.dataset_name, 'desc', tds.dataset_desc,
'shortname', tds.dataset_shortname, 'data_type', ndt.cd_nomenclature,
'collecting_method', ncm.cd_nomenclature, 'data_origin', ndo.cd_nomenclature,
'dataset_objectif', ndso.cd_nomenclature, 'resource_type', nrt.cd_nomenclature,
'source_status', nss.cd_nomenclature, 'territories', array_agg(DISTINCT
ref_nomenclatures.get_cd_nomenclature(cdt.id_nomenclature_territory)),
'actors', json_agg(ds_actors.json_data)) AS dataset_data
FROM gn_meta.t_datasets tds
JOIN ds_actors ON ds_actors.id_dataset = tds.id_dataset
LEFT JOIN gn_meta.cor_dataset_territory cdt ON cdt.id_dataset = tds.id_dataset
LEFT JOIN ref_nomenclatures.t_nomenclatures ndt
ON tds.id_nomenclature_data_type = ndt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ncm
ON tds.id_nomenclature_collecting_method = ncm.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndo
ON tds.id_nomenclature_data_origin = ndo.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndso
ON tds.id_nomenclature_dataset_objectif = ndso.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nrt
ON tds.id_nomenclature_resource_type = nrt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nss
ON tds.id_nomenclature_source_status = nss.id_nomenclature
GROUP BY tds.id_dataset, tds.id_acquisition_framework, tds.unique_dataset_id, tds.dataset_name,
tds.dataset_desc, tds.dataset_shortname, ndt.cd_nomenclature, ncm.cd_nomenclature,
ndo.cd_nomenclature, ndso.cd_nomenclature, nrt.cd_nomenclature, nss.cd_nomenclature)
SELECT s.id_synthese,
s.entity_source_pk_value AS id_source,
s.unique_id_sinp AS id_perm_sinp,
s.unique_id_sinp_grp AS id_perm_grp_sinp,
s.date_min AS date_debut,
s.date_max AS date_fin,
s.cd_nom,
s.meta_v_taxref AS version_taxref,
s.nom_cite,
s.count_min AS nombre_min,
s.count_max AS nombre_max,
s.altitude_min,
s.altitude_max,
s.depth_min AS profondeur_min,
s.depth_max AS profondeur_max,
s.observers AS observateurs,
s.determiner AS determinateur,
s.validator AS validateur,
s.sample_number_proof AS numero_preuve,
s.digital_proof AS preuve_numerique,
s.non_digital_proof AS preuve_non_numerique,
s.comment_context AS comment_releve,
s.comment_description AS comment_occurrence,
ds.dataset_data AS jdd_data,
af.af_data AS ca_data,
s.reference_biblio,
s.cd_hab AS code_habitat,
h.lb_hab_fr AS habitat,
s.place_name AS nom_lieu,
s.precision,
s.additional_data::TEXT AS donnees_additionnelles,
s.the_geom_4326 AS geom,
st_astext(s.the_geom_4326) AS wkt_4326,
n1.cd_nomenclature AS nature_objet_geo,
n2.cd_nomenclature AS type_regroupement,
s.grp_method AS methode_regroupement,
n3.cd_nomenclature AS comportement,
n4.cd_nomenclature AS technique_obs,
n5.cd_nomenclature AS statut_biologique,
n6.cd_nomenclature AS etat_biologique,
n7.cd_nomenclature AS naturalite,
n8.cd_nomenclature AS preuve_existante,
n9.cd_nomenclature AS precision_diffusion,
n10.cd_nomenclature AS stade_vie,
n11.cd_nomenclature AS sexe,
n12.cd_nomenclature AS objet_denombrement,
n13.cd_nomenclature AS type_denombrement,
n14.cd_nomenclature AS niveau_sensibilite,
n15.cd_nomenclature AS statut_observation,
n16.cd_nomenclature AS floutage_dee,
n17.cd_nomenclature AS statut_source,
n18.cd_nomenclature AS type_info_geo,
n19.cd_nomenclature AS methode_determination,
n20.cd_nomenclature AS statut_validation,
coalesce(s.meta_update_date, s.meta_create_date) AS derniere_action
FROM gn_synthese.synthese s
JOIN ds ON ds.id_dataset = s.id_dataset
JOIN af ON ds.id_acquisition_framework = af.id_acquisition_framework
LEFT JOIN ref_habitats.habref h ON h.cd_hab = s.cd_hab
LEFT JOIN ref_nomenclatures.t_nomenclatures n1 ON s.id_nomenclature_geo_object_nature = n1.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n2 ON s.id_nomenclature_grp_typ = n2.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n3 ON s.id_nomenclature_behaviour = n3.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n4 ON s.id_nomenclature_obs_technique = n4.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n5 ON s.id_nomenclature_bio_status = n5.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n6 ON s.id_nomenclature_bio_condition = n6.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n7 ON s.id_nomenclature_naturalness = n7.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n8 ON s.id_nomenclature_exist_proof = n8.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n9 ON s.id_nomenclature_diffusion_level = n9.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
LEFT JOIN ref_nomenclatures.t_nomenclatures n12 ON s.id_nomenclature_obj_count = n12.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n13 ON s.id_nomenclature_type_count = n13.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n14 ON s.id_nomenclature_sensitivity = n14.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n15 ON s.id_nomenclature_observation_status = n15.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n16 ON s.id_nomenclature_blurring = n16.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n17 ON s.id_nomenclature_source_status = n17.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n18 ON s.id_nomenclature_info_geo_type = n18.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n19 ON s.id_nomenclature_determination_method = n19.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n20 ON s.id_nomenclature_valid_status = n20.id_nomenclature
JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom
JOIN gn_synthese.t_sources ts ON ts.id_source = s.id_source
WHERE ST_INTERSECTS(
s.the_geom_4326,
(SELECT ST_TRANSFORM(ST_UNION(geom),4326) FROM ref_geo.l_areas
JOIN ref_geo.bib_areas_types USING (id_type)
WHERE type_code IN ('ENS_ZO','ENS_ZI')
--AND area_code IN ('SD30','SD29','SD28','SD26','SD24','SD19','SD18','SD17','SD16','SD15','SD12','SD11','SD09','SD06',z'SD05','SD02','SD01','PSND2','PSND1')
))
-- exclision CA ([SICEN] Données anciennes,[TEST] : migration sicen,[SICEN] Hors Etude)
AND ds.id_acquisition_framework NOT IN (53,65,66,1,2,6)
-- exclision JDD `Observations opportunistes du CEN Isère importé depuis Faune Isère`
AND ds.id_dataset NOT IN (185,377,236)
-- exclision CA (`Gestion de l'Espace Naturel Sensible du Méandre des Oves`, `Gestion de la Réserve Naturelle Nationale de l'Ile de la Platière`, `Gestion des Natura 2000 FR 8201749 « Milieux alluviaux et aquatiques de l’Île de la Platière » et FR 8212012 « Île de la Platière »`, `RNN Platière`
--AND (ts.id_module = 7 AND ds.id_acquisition_framework IN (7,38,39,42,44,45,46,48,55,57,58,60)
AND (
unaccent(observers) LIKE ANY (array['%%Conservatoire d%%Espaces Naturels Isere%%', '%%Conservatoire d%%Espaces Naturels d%%Isere%%', '%%CEN Isere%%', '%%Association des Amis de l%%Ile de la Platiere%%'])
OR observers NOT LIKE '%%(%%)%%'
)
AND unaccent(observers) NOT LIKE ALL(array[
'%%Sympetrum%%','%%Departement%%','%%Rhone%%','%%Oxalis%%',
'%%LPO%%','%%GRPLS%%','%%Parvi%%','%%CD Isere%%','%%Personnel%%','%%Independant%%'
'%%DELOCHE Denis%%'
])
AND observers NOT IN ('', 'Benoit Dodelin',', ')
-- statut_validation = 'Certain - très probable'
-- AND n20.cd_nomenclature = '1'
ORDER BY s.id_synthese;
'''
with con_gn.begin() as cnx:
cnx.execute(sql)
+149
View File
@@ -0,0 +1,149 @@
from pycen import con_gn
sql = '''
DROP VIEW IF EXISTS gn_exports.export_taxon_unique;
CREATE VIEW gn_exports.export_taxon_unique AS
WITH af_actors AS (
SELECT cafa.id_acquisition_framework,
json_build_object('type_role',
CASE
WHEN cafa.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cafa.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END,
'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cafa.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cafa.id_role IS NOT NULL THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_acquisition_framework_actor cafa
LEFT JOIN utilisateurs.bib_organismes borg ON cafa.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cafa.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cafa.id_nomenclature_actor_role = tn.id_nomenclature),
af AS (
SELECT taf.id_acquisition_framework,
jsonb_build_object('uuid', taf.unique_acquisition_framework_id, 'name',
taf.acquisition_framework_name,
'desc', taf.acquisition_framework_desc, 'start_date',
taf.acquisition_framework_start_date, 'end_date',
taf.acquisition_framework_end_date,
'initial_closing_date', taf.initial_closing_date, 'territorial_level',
ntl.cd_nomenclature, 'financing_type', nft.cd_nomenclature, 'target_description',
taf.target_description, 'ecologic_or_geologic_target',
taf.ecologic_or_geologic_target, 'actors',
json_agg(af_actors.json_data)) AS af_data
FROM gn_meta.t_acquisition_frameworks taf
JOIN af_actors ON af_actors.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN ref_nomenclatures.t_nomenclatures ntl
ON taf.id_nomenclature_territorial_level = ntl.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nft
ON taf.id_nomenclature_financing_type = nft.id_nomenclature
GROUP BY taf.id_acquisition_framework, taf.acquisition_framework_name, taf.acquisition_framework_desc,
taf.acquisition_framework_start_date, taf.acquisition_framework_end_date, taf.initial_closing_date,
ntl.cd_nomenclature, nft.cd_nomenclature),
ds_actors AS (
SELECT cda.id_dataset,
json_build_object('type_role',
CASE
WHEN cda.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cda.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cda.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cda.id_role IS NOT NULL THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_dataset_actor cda
LEFT JOIN utilisateurs.bib_organismes borg ON cda.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cda.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cda.id_nomenclature_actor_role = tn.id_nomenclature),
ds AS (SELECT tds.id_dataset,
tds.id_acquisition_framework,
-- tds.additional_data,
jsonb_build_object('uuid', tds.unique_dataset_id, 'name', tds.dataset_name, 'desc', tds.dataset_desc,
'shortname', tds.dataset_shortname, 'data_type', ndt.cd_nomenclature,
'collecting_method', ncm.cd_nomenclature, 'data_origin', ndo.cd_nomenclature,
'dataset_objectif', ndso.cd_nomenclature, 'resource_type', nrt.cd_nomenclature,
'source_status', nss.cd_nomenclature, 'territories', array_agg(DISTINCT
ref_nomenclatures.get_cd_nomenclature(cdt.id_nomenclature_territory)),
'actors', json_agg(ds_actors.json_data)) AS dataset_data
FROM gn_meta.t_datasets tds
JOIN ds_actors ON ds_actors.id_dataset = tds.id_dataset
LEFT JOIN gn_meta.cor_dataset_territory cdt ON cdt.id_dataset = tds.id_dataset
LEFT JOIN ref_nomenclatures.t_nomenclatures ndt
ON tds.id_nomenclature_data_type = ndt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ncm
ON tds.id_nomenclature_collecting_method = ncm.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndo
ON tds.id_nomenclature_data_origin = ndo.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndso
ON tds.id_nomenclature_dataset_objectif = ndso.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nrt
ON tds.id_nomenclature_resource_type = nrt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nss
ON tds.id_nomenclature_source_status = nss.id_nomenclature
GROUP BY tds.id_dataset, tds.id_acquisition_framework, tds.unique_dataset_id, tds.dataset_name,
tds.dataset_desc, tds.dataset_shortname, ndt.cd_nomenclature, ncm.cd_nomenclature,
ndo.cd_nomenclature, ndso.cd_nomenclature, nrt.cd_nomenclature, nss.cd_nomenclature)
SELECT DISTINCT ON (s.cd_nom)
s.cd_nom,
s.nom_cite,
t.regne,
t.classe,
t.ordre,
t.famille,
t.sous_famille,
t.cd_ref,
t.lb_nom,
t.nom_complet,
t.nom_vern,
t.group1_inpn,
t.group2_inpn,
t.group3_inpn,
count(s.cd_nom) occurence
FROM gn_synthese.synthese s
JOIN ds ON ds.id_dataset = s.id_dataset
JOIN af ON ds.id_acquisition_framework = af.id_acquisition_framework
LEFT JOIN ref_habitats.habref h ON h.cd_hab = s.cd_hab
LEFT JOIN ref_nomenclatures.t_nomenclatures n1 ON s.id_nomenclature_geo_object_nature = n1.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n2 ON s.id_nomenclature_grp_typ = n2.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n3 ON s.id_nomenclature_behaviour = n3.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n4 ON s.id_nomenclature_obs_technique = n4.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n5 ON s.id_nomenclature_bio_status = n5.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n6 ON s.id_nomenclature_bio_condition = n6.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n7 ON s.id_nomenclature_naturalness = n7.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n8 ON s.id_nomenclature_exist_proof = n8.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n9 ON s.id_nomenclature_diffusion_level = n9.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
LEFT JOIN ref_nomenclatures.t_nomenclatures n12 ON s.id_nomenclature_obj_count = n12.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n13 ON s.id_nomenclature_type_count = n13.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n14 ON s.id_nomenclature_sensitivity = n14.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n15 ON s.id_nomenclature_observation_status = n15.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n16 ON s.id_nomenclature_blurring = n16.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n17 ON s.id_nomenclature_source_status = n17.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n18 ON s.id_nomenclature_info_geo_type = n18.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n19 ON s.id_nomenclature_determination_method = n19.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n20 ON s.id_nomenclature_valid_status = n20.id_nomenclature
JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom
JOIN gn_synthese.t_sources ts ON ts.id_source = s.id_source
Group by s.cd_nom, s.nom_cite, t.regne, t.classe, t.ordre, t.famille, t.sous_famille, t.cd_ref, t.lb_nom, t.nom_complet, t.nom_vern, t.group1_inpn, t.group2_inpn, t.group3_inpn
;
'''
with con_gn.begin() as cnx:
cnx.execute(sql)
@@ -0,0 +1,186 @@
# SCRIPT NON VALIDE À CE JOUR
from pycen import con_gn
sql = '''
DROP VIEW IF EXISTS gn_exports.v_synthese_sinp_with_metadata_flora_for_gn2pg_bis;
CREATE VIEW gn_exports.v_synthese_sinp_with_metadata_flora_for_gn2pg_bis AS
WITH af_actors AS (
SELECT cafa.id_acquisition_framework
FROM gn_meta.cor_acquisition_framework_actor cafa
LEFT JOIN utilisateurs.bib_organismes borg ON cafa.id_organism = borg.id_organisme
WHERE borg.uuid_organisme = '5a433bd0-2070-25d9-e053-2614a8c026f8'::uuid
), af AS (
SELECT taf.id_acquisition_framework
FROM gn_meta.t_acquisition_frameworks taf
JOIN af_actors ON af_actors.id_acquisition_framework = taf.id_acquisition_framework
GROUP BY taf.id_acquisition_framework
), ds AS (
SELECT tds.id_dataset,
tds.dataset_name AS nom_jdd,
tds.id_acquisition_framework
FROM gn_meta.t_datasets tds
GROUP BY tds.id_dataset, tds.dataset_name
), geo AS (
SELECT "left"(geo_1.area_code::text, 2) AS departement,
geo_1.area_code AS commune,
s_1.id_synthese,
st_transform(s_1.the_geom_local, 4326) AS st_transform
FROM ref_geo.l_areas geo_1
JOIN gn_synthese.synthese s_1 ON st_intersects(s_1.the_geom_4326, st_transform(geo_1.geom, 4326))
WHERE geo_1.id_type = 25
)
SELECT
ds.nom_jdd AS nom_jdd,
s.unique_id_sinp_grp AS id_sinp_releve,
occ.id_releve_occtax AS identifiant_releve,
NULL::text AS code_perso_releve,
s.unique_id_sinp AS id_sinp_observation,
s.entity_source_pk_value AS identifiant_observation,
geo.departement,
geo.commune,
NULL::text AS lieu_dit,
CASE
WHEN "position"(sp.srtext::text, 'GEOGCS'::text) = 1 THEN "substring"(replace(sp.srtext::text, 'GEOGCS["'::text, ''::text), 1, "position"(replace(sp.srtext::text, 'GEOGCS["'::text, ''::text), '",'::text) - 1)
WHEN "position"(sp.srtext::text, 'PROJCS'::text) = 1 THEN "substring"(replace(sp.srtext::text, 'PROJCS["'::text, ''::text), 1, "position"(replace(sp.srtext::text, 'PROJCS["'::text, ''::text), '",'::text) - 1)
WHEN "position"(sp.srtext::text, 'GEOCCS'::text) = 1 THEN "substring"(replace(sp.srtext::text, 'GEOCCS["'::text, ''::text), 1, "position"(replace(sp.srtext::text, 'GEOCCS["'::text, ''::text), '",'::text) - 1)
WHEN "position"(sp.srtext::text, 'COMPD_CS'::text) = 1 THEN "substring"(replace(sp.srtext::text, 'COMPD_CS["'::text, ''::text), 1, "position"(replace(sp.srtext::text, 'COMPD_CS["'::text, ''::text), '",'::text) - 1)
ELSE 'Non défini'::text
END AS sys_coord,
st_srid(s.the_geom_4326) AS "SRID",
st_astext(s.the_geom_4326) AS localisation_wkt,
st_x(st_centroid(s.the_geom_4326)) AS coord_x,
st_y(st_centroid(s.the_geom_4326)) AS coord_y,
s."precision" AS precision,
NULL::text AS nature_objet,
s.altitude_min AS alti_min,
s.altitude_max AS alti_max,
NULL::text AS pente,
NULL::text AS exposition,
NULL::text AS comm_geol,
NULL::text AS milieu,
s.observers AS observateurs,
s.date_min AS date_debut,
s.date_max AS date_fin,
NULL::text AS comm_context,
n2.mnemonique AS type_regroupement,
s.grp_method AS meth_regroupement,
NULL::text AS surface,
(s."additional_data"::json#>>'{strate_flore}') ||
ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_strate_flore}')::int)
AS strate_vegetation,
(s."additional_data"::json#>>'{heigth_herbace}')::text || (s."additional_data"::json#>>'{heigth_arbust}')::text
|| (s."additional_data"::json#>>'{heigth_arbore}')::text || (s."additional_data"::json#>>'{heigth_ssarbust}')::text
AS hauteur_strate,
(s."additional_data"::json#>>'{rcvmt_herbace}')::text || (s."additional_data"::json#>>'{rcvmt_arbust}')::text
|| (s."additional_data"::json#>>'{rcvmt_arbore}')::text || (s."additional_data"::json#>>'{rcvmt_ssarbust}')::text
AS recouvrement_strate,
s.cd_hab AS cdhab,
NULL::text AS cdhab_v,
NULL::text AS code_eur,
NULL::text AS code_eunis,
NULL::text AS code_cahab,
NULL::text AS code_cb,
NULL::text AS id_microhab,
n21.regne AS regne,
s.nom_cite AS nom_cite,
s.cd_nom as cd_nom,
(s."additional_data"::json#>>'{effectif_textuel}')::text ||
ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_braunblanq_abdom}')::int)::text
AS abondance,
NULL::text AS sociabilite,
n11.mnemonique AS sexe,
n7.mnemonique AS naturalite,
NULL::text AS comm_description,
n15.mnemonique AS statut_observation,
n12.mnemonique AS objet_denombrement,
n13.mnemonique AS type_denombrement,
s.count_min AS nombre_min,
s.count_max AS nombre_max,
n17.label_default AS statut_source,
NULL::text AS reference_biblio,
NULL::text AS page,
n8.mnemonique AS preuve_existence,
s.digital_proof AS preuve_numerique,
s.non_digital_proof AS preuve_non_numerique,
NULL::text AS nom_collection,
NULL::text AS ref_collection,
s.determiner AS determinateur,
NULL::text AS niv_val,
NULL::text AS niveau_diffusion,
n16.mnemonique AS floutage_dee,
NULL::text AS methode_observation,
CASE WHEN ts.name_source like 'MONITORING_%%'
THEN split_part(ts.name_source,'_',2)
ELSE 'RELEVE FLORE'::text
END AS protocole,
n6.mnemonique AS etat_biologique,
n5.mnemonique AS statut_biologique,
n10.mnemonique AS stade_vie,
n19.mnemonique AS methode_determination,
n3.mnemonique AS comportement,
s.additional_data - '{effectif_textuel,strate_flore,code_atlas,id_nomenclature_braunblanq_abdom,id_nomenclature_strate_flore}'::text[] AS donnees_additionnelles
FROM gn_synthese.synthese s
JOIN ds ON ds.id_dataset = s.id_dataset
JOIN af ON ds.id_acquisition_framework = af.id_acquisition_framework
JOIN geo ON s.id_synthese = geo.id_synthese
JOIN spatial_ref_sys sp ON st_srid(s.the_geom_4326) = sp.auth_srid
LEFT JOIN ref_habitats.habref h ON h.cd_hab = s.cd_hab
LEFT JOIN pr_occtax.t_releves_occtax occ ON occ.unique_id_sinp_grp = s.unique_id_sinp_grp
LEFT JOIN ref_nomenclatures.t_nomenclatures n1 ON s.id_nomenclature_geo_object_nature = n1.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n2 ON s.id_nomenclature_grp_typ = n2.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n3 ON s.id_nomenclature_behaviour = n3.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n4 ON s.id_nomenclature_obs_technique = n4.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n5 ON s.id_nomenclature_bio_status = n5.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n6 ON s.id_nomenclature_bio_condition = n6.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n7 ON s.id_nomenclature_naturalness = n7.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n8 ON s.id_nomenclature_exist_proof = n8.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n9 ON s.id_nomenclature_diffusion_level = n9.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
LEFT JOIN ref_nomenclatures.t_nomenclatures n12 ON s.id_nomenclature_obj_count = n12.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n13 ON s.id_nomenclature_type_count = n13.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n14 ON s.id_nomenclature_sensitivity = n14.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n15 ON s.id_nomenclature_observation_status = n15.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n16 ON s.id_nomenclature_blurring = n16.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n17 ON s.id_nomenclature_source_status = n17.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n18 ON s.id_nomenclature_info_geo_type = n18.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n19 ON s.id_nomenclature_determination_method = n19.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n20 ON s.id_nomenclature_valid_status = n20.id_nomenclature
LEFT JOIN taxonomie.taxref n21 ON s.cd_nom = n21.cd_nom
JOIN gn_synthese.cor_area_synthese cas ON cas.id_synthese = s.id_synthese
-- ADD CEN_38
JOIN gn_synthese.t_sources ts ON ts.id_source = s.id_source
WHERE n21.regne::text != 'Animalia'::text
-- exclision CA ([SICEN] Données anciennes,[TEST] : migration sicen,[SICEN] Hors Etude)
AND ds.id_acquisition_framework NOT IN (
53,1,2,6, -- CA tests
84, -- Echange de données PG Chravas
85, -- Echange de données
116 -- Echange de données issus de SICEN
)
-- exclision JDD `Observations opportunistes du CEN Isère importé depuis Faune Isère`
AND ds.id_dataset NOT IN (
185,377,236,
409 -- Echange de données CORA
)
-- exclision CA (`Gestion de l'Espace Naturel Sensible du Méandre des Oves`, `Gestion de la Réserve Naturelle Nationale de l'Ile de la Platière`, `Gestion des Natura 2000 FR 8201749 « Milieux alluviaux et aquatiques de l’Île de la Platière » et FR 8212012 « Île de la Platière »`, `RNN Platière`
--AND (ts.id_module = 7 AND ds.id_acquisition_framework IN (7,38,39,42,44,45,46,48,55,57,58,60)
AND (
unaccent(observers) LIKE ANY (array['%%Conservatoire d%%Espaces Naturels Isere%%', '%%Conservatoire d%%Espaces Naturels d%%Isere%%', '%%CEN Isere%%', '%%Association des Amis de l%%Ile de la Platiere%%'])
OR observers NOT LIKE '%%(%%)%%'
)
AND unaccent(observers) NOT LIKE ALL(array[
'%%Sympetrum%%','%%Departement%%','%%Rhone%%','%%Oxalis%%',
'%%LPO%%','%%GRPLS%%','%%Parvi%%','%%CD Isere%%','%%Personnel%%','%%Independant%%'
'%%DELOCHE Denis%%'
])
AND observers NOT IN ('', 'Benoit Dodelin',', ')
-- statut_validation = 'Certain - très probable'
-- AND n20.cd_nomenclature = '1'
ORDER BY s.id_synthese;
'''
with con_gn.begin() as cnx:
cnx.execute(sql)
@@ -0,0 +1,203 @@
from pycen import con_gn
sql = '''
DROP VIEW IF EXISTS gn_exports.v_synthese_sinp_with_metadata_flora_for_gn2pg CASCADE;
CREATE VIEW gn_exports.v_synthese_sinp_with_metadata_flora_for_gn2pg AS
WITH af_actors AS (
SELECT cafa.id_acquisition_framework
FROM gn_meta.cor_acquisition_framework_actor cafa
LEFT JOIN utilisateurs.bib_organismes borg ON cafa.id_organism = borg.id_organisme
WHERE borg.uuid_organisme = '5a433bd0-2070-25d9-e053-2614a8c026f8'::uuid
), af AS (
SELECT taf.id_acquisition_framework, unique_acquisition_framework_id
FROM gn_meta.t_acquisition_frameworks taf
JOIN af_actors ON af_actors.id_acquisition_framework = taf.id_acquisition_framework
GROUP BY taf.id_acquisition_framework
), ds AS (
SELECT tds.id_dataset, tds.unique_dataset_id,
tds.dataset_name AS nom_jdd,
tds.id_acquisition_framework
FROM gn_meta.t_datasets tds
GROUP BY tds.id_dataset, tds.dataset_name
), geo AS (
SELECT "left"(geo_1.area_code::text, 2) AS departement,
json_agg(geo_1.area_code) AS commune,
s_1.id_synthese,
st_transform(s_1.the_geom_local, 4326) AS st_transform
FROM ref_geo.l_areas geo_1
JOIN gn_synthese.cor_area_synthese USING (id_area)
JOIN gn_synthese.synthese s_1 USING (id_synthese)
WHERE geo_1.id_type = 25
GROUP BY 1,3,4
)
SELECT
af.unique_acquisition_framework_id id_sinp_ca,
ds.nom_jdd AS nom_jdd,
ds.unique_dataset_id id_sinp_jdd,
s.unique_id_sinp_grp AS id_sinp_releve,
occ.id_releve_occtax AS identifiant_releve,
NULL::text AS code_perso_releve,
s.unique_id_sinp AS id_sinp_observation,
s.entity_source_pk_value AS identifiant_observation,
geo.departement,
geo.commune,
NULL::text AS lieu_dit,
CASE
WHEN "position"(sp.srtext::text, 'GEOGCS'::text) = 1 THEN "substring"(replace(sp.srtext::text, 'GEOGCS["'::text, ''::text), 1, "position"(replace(sp.srtext::text, 'GEOGCS["'::text, ''::text), '",'::text) - 1)
WHEN "position"(sp.srtext::text, 'PROJCS'::text) = 1 THEN "substring"(replace(sp.srtext::text, 'PROJCS["'::text, ''::text), 1, "position"(replace(sp.srtext::text, 'PROJCS["'::text, ''::text), '",'::text) - 1)
WHEN "position"(sp.srtext::text, 'GEOCCS'::text) = 1 THEN "substring"(replace(sp.srtext::text, 'GEOCCS["'::text, ''::text), 1, "position"(replace(sp.srtext::text, 'GEOCCS["'::text, ''::text), '",'::text) - 1)
WHEN "position"(sp.srtext::text, 'COMPD_CS'::text) = 1 THEN "substring"(replace(sp.srtext::text, 'COMPD_CS["'::text, ''::text), 1, "position"(replace(sp.srtext::text, 'COMPD_CS["'::text, ''::text), '",'::text) - 1)
ELSE 'Non défini'::text
END AS sys_coord,
st_srid(s.the_geom_4326) AS "SRID",
st_astext(s.the_geom_4326) AS localisation_wkt,
st_x(st_centroid(s.the_geom_4326)) AS coord_x,
st_y(st_centroid(s.the_geom_4326)) AS coord_y,
s."precision" AS precision,
NULL::text AS nature_objet,
s.altitude_min AS alti_min,
s.altitude_max AS alti_max,
NULL::text AS pente,
NULL::text AS exposition,
NULL::text AS comm_geol,
NULL::text AS milieu,
s.observers AS observateurs,
s.date_min AS date_debut,
s.date_max AS date_fin,
NULL::text AS comm_context,
n2.mnemonique AS type_regroupement,
s.grp_method AS meth_regroupement,
NULL::text AS surface,
CASE WHEN (s."additional_data"::json#>>'{strate_flore}') IS NOT NULL
THEN (s."additional_data"::json#>>'{strate_flore}')::text
WHEN s."additional_data"::json#>>'{id_nomenclature_strate_flore}' IS NOT NULL
THEN ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_strate_flore}')::int)::text
ELSE NULL::text
END AS strate_vegetation,
CASE WHEN ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_strate_flore}')::int)::text = 'Strate herbacée'::text
THEN (s."additional_data"::json#>>'{heigth_herbace}')::text
WHEN ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_strate_flore}')::int)::text = 'Strate arbustive'::text
THEN (s."additional_data"::json#>>'{heigth_arbust}')::text
WHEN ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_strate_flore}')::int)::text = 'Strate arborée'::text
THEN (s."additional_data"::json#>>'{heigth_arbore}')::text
WHEN ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_strate_flore}')::int)::text = 'Strate sous-arbustive'::text
THEN (s."additional_data"::json#>>'{heigth_ssarbust}')::text
ELSE NULL::text
END AS hauteur_strate,
CASE WHEN s."additional_data"::json#>>'{id_nomenclature_strate_flore}' IS NOT NULL
THEN CASE WHEN ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_strate_flore}')::int)::text = 'Strate herbacée'::text
THEN (s."additional_data"::json#>>'{rcvmt_herbace}')::text
WHEN ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_strate_flore}')::int)::text = 'Strate arbustive'::text
THEN (s."additional_data"::json#>>'{rcvmt_arbust}')::text
WHEN ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_strate_flore}')::int)::text = 'Strate arborée'::text
THEN (s."additional_data"::json#>>'{rcvmt_arbore}')::text
WHEN ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_strate_flore}')::int)::text = 'Strate sous-arbustive'::text
THEN (s."additional_data"::json#>>'{rcvmt_ssarbust}')::text
ELSE NULL::text END
ELSE NULL::text
END AS recouvrement_strate,
s.cd_hab AS cdhab,
NULL::text AS cdhab_v,
NULL::text AS code_eur,
NULL::text AS code_eunis,
NULL::text AS code_cahab,
NULL::text AS code_cb,
NULL::text AS id_microhab,
n21.regne AS regne,
s.nom_cite AS nom_cite,
s.cd_nom as cd_nom,
CASE WHEN (s."additional_data"::json#>>'{effectif_textuel}') IS NOT NULL
THEN (s."additional_data"::json#>>'{effectif_textuel}')::text
WHEN s."additional_data"::json#>>'{id_nomenclature_braunblanq_abdom}' IS NOT NULL
THEN ref_nomenclatures.get_nomenclature_label((s."additional_data"::json#>>'{id_nomenclature_braunblanq_abdom}')::int)::text
ELSE NULL::text
END AS abondance,
NULL::text AS sociabilite,
n11.mnemonique AS sexe,
n7.mnemonique AS naturalite,
NULL::text AS comm_description,
n15.mnemonique AS statut_observation,
n12.mnemonique AS objet_denombrement,
n13.mnemonique AS type_denombrement,
s.count_min AS nombre_min,
s.count_max AS nombre_max,
n17.label_default AS statut_source,
NULL::text AS reference_biblio,
NULL::text AS page,
n8.mnemonique AS preuve_existence,
s.digital_proof AS preuve_numerique,
s.non_digital_proof AS preuve_non_numerique,
NULL::text AS nom_collection,
NULL::text AS ref_collection,
s.determiner AS determinateur,
NULL::text AS niv_val,
NULL::text AS niveau_diffusion,
n16.mnemonique AS floutage_dee,
NULL::text AS methode_observation,
CASE WHEN ts.name_source like 'MONITORING_%%'
THEN split_part(ts.name_source,'_',2)
ELSE 'RELEVE FLORE'::text
END AS protocole,
n6.mnemonique AS etat_biologique,
n5.mnemonique AS statut_biologique,
n10.mnemonique AS stade_vie,
n19.mnemonique AS methode_determination,
n3.mnemonique AS comportement,
s.additional_data - '{effectif_textuel,strate_flore,code_atlas,id_nomenclature_braunblanq_abdom,id_nomenclature_strate_flore}'::text[] AS donnees_additionnelles
FROM gn_synthese.synthese s
JOIN ds ON ds.id_dataset = s.id_dataset
JOIN af ON ds.id_acquisition_framework = af.id_acquisition_framework
JOIN geo ON s.id_synthese = geo.id_synthese
JOIN spatial_ref_sys sp ON st_srid(s.the_geom_4326) = sp.auth_srid
LEFT JOIN ref_habitats.habref h ON h.cd_hab = s.cd_hab
LEFT JOIN pr_occtax.t_releves_occtax occ ON occ.unique_id_sinp_grp = s.unique_id_sinp_grp
LEFT JOIN ref_nomenclatures.t_nomenclatures n1 ON s.id_nomenclature_geo_object_nature = n1.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n2 ON s.id_nomenclature_grp_typ = n2.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n3 ON s.id_nomenclature_behaviour = n3.id_nomenclature
-- LEFT JOIN ref_nomenclatures.t_nomenclatures n4 ON s.id_nomenclature_obs_technique = n4.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n5 ON s.id_nomenclature_bio_status = n5.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n6 ON s.id_nomenclature_bio_condition = n6.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n7 ON s.id_nomenclature_naturalness = n7.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n8 ON s.id_nomenclature_exist_proof = n8.id_nomenclature
-- LEFT JOIN ref_nomenclatures.t_nomenclatures n9 ON s.id_nomenclature_diffusion_level = n9.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
LEFT JOIN ref_nomenclatures.t_nomenclatures n12 ON s.id_nomenclature_obj_count = n12.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n13 ON s.id_nomenclature_type_count = n13.id_nomenclature
-- LEFT JOIN ref_nomenclatures.t_nomenclatures n14 ON s.id_nomenclature_sensitivity = n14.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n15 ON s.id_nomenclature_observation_status = n15.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n16 ON s.id_nomenclature_blurring = n16.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n17 ON s.id_nomenclature_source_status = n17.id_nomenclature
-- LEFT JOIN ref_nomenclatures.t_nomenclatures n18 ON s.id_nomenclature_info_geo_type = n18.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n19 ON s.id_nomenclature_determination_method = n19.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n20 ON s.id_nomenclature_valid_status = n20.id_nomenclature
LEFT JOIN taxonomie.taxref n21 ON s.cd_nom = n21.cd_nom
--JOIN gn_synthese.cor_area_synthese cas ON cas.id_synthese = s.id_synthese
-- ADD CEN_38
JOIN gn_synthese.t_sources ts ON ts.id_source = s.id_source
WHERE n21.regne::text = 'Plantae'::text
-- exclision CA ([SICEN] Données anciennes,[TEST] : migration sicen,[SICEN] Hors Etude)
AND ds.id_acquisition_framework NOT IN (53,66,1,2,6)
-- exclision JDD `Observations opportunistes du CEN Isère importé depuis Faune Isère`
AND ds.id_dataset NOT IN (185,377,236)
-- exclision CA (`Gestion de l'Espace Naturel Sensible du Méandre des Oves`, `Gestion de la Réserve Naturelle Nationale de l'Ile de la Platière`, `Gestion des Natura 2000 FR 8201749 « Milieux alluviaux et aquatiques de l’Île de la Platière » et FR 8212012 « Île de la Platière »`, `RNN Platière`
--AND (ts.id_module = 7 AND ds.id_acquisition_framework IN (7,38,39,42,44,45,46,48,55,57,58,60)
AND (
unaccent(observers) LIKE ANY (array['%%Conservatoire d%%Espaces Naturels Isere%%', '%%Conservatoire d%%Espaces Naturels d%%Isere%%', '%%CEN Isere%%', '%%Association des Amis de l%%Ile de la Platiere%%'])
OR observers NOT LIKE '%%(%%)%%'
)
AND unaccent(observers) NOT LIKE ALL(array[
'%%Sympetrum%%','%%Departement%%','%%Rhone%%','%%Oxalis%%',
'%%LPO%%','%%GRPLS%%','%%Parvi%%','%%CD Isere%%','%%Personnel%%','%%Independant%%'
'%%DELOCHE Denis%%'
])
AND observers NOT IN ('', 'Benoit Dodelin',', ')
-- statut_validation = 'Certain - très probable'
-- AND n20.cd_nomenclature = '1'
ORDER BY s.id_synthese;
'''
with con_gn.begin() as cnx:
cnx.execute(sql)
@@ -0,0 +1,172 @@
DROP VIEW IF EXISTS gn_exports.v_synthese_sinp_with_metadata_for_gn2pg;
CREATE VIEW gn_exports.v_synthese_sinp_with_metadata_for_gn2pg AS
WITH af_actors AS (SELECT cafa.id_acquisition_framework,
json_build_object('type_role',
CASE
WHEN cafa.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cafa.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cafa.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cafa.id_role IS NOT NULL THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_acquisition_framework_actor cafa
LEFT JOIN utilisateurs.bib_organismes borg ON cafa.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cafa.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cafa.id_nomenclature_actor_role = tn.id_nomenclature),
af AS (SELECT taf.id_acquisition_framework,
jsonb_build_object('uuid', taf.unique_acquisition_framework_id, 'name',
taf.acquisition_framework_name,
'desc', taf.acquisition_framework_desc, 'start_date',
taf.acquisition_framework_start_date, 'end_date',
taf.acquisition_framework_end_date,
'initial_closing_date', taf.initial_closing_date, 'territorial_level',
ntl.cd_nomenclature, 'financing_type', nft.cd_nomenclature, 'target_description',
taf.target_description, 'ecologic_or_geologic_target',
taf.ecologic_or_geologic_target, 'actors',
json_agg(af_actors.json_data)) AS af_data
FROM gn_meta.t_acquisition_frameworks taf
JOIN af_actors ON af_actors.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN ref_nomenclatures.t_nomenclatures ntl
ON taf.id_nomenclature_territorial_level = ntl.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nft
ON taf.id_nomenclature_financing_type = nft.id_nomenclature
GROUP BY taf.id_acquisition_framework, taf.acquisition_framework_name, taf.acquisition_framework_desc,
taf.acquisition_framework_start_date, taf.acquisition_framework_end_date, taf.initial_closing_date,
ntl.cd_nomenclature, nft.cd_nomenclature),
ds_actors AS (SELECT cda.id_dataset,
json_build_object('type_role',
CASE
WHEN cda.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cda.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cda.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cda.id_role IS NOT NULL THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_dataset_actor cda
LEFT JOIN utilisateurs.bib_organismes borg ON cda.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cda.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cda.id_nomenclature_actor_role = tn.id_nomenclature),
ds AS (SELECT tds.id_dataset,
tds.id_acquisition_framework,
-- tds.additional_data,
jsonb_build_object('uuid', tds.unique_dataset_id, 'name', tds.dataset_name, 'desc', tds.dataset_desc,
'shortname', tds.dataset_shortname, 'data_type', ndt.cd_nomenclature,
'collecting_method', ncm.cd_nomenclature, 'data_origin', ndo.cd_nomenclature,
'dataset_objectif', ndso.cd_nomenclature, 'resource_type', nrt.cd_nomenclature,
'source_status', nss.cd_nomenclature, 'territories', array_agg(DISTINCT
ref_nomenclatures.get_cd_nomenclature(cdt.id_nomenclature_territory)),
'actors', json_agg(ds_actors.json_data)) AS dataset_data
FROM gn_meta.t_datasets tds
JOIN ds_actors ON ds_actors.id_dataset = tds.id_dataset
LEFT JOIN gn_meta.cor_dataset_territory cdt ON cdt.id_dataset = tds.id_dataset
LEFT JOIN ref_nomenclatures.t_nomenclatures ndt
ON tds.id_nomenclature_data_type = ndt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ncm
ON tds.id_nomenclature_collecting_method = ncm.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndo
ON tds.id_nomenclature_data_origin = ndo.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndso
ON tds.id_nomenclature_dataset_objectif = ndso.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nrt
ON tds.id_nomenclature_resource_type = nrt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nss
ON tds.id_nomenclature_source_status = nss.id_nomenclature
GROUP BY tds.id_dataset, tds.id_acquisition_framework, tds.unique_dataset_id, tds.dataset_name,
tds.dataset_desc, tds.dataset_shortname, ndt.cd_nomenclature, ncm.cd_nomenclature,
ndo.cd_nomenclature, ndso.cd_nomenclature, nrt.cd_nomenclature, nss.cd_nomenclature)
SELECT s.id_synthese,
s.entity_source_pk_value AS id_source,
s.unique_id_sinp AS id_perm_sinp,
s.unique_id_sinp_grp AS id_perm_grp_sinp,
s.date_min AS date_debut,
s.date_max AS date_fin,
s.cd_nom,
s.meta_v_taxref AS version_taxref,
s.nom_cite,
s.count_min AS nombre_min,
s.count_max AS nombre_max,
s.altitude_min,
s.altitude_max,
s.depth_min AS profondeur_min,
s.depth_max AS profondeur_max,
s.observers AS observateurs,
s.determiner AS determinateur,
s.validator AS validateur,
s.sample_number_proof AS numero_preuve,
s.digital_proof AS preuve_numerique,
s.non_digital_proof AS preuve_non_numerique,
s.comment_context AS comment_releve,
s.comment_description AS comment_occurrence,
ds.dataset_data AS jdd_data,
af.af_data AS ca_data,
s.reference_biblio,
s.cd_hab AS code_habitat,
h.lb_hab_fr AS habitat,
s.place_name AS nom_lieu,
s.precision,
s.additional_data::TEXT AS donnees_additionnelles,
st_astext(s.the_geom_4326) AS wkt_4326,
n1.cd_nomenclature AS nature_objet_geo,
n2.cd_nomenclature AS type_regroupement,
s.grp_method AS methode_regroupement,
n3.cd_nomenclature AS comportement,
n4.cd_nomenclature AS technique_obs,
n5.cd_nomenclature AS statut_biologique,
n6.cd_nomenclature AS etat_biologique,
n7.cd_nomenclature AS naturalite,
n8.cd_nomenclature AS preuve_existante,
n9.cd_nomenclature AS precision_diffusion,
n10.cd_nomenclature AS stade_vie,
n11.cd_nomenclature AS sexe,
n12.cd_nomenclature AS objet_denombrement,
n13.cd_nomenclature AS type_denombrement,
n14.cd_nomenclature AS niveau_sensibilite,
n15.cd_nomenclature AS statut_observation,
n16.cd_nomenclature AS floutage_dee,
n17.cd_nomenclature AS statut_source,
n18.cd_nomenclature AS type_info_geo,
n19.cd_nomenclature AS methode_determination,
n20.cd_nomenclature AS statut_validation,
coalesce(s.meta_update_date, s.meta_create_date) AS derniere_action
FROM gn_synthese.synthese s
JOIN ds ON ds.id_dataset = s.id_dataset
JOIN af ON ds.id_acquisition_framework = af.id_acquisition_framework
LEFT JOIN ref_habitats.habref h ON h.cd_hab = s.cd_hab
LEFT JOIN ref_nomenclatures.t_nomenclatures n1 ON s.id_nomenclature_geo_object_nature = n1.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n2 ON s.id_nomenclature_grp_typ = n2.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n3 ON s.id_nomenclature_behaviour = n3.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n4 ON s.id_nomenclature_obs_technique = n4.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n5 ON s.id_nomenclature_bio_status = n5.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n6 ON s.id_nomenclature_bio_condition = n6.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n7 ON s.id_nomenclature_naturalness = n7.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n8 ON s.id_nomenclature_exist_proof = n8.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n9 ON s.id_nomenclature_diffusion_level = n9.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
LEFT JOIN ref_nomenclatures.t_nomenclatures n12 ON s.id_nomenclature_obj_count = n12.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n13 ON s.id_nomenclature_type_count = n13.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n14 ON s.id_nomenclature_sensitivity = n14.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n15 ON s.id_nomenclature_observation_status = n15.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n16 ON s.id_nomenclature_blurring = n16.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n17 ON s.id_nomenclature_source_status = n17.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n18 ON s.id_nomenclature_info_geo_type = n18.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n19 ON s.id_nomenclature_determination_method = n19.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n20 ON s.id_nomenclature_valid_status = n20.id_nomenclature
ORDER BY s.id_synthese;
+52
View File
@@ -0,0 +1,52 @@
import requests
import geopandas as gpd
def get_orb_token():
login = 'cgeier'
pwd = 'adm1n*cEn38'
url = "https://donnees.biodiversite-auvergne-rhone-alpes.fr/api/auth/login"
return requests.post(
url,
json={"login": login, "password": pwd},
headers={'Content-Type': 'application/json'}
)
def get_orb_sp(tok, params: dict = None, geo=None):
import json
print("LOAD ORB DATA ...")
url = "https://donnees.biodiversite-auvergne-rhone-alpes.fr/api/synthese/for_web?"
if geo:
params += {
# "geoIntersection":{"type":"Feature","properties":{},"geometry":_json_geo['features'][0]['geometry']},
"geoIntersection": geo.to_crs(4326).unary_union.wkt,
"with_areas": False
}
res = requests.post(
url,
headers={'Content-Type': 'application/json'},
cookies=tok.cookies,
json=params)
_orb_geo = gpd.read_file(res.text)
orb_geo = (
_orb_geo[_orb_geo.geom_type == 'Point']
.reset_index(drop=True)
.to_crs(2154))
orb_geo['cd_nom'] = [
[cd['cd_nom'] for cd in json.loads(o)]
for o in orb_geo.observations
]
orb = orb_geo.explode('cd_nom')
# orb.drop(['observations','cd_nom'],axis=1,inplace=True)
return orb
if __name__ == "__main__":
tok = get_orb_token()
orb = get_orb_sp(tok, params={'regne': 'Animalia'})
+41
View File
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import geopandas as gpd
import requests
from os import path
import io
def get_zh(geom=None):
url = 'https://geonature.cen-isere.fr/geonature/api/exports/api/9?limit=30000&{geo}'
if not geom.empty :
if geom.crs.srs.lower() != 'epsg:4326':
geom.to_crs(4326,inplace=True)
if gpd.__version__ >='1.0.1':
geometry = 'geometry={geom}'.format(geom=geom.union_all().wkt)
else:
geometry = 'geometry={geom}'.format(geom=geom.unary_union.wkt)
else:
geom = ''
print(url.format(geo=geometry))
r = requests.get(url.format(geo=geometry))
if r.status_code == 200:
d = r.json()
data = d['items']['features']
p = [i['properties'] for i in data]
g = [i['geometry'] for i in data]
df = gpd.GeoDataFrame.from_features(data,crs=4326)
return df
if __name__ == "__main__":
PATH = '/media/cgeier/Disk2/tmp/GEONATURE/ST MARTIN URIAGE'
FILE = 'ZH ENS POUR CEN 14102025.gpkg'
f = gpd.read_file(path.join(PATH,FILE))
df = get_zh(f)
# NEED GeoPandas >=1.0.1 pour sauvegarder
df.to_file(path.join(PATH,'inventaire_zoneshumides_seglieres.gpkg'))
@@ -0,0 +1,276 @@
from pycen import con_gn
sql = '''
DROP VIEW IF EXISTS gn_exports.v_synthese_sinp_with_metadata_invertebre_for_gn2pg;
CREATE VIEW gn_exports.v_synthese_sinp_with_metadata_invertebre_for_gn2pg AS
WITH af_actors AS (SELECT cafa.id_acquisition_framework,
json_build_object('type_role',
CASE
WHEN cafa.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cafa.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cafa.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cafa.id_role IS NOT NULL THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_acquisition_framework_actor cafa
LEFT JOIN utilisateurs.bib_organismes borg ON cafa.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cafa.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cafa.id_nomenclature_actor_role = tn.id_nomenclature),
af_territories AS (SELECT caft.id_acquisition_framework,
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS territories
FROM gn_meta.cor_acquisition_framework_territory caft
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON caft.id_nomenclature_territory =
t_nomenclatures.id_nomenclature
GROUP BY caft.id_acquisition_framework),
af_objectives AS (SELECT cafo.id_acquisition_framework,
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS objectives
FROM gn_meta.cor_acquisition_framework_objectif cafo
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON cafo.id_nomenclature_objectif =
t_nomenclatures.id_nomenclature
GROUP BY cafo.id_acquisition_framework),
af_voletsinp AS (SELECT cafv.id_acquisition_framework,
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS voletsinp
FROM gn_meta.cor_acquisition_framework_voletsinp cafv
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON cafv.id_nomenclature_voletsinp =
t_nomenclatures.id_nomenclature
GROUP BY cafv.id_acquisition_framework),
af_publication AS (SELECT cafp.id_acquisition_framework,
array_agg(DISTINCT
jsonb_build_object('uuid', sinp_datatype_publications.unique_publication_id,
'reference',
sinp_datatype_publications.publication_reference,
'url',
sinp_datatype_publications.publication_url)) AS publications
FROM gn_meta.cor_acquisition_framework_publication cafp
LEFT JOIN gn_meta.sinp_datatype_publications
ON cafp.id_publication = sinp_datatype_publications.id_publication
GROUP BY cafp.id_acquisition_framework)
,
af AS
(SELECT taf.id_acquisition_framework,
jsonb_build_object('uuid', taf.unique_acquisition_framework_id, 'name',
taf.acquisition_framework_name,
'desc', taf.acquisition_framework_desc, 'start_date',
taf.acquisition_framework_start_date, 'end_date',
taf.acquisition_framework_end_date,
'initial_closing_date', taf.initial_closing_date, 'territories',
af_territories.territories, 'territorial_level',
ntl.cd_nomenclature, 'territory_desc', taf.territory_desc, 'objectives',
af_objectives.objectives, 'publications', af_publication.publications,
'financing_type', nft.cd_nomenclature,
'target_description',
taf.target_description, 'ecologic_or_geologic_target',
taf.ecologic_or_geologic_target, 'actors',
json_agg(af_actors.json_data), 'is_parent', taf.is_parent, 'parent_uuid',
tafp.unique_acquisition_framework_id) AS af_data
FROM gn_meta.t_acquisition_frameworks taf
LEFT JOIN gn_meta.t_acquisition_frameworks tafp
ON tafp.id_acquisition_framework = taf.acquisition_framework_parent_id
JOIN af_actors ON af_actors.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN ref_nomenclatures.t_nomenclatures ntl
ON taf.id_nomenclature_territorial_level = ntl.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nft
ON taf.id_nomenclature_financing_type = nft.id_nomenclature
LEFT JOIN af_territories ON af_territories.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN af_objectives ON af_objectives.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN af_voletsinp ON af_voletsinp.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN af_publication ON af_publication.id_acquisition_framework = taf.id_acquisition_framework
GROUP BY taf.id_acquisition_framework, taf.acquisition_framework_name, taf.acquisition_framework_desc,
taf.acquisition_framework_start_date, taf.acquisition_framework_end_date, taf.initial_closing_date,
ntl.cd_nomenclature, nft.cd_nomenclature, af_territories.territories, af_objectives.objectives,
af_voletsinp.voletsinp, af_publication.publications, taf.is_parent,
tafp.unique_acquisition_framework_id),
ds_actors AS (SELECT cda.id_dataset,
json_build_object('type_role',
CASE
WHEN cda.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cda.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cda.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cda.id_role IS NOT NULL THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_dataset_actor cda
LEFT JOIN utilisateurs.bib_organismes borg ON cda.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cda.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cda.id_nomenclature_actor_role = tn.id_nomenclature),
ds_protocols AS (SELECT cdp.id_dataset,
jsonb_build_object(
'uuid', sdp.unique_protocol_id,
'name', sdp.protocol_name,
'desc', sdp.protocol_desc,
'url', sdp.protocol_url,
'type', t_nomenclatures.cd_nomenclature) AS protocols
FROM gn_meta.cor_dataset_protocol cdp
JOIN gn_meta.sinp_datatype_protocols sdp
ON cdp.id_protocol = sdp.id_protocol
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON sdp.id_nomenclature_protocol_type = t_nomenclatures.id_nomenclature)
,
ds AS (SELECT tds.id_dataset,
tds.id_acquisition_framework,
-- tds.additional_data,
jsonb_build_object('uuid', tds.unique_dataset_id, 'name', tds.dataset_name, 'desc', tds.dataset_desc,
'shortname', tds.dataset_shortname, 'data_type', ndt.cd_nomenclature,
'keywords', tds.keywords, 'marine_domain', tds.marine_domain,
'terrestrial_domain', tds.terrestrial_domain, 'collecting_method',
ncm.cd_nomenclature, 'protocols',
ds_protocols.protocols,
'data_origin', ndo.cd_nomenclature,
'dataset_objectif', ndso.cd_nomenclature, 'resource_type', nrt.cd_nomenclature,
'source_status', nss.cd_nomenclature, 'territories', array_agg(DISTINCT
ref_nomenclatures.get_cd_nomenclature(cdt.id_nomenclature_territory)),
'actors', json_agg(ds_actors.json_data)) AS dataset_data
FROM gn_meta.t_datasets tds
JOIN ds_actors ON ds_actors.id_dataset = tds.id_dataset
LEFT JOIN gn_meta.cor_dataset_territory cdt ON cdt.id_dataset = tds.id_dataset
LEFT JOIN ds_protocols ON ds_protocols.id_dataset = tds.id_dataset
LEFT JOIN ref_nomenclatures.t_nomenclatures ndt
ON tds.id_nomenclature_data_type = ndt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ncm
ON tds.id_nomenclature_collecting_method = ncm.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndo
ON tds.id_nomenclature_data_origin = ndo.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndso
ON tds.id_nomenclature_dataset_objectif = ndso.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nrt
ON tds.id_nomenclature_resource_type = nrt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nss
ON tds.id_nomenclature_source_status = nss.id_nomenclature
GROUP BY tds.id_dataset, tds.id_acquisition_framework, tds.unique_dataset_id, tds.dataset_name,
tds.dataset_desc, tds.dataset_shortname, ndt.cd_nomenclature, ncm.cd_nomenclature,
ndo.cd_nomenclature, ndso.cd_nomenclature, nrt.cd_nomenclature, nss.cd_nomenclature,
ds_protocols.protocols)
SELECT s.id_synthese,
s.entity_source_pk_value AS id_source,
s.unique_id_sinp AS id_perm_sinp,
s.unique_id_sinp_grp AS id_perm_grp_sinp,
s.date_min AS date_debut,
s.date_max AS date_fin,
s.cd_nom,
s.meta_v_taxref AS version_taxref,
s.nom_cite,
s.count_min AS nombre_min,
s.count_max AS nombre_max,
s.altitude_min,
s.altitude_max,
s.depth_min AS profondeur_min,
s.depth_max AS profondeur_max,
s.observers AS observateurs,
s.determiner AS determinateur,
s.validator AS validateur,
s.sample_number_proof AS numero_preuve,
s.digital_proof AS preuve_numerique,
s.non_digital_proof AS preuve_non_numerique,
s.comment_context AS comment_releve,
s.comment_description AS comment_occurrence,
ds.dataset_data AS jdd_data,
af.af_data AS ca_data,
s.reference_biblio,
s.cd_hab AS code_habitat,
h.lb_hab_fr AS habitat,
s.place_name AS nom_lieu,
s.precision,
s.additional_data AS donnees_additionnelles,
st_astext(s.the_geom_4326) AS wkt_4326,
n1.cd_nomenclature AS nature_objet_geo,
n2.cd_nomenclature AS type_regroupement,
s.grp_method AS methode_regroupement,
n3.cd_nomenclature AS comportement,
n4.cd_nomenclature AS technique_obs,
n5.cd_nomenclature AS statut_biologique,
n6.cd_nomenclature AS etat_biologique,
n7.cd_nomenclature AS naturalite,
n8.cd_nomenclature AS preuve_existante,
n9.cd_nomenclature AS precision_diffusion,
n10.cd_nomenclature AS stade_vie,
n11.cd_nomenclature AS sexe,
n12.cd_nomenclature AS objet_denombrement,
n13.cd_nomenclature AS type_denombrement,
n14.cd_nomenclature AS niveau_sensibilite,
n15.cd_nomenclature AS statut_observation,
n16.cd_nomenclature AS floutage_dee,
n17.cd_nomenclature AS statut_source,
n18.cd_nomenclature AS type_info_geo,
n19.cd_nomenclature AS methode_determination,
n20.cd_nomenclature AS statut_validation,
coalesce(s.meta_update_date, s.meta_create_date) AS derniere_action
FROM gn_synthese.synthese s
JOIN ds ON ds.id_dataset = s.id_dataset
JOIN af ON ds.id_acquisition_framework = af.id_acquisition_framework
LEFT JOIN ref_habitats.habref h ON h.cd_hab = s.cd_hab
LEFT JOIN ref_nomenclatures.t_nomenclatures n1 ON s.id_nomenclature_geo_object_nature = n1.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n2 ON s.id_nomenclature_grp_typ = n2.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n3 ON s.id_nomenclature_behaviour = n3.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n4 ON s.id_nomenclature_obs_technique = n4.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n5 ON s.id_nomenclature_bio_status = n5.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n6 ON s.id_nomenclature_bio_condition = n6.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n7 ON s.id_nomenclature_naturalness = n7.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n8 ON s.id_nomenclature_exist_proof = n8.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n9 ON s.id_nomenclature_diffusion_level = n9.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
LEFT JOIN ref_nomenclatures.t_nomenclatures n12 ON s.id_nomenclature_obj_count = n12.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n13 ON s.id_nomenclature_type_count = n13.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n14 ON s.id_nomenclature_sensitivity = n14.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n15 ON s.id_nomenclature_observation_status = n15.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n16 ON s.id_nomenclature_blurring = n16.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n17 ON s.id_nomenclature_source_status = n17.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n18 ON s.id_nomenclature_info_geo_type = n18.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n19 ON s.id_nomenclature_determination_method = n19.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n20 ON s.id_nomenclature_valid_status = n20.id_nomenclature
-- ADD CEN_38
JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom
JOIN gn_synthese.t_sources ts ON ts.id_source = s.id_source
WHERE t.regne = 'Animalia'
AND t.phylum <> 'Chordata'
-- exclision CA ([SICEN] Données anciennes,[TEST] : migration sicen,[SICEN] Hors Etude)
AND ds.id_acquisition_framework NOT IN (
53,1,2,6, -- CA tests
84, -- Echange de données PG Chravas
85, -- Echange de données
116 -- Echange de données issus de SICEN
)
-- exclision CA (`Gestion de l'Espace Naturel Sensible du Méandre des Oves`, `Gestion de la Réserve Naturelle Nationale de l'Ile de la Platière`, `Gestion des Natura 2000 FR 8201749 « Milieux alluviaux et aquatiques de l’Île de la Platière » et FR 8212012 « Île de la Platière »`, `RNN Platière`
--AND (ts.id_module = 7 AND ds.id_acquisition_framework IN (7,38,39,42,44,45,46,48,55,57,58,60)
AND (
unaccent(observers) LIKE ANY (array['%%Conservatoire d%%Espaces Naturels Isere%%', '%%Conservatoire d%%Espaces Naturels d%%Isere%%', '%%CEN Isere%%', '%%Association des Amis de l%%Ile de la Platiere%%'])
OR observers NOT LIKE '%%(%%)%%'
)
AND unaccent(observers) NOT LIKE ALL(array[
'%%Sympetrum%%','%%Departement%%','%%Rhone%%','%%Oxalis%%',
'%%LPO%%','%%GRPLS%%','%%Parvi%%','%%CD Isere%%','%%CBNA%%',
'%%Flavia%%','%%Gentiana%%','%%region%%','%%Personnel%%','%%Independant%%'
])
AND observers NOT IN ('', 'Benoit Dodelin',', ')
AND ds.id_dataset NOT IN (185,377,236,409)
-- exclision JDD `Observations opportunistes du CEN Isère importé depuis Faune Isère`
-- statut_validation = 'Certain - très probable'
-- AND n20.cd_nomenclature = '1'
AND s.cd_nom != 781926 -- Paradiarsia punicea (Hübner, 1803) ; Espèce en danger critique à faire remonter une fois la liste de sensibilité invertébrée sortie !
ORDER BY s.id_synthese;
'''
with con_gn.begin() as cnx:
cnx.execute(sql)
+75
View File
@@ -0,0 +1,75 @@
from pycen import con_gn
sql = """
DROP VIEW IF EXISTS gn_exports.v_synthese_sinp_acquisition_flore_with_metadata_for_gn2pg CASCADE;
CREATE OR REPLACE VIEW gn_exports.v_synthese_sinp_acquisition_flore_with_metadata_for_gn2pg AS
WITH af_actors AS
(SELECT cafa.*
FROM gn_meta.cor_acquisition_framework_actor cafa
LEFT JOIN utilisateurs.bib_organismes borg ON cafa.id_organism = borg.id_organisme
--WHERE borg.uuid_organisme = '5a433bd0-2070-25d9-e053-2614a8c026f8'::uuid
--OR borg.uuid_organisme = 'a3c44538-f22a-4134-9e21-28646a73986b'::uuid
), act AS
(SELECT *
FROM crosstab( 'SELECT id_acquisition_framework, id_nomenclature_actor_role, id_organism
FROM gn_meta.cor_acquisition_framework_actor
WHERE id_acquisition_framework NOT IN (1,6)
ORDER BY 1,2' , $$VALUES ('359'::text), ('361')$$ ) AS ct ("id_acquisition_framework" int, "Contact principal" int, "Producteur du jeu de données" int))
SELECT taf.id_acquisition_framework AS id_ca,
taf.unique_acquisition_framework_id AS id_sinp_ca,
taf.acquisition_framework_name AS libelle,
NULL::text AS cadre_acquisition_parent,
taf.acquisition_framework_desc AS description,
taf.keywords AS mots_cles,
ref1.label_default as niveau_territorial,
taf.territory_desc AS description_territoire,
json_agg(ref2.label_default) AS objectifs_cadre_acquisition,
ref4.label_default AS volet_SINP,
ref3.label_default AS type_financement,
taf.target_description AS description_cible,
to_char(taf.meta_create_date, 'DD-MM-YYYY')::date AS date_debut,
NULL::date AS date_fin,
ref5.nom_organisme AS acteur1_organisme,
NULL::text AS acteur1_personne_groupe,
'Contact principal' AS acteur1_type_role,
ref6.nom_organisme AS acteur2_organisme,
NULL::text AS acteur2_personne_groupe,
CASE
WHEN ref6.nom_organisme IS NOT NULL THEN 'Producteur du jeu de données'
ELSE NULL
END AS acteur2_type_role,
NULL::text AS acteur3_organisme,
NULL::text AS acteur3_personne_groupe,
NULL::text AS acteur3_type_role
FROM gn_meta.t_acquisition_frameworks taf
left JOIN af_actors ON af_actors.id_acquisition_framework = taf.id_acquisition_framework
left JOIN gn_meta.cor_acquisition_framework_objectif obj ON obj.id_acquisition_framework = taf.id_acquisition_framework
left JOIN ref_nomenclatures.t_nomenclatures ref1 ON ref1.id_nomenclature = taf.id_nomenclature_territorial_level
JOIN ref_nomenclatures.t_nomenclatures ref2 ON ref2.id_nomenclature = obj.id_nomenclature_objectif
JOIN ref_nomenclatures.t_nomenclatures ref3 ON ref3.id_nomenclature = taf.id_nomenclature_financing_type
left JOIN gn_meta.cor_acquisition_framework_voletsinp sinp ON sinp.id_acquisition_framework = taf.id_acquisition_framework
left JOIN ref_nomenclatures.t_nomenclatures ref4 ON ref4.id_nomenclature = sinp.id_nomenclature_voletsinp
left JOIN act ON act.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN utilisateurs.bib_organismes ref5 ON ref5.id_organisme = act."Contact principal"
LEFT JOIN utilisateurs.bib_organismes ref6 ON ref6.id_organisme = act."Producteur du jeu de données"
join gn_exports.v_synthese_sinp_with_metadata_flora_for_gn2pg vsswmffgp on vsswmffgp.id_sinp_ca = taf.unique_acquisition_framework_id
GROUP BY taf.id_acquisition_framework,
taf.unique_acquisition_framework_id,
taf.acquisition_framework_name,
taf.acquisition_framework_desc,
taf.keywords,
ref1.label_default,
taf.territory_desc,
ref4.label_default,
ref3.label_default,
taf.target_description,
to_char(taf.meta_create_date, 'DD-MM-YYYY')::date,
ref5.nom_organisme,
ref6.nom_organisme
order by 1
;
"""
with con_gn.begin() as cnx:
cnx.execute(sql)
+87
View File
@@ -0,0 +1,87 @@
from pycen import con_gn
sql = '''
DROP VIEW IF EXISTS gn_exports.v_synthese_sinp_jeu_donnees_flore_with_metadata_for_gn2pg CASCADE;
CREATE VIEW gn_exports.v_synthese_sinp_jeu_donnees_flore_with_metadata_for_gn2pg AS
WITH ds_actors AS (
SELECT cda.id_dataset,
borg.nom_organisme,
cda.id_role,
borg.uuid_organisme,
tro.nom_role,
tro.prenom_role,
borg.email_organisme,
tro.email
FROM gn_meta.cor_dataset_actor cda
LEFT JOIN utilisateurs.bib_organismes borg ON cda.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cda.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn ON cda.id_nomenclature_actor_role = tn.id_nomenclature
-- WHERE borg.uuid_organisme = '5a433bd0-2070-25d9-e053-2614a8c026f8'::uuid
-- OR borg.uuid_organisme = 'a3c44538-f22a-4134-9e21-28646a73986b'::uuid
),
actor AS (
SELECT *
FROM crosstab( 'SELECT id_dataset, id_nomenclature_actor_role, id_organism
FROM gn_meta.cor_dataset_actor
ORDER BY 1,2' ,
$$VALUES ('359'), ('364'), ('365'), ('395')$$ ) AS ct ("id_dataset" int, "Contact principal" int, "Producteur du jeu de données" int, "Point de contact base de données de production" int, "Point de contact pour les métadonnées" int)
),
ds AS (
SELECT distinct tds.id_dataset AS id_jdd,
tds.unique_dataset_id AS id_sinp_jdd,
acq.acquisition_framework_name AS cadre_acquisiton,
tds.dataset_name AS nom_jeu_donnees,
tds.dataset_shortname AS nom_court,
tds.dataset_desc AS description,
ndso.label_default AS objectif,
ncm.label_default AS methode_collecte,
ndo.label_default AS origine_donnees,
nss.label_default AS statut_source,
tds.keywords AS mots_cles,
act1.nom_organisme AS acteur1_organisme,
NULL::text AS acteur1_personne_groupe,
'Contact principal' AS acteur1_type_role,
act2.nom_organisme AS acteur2_organisme,
NULL::text AS acteur2_personne_groupe,
CASE
WHEN act2.nom_organisme IS NOT NULL THEN 'Producteur du jeu de données'
ELSE NULL
END AS acteur2_type_role,
act3.nom_organisme AS acteur3_organisme,
NULL::text AS acteur3_personne_groupe,
CASE
WHEN act3.nom_organisme IS NOT NULL THEN 'Point de contact base de données de production'
ELSE NULL
END AS acteur3_type_role,
act4.nom_organisme AS acteur4_organisme,
NULL::text AS acteur4_personne_groupe,
CASE
WHEN act4.nom_organisme IS NOT NULL THEN 'Point de contact pour les métadonnées'
ELSE NULL
END AS acteur4_type_role
FROM gn_meta.t_datasets tds
left JOIN ds_actors ON ds_actors.id_dataset = tds.id_dataset
left JOIN actor ON actor.id_dataset = tds.id_dataset
JOIN gn_meta.t_acquisition_frameworks acq ON tds.id_acquisition_framework = acq.id_acquisition_framework
LEFT JOIN gn_meta.cor_dataset_territory cdt ON cdt.id_dataset = tds.id_dataset
LEFT JOIN ref_nomenclatures.t_nomenclatures ndt ON tds.id_nomenclature_data_type = ndt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ncm ON tds.id_nomenclature_collecting_method = ncm.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndo ON tds.id_nomenclature_data_origin = ndo.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndso ON tds.id_nomenclature_dataset_objectif = ndso.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nrt ON tds.id_nomenclature_resource_type = nrt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nss ON tds.id_nomenclature_source_status = nss.id_nomenclature
LEFT JOIN utilisateurs.bib_organismes act1 ON actor."Contact principal" = act1.id_organisme
LEFT JOIN utilisateurs.bib_organismes act2 ON actor."Producteur du jeu de données" = act2.id_organisme
LEFT JOIN utilisateurs.bib_organismes act3 ON actor."Point de contact base de données de production" = act3.id_organisme
LEFT JOIN utilisateurs.bib_organismes act4 ON actor."Point de contact pour les métadonnées" = act4.id_organisme
join gn_exports.v_synthese_sinp_with_metadata_flora_for_gn2pg vsswmffgp on vsswmffgp.id_sinp_jdd = tds.unique_dataset_id
GROUP BY tds.id_dataset, acq.acquisition_framework_name, tds.unique_dataset_id, tds.dataset_name, tds.dataset_shortname, tds.dataset_desc, ndso.label_default, ncm.label_default, ndo.label_default, nss.label_default, ds_actors.nom_organisme, act1.nom_organisme, act2.nom_organisme, act3.nom_organisme, act4.nom_organisme
)
SELECT * FROM ds order by 1
--WHERE acteur1_organisme IN ('Conservatoire d’espaces naturels Isère')
;
'''
with con_gn.begin() as cnx:
cnx.execute(sql)
+20
View File
@@ -0,0 +1,20 @@
from pycen import con_gn
sql = '''
CREATE OR REPLACE VIEW gn_exports.v_bam_widget AS
SELECT
t.cd_ref AS cd_ref,
t.nom_vern AS nom_vernaculaire,
t.lb_nom AS nom_scientifique,
s.id_synthese AS id_synthese,
s.date_min AS date_min,
s.date_max AS date_max,
s.the_geom_4326 AS the_geom_4326,
t.classe AS classe
FROM gn_synthese.synthese s
JOIN taxonomie.taxref t USING(cd_nom)
;
'''
with con_gn.begin() as cnx:
cnx.execute(sql)
@@ -0,0 +1,41 @@
from pycen import con_gn
sql = '''
DROP VIEW IF EXISTS gn_exports.v_eee_n2000_platiere;
CREATE OR REPLACE VIEW gn_exports.v_eee_n2000_platiere
AS
SELECT
v.*
FROM gn_synthese.v_synthese_for_export v
JOIN ref_geo.l_areas ON st_intersects(ST_GeomFromGeoJSON(v.geojson_4326),st_transform(l_areas.geom,4326))
JOIN ref_geo.bib_areas_types bib USING (id_type)
WHERE bib.type_code = 'ZPS'
AND area_name ilike '%%plati%%re%%'
AND v.cd_ref in (100330, 101055, 101237, 101286, 103139, 103543, 103545, 103547,
103557, 104074, 104805, 105017, 105433, 105615, 105689, 105960,
106252, 106571, 106742, 106748, 106754, 106965, 107446, 108628,
108642, 108810, 109141, 109911, 109926, 109954, 109980, 110762,
111863, 111881, 112100, 112111, 112130, 112195, 112463, 112467,
112482, 112712, 112790, 113418, 114024, 115527, 116089, 116137,
116485, 117503, 117505, 117723, 117860, 117937, 118477, 119474,
119558, 119595, 119854, 122630, 124025, 124164, 124168, 124378,
124635, 124646, 124719, 124730, 125331, 128504, 128748, 128863,
128954, 129468, 130484, 130491, 159690, 159937, 4419, 446169,
448413, 454932, 4872, 611690, 611753, 612522, 717136, 717180,
79766, 79877, 80086, 80824, 81955, 81978, 82018, 82080,
82093, 82164, 83938, 84057, 84251, 85186, 85469, 85949,
85957, 86167, 86513, 86817, 86869, 86975, 89452, 90192,
90234, 92572, 92649, 92663, 92793, 93020, 93129, 93613,
93923, 93924, 94168, 94489, 95679, 95823, 95831, 95965,
95975, 95980, 96149, 96585, 96644, 96739, 96749, 96775,
97346, 97594, 97666, 97961, 99260, 99359, 95983, 96814,
117507, 129959, 81992, 90532, 97623, 104353, 111886, 112483,
125369, 109037, 96624, 101056, 106800, 109949, 116762, 125324
)
;
'''
with con_gn.begin() as cnx:
cnx.execute(sql)
+273
View File
@@ -0,0 +1,273 @@
from pycen import con_gn
sql = '''
DROP VIEW IF EXISTS gn_exports.v_synthese_negria_forcenra;
CREATE OR REPLACE VIEW gn_exports.v_synthese_negria_forcenra
AS
WITH af_actors AS (
SELECT
cafa.id_acquisition_framework,
json_build_object('type_role',
CASE
WHEN cafa.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cafa.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cafa.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cafa.id_role IS NOT NULL THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_acquisition_framework_actor cafa
LEFT JOIN utilisateurs.bib_organismes borg ON cafa.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cafa.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cafa.id_nomenclature_actor_role = tn.id_nomenclature
), af_territories AS (
SELECT
caft.id_acquisition_framework,
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS territories
FROM gn_meta.cor_acquisition_framework_territory caft
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON caft.id_nomenclature_territory =
t_nomenclatures.id_nomenclature
GROUP BY caft.id_acquisition_framework
), af_objectives AS (
SELECT
cafo.id_acquisition_framework,
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS objectives
FROM gn_meta.cor_acquisition_framework_objectif cafo
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON cafo.id_nomenclature_objectif =
t_nomenclatures.id_nomenclature
GROUP BY cafo.id_acquisition_framework
), af_voletsinp AS (
SELECT
cafv.id_acquisition_framework,
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS voletsinp
FROM gn_meta.cor_acquisition_framework_voletsinp cafv
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON cafv.id_nomenclature_voletsinp =
t_nomenclatures.id_nomenclature
GROUP BY cafv.id_acquisition_framework
), af_publication AS (
SELECT
cafp.id_acquisition_framework,
array_agg(DISTINCT
jsonb_build_object('uuid', sinp_datatype_publications.unique_publication_id,
'reference',
sinp_datatype_publications.publication_reference,
'url',
sinp_datatype_publications.publication_url)) AS publications
FROM gn_meta.cor_acquisition_framework_publication cafp
LEFT JOIN gn_meta.sinp_datatype_publications
ON cafp.id_publication = sinp_datatype_publications.id_publication
GROUP BY cafp.id_acquisition_framework
), af AS (
SELECT
taf.id_acquisition_framework,
jsonb_build_object('uuid', taf.unique_acquisition_framework_id, 'name',
taf.acquisition_framework_name,
'desc', taf.acquisition_framework_desc, 'start_date',
taf.acquisition_framework_start_date, 'end_date',
taf.acquisition_framework_end_date,
'initial_closing_date', taf.initial_closing_date, 'territories',
af_territories.territories, 'territorial_level',
ntl.cd_nomenclature, 'territory_desc', taf.territory_desc, 'objectives',
af_objectives.objectives, 'publications', af_publication.publications,
'financing_type', nft.cd_nomenclature,
'target_description',
taf.target_description, 'ecologic_or_geologic_target',
taf.ecologic_or_geologic_target, 'actors',
json_agg(af_actors.json_data), 'is_parent', taf.is_parent, 'parent_uuid',
tafp.unique_acquisition_framework_id) AS af_data
FROM gn_meta.t_acquisition_frameworks taf
LEFT JOIN gn_meta.t_acquisition_frameworks tafp
ON tafp.id_acquisition_framework = taf.acquisition_framework_parent_id
JOIN af_actors ON af_actors.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN ref_nomenclatures.t_nomenclatures ntl
ON taf.id_nomenclature_territorial_level = ntl.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nft
ON taf.id_nomenclature_financing_type = nft.id_nomenclature
LEFT JOIN af_territories ON af_territories.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN af_objectives ON af_objectives.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN af_voletsinp ON af_voletsinp.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN af_publication ON af_publication.id_acquisition_framework = taf.id_acquisition_framework
GROUP BY taf.id_acquisition_framework, taf.acquisition_framework_name, taf.acquisition_framework_desc,
taf.acquisition_framework_start_date, taf.acquisition_framework_end_date, taf.initial_closing_date,
ntl.cd_nomenclature, nft.cd_nomenclature, af_territories.territories, af_objectives.objectives,
af_voletsinp.voletsinp, af_publication.publications, taf.is_parent,
tafp.unique_acquisition_framework_id
), ds_actors AS (
SELECT
cda.id_dataset,
json_build_object('type_role',
CASE
WHEN cda.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cda.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cda.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cda.id_role IS NOT NULL THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_dataset_actor cda
LEFT JOIN utilisateurs.bib_organismes borg ON cda.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cda.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cda.id_nomenclature_actor_role = tn.id_nomenclature
), -- FIN
ds_protocols AS (
SELECT
cdp.id_dataset,
jsonb_build_object(
'uuid', sdp.unique_protocol_id,
'name', sdp.protocol_name,
'desc', sdp.protocol_desc,
'url', sdp.protocol_url,
'type', t_nomenclatures.cd_nomenclature) AS protocols
FROM gn_meta.cor_dataset_protocol cdp
JOIN gn_meta.sinp_datatype_protocols sdp
ON cdp.id_protocol = sdp.id_protocol
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON sdp.id_nomenclature_protocol_type = t_nomenclatures.id_nomenclature
), ds AS (
SELECT
tds.id_dataset,
tds.id_acquisition_framework,
-- tds.additional_data,
jsonb_build_object('uuid', tds.unique_dataset_id, 'name', tds.dataset_name, 'desc', tds.dataset_desc,
'shortname', tds.dataset_shortname, 'data_type', ndt.cd_nomenclature,
'keywords', tds.keywords, 'marine_domain', tds.marine_domain,
'terrestrial_domain', tds.terrestrial_domain, 'collecting_method',
ncm.cd_nomenclature, 'protocols',
ds_protocols.protocols,
'data_origin', ndo.cd_nomenclature,
'dataset_objectif', ndso.cd_nomenclature, 'resource_type', nrt.cd_nomenclature,
'source_status', nss.cd_nomenclature, 'territories', array_agg(DISTINCT
ref_nomenclatures.get_cd_nomenclature(cdt.id_nomenclature_territory)),
'actors', json_agg(ds_actors.json_data)) AS dataset_data
FROM gn_meta.t_datasets tds
JOIN ds_actors ON ds_actors.id_dataset = tds.id_dataset
LEFT JOIN gn_meta.cor_dataset_territory cdt ON cdt.id_dataset = tds.id_dataset
LEFT JOIN ds_protocols ON ds_protocols.id_dataset = tds.id_dataset
LEFT JOIN ref_nomenclatures.t_nomenclatures ndt
ON tds.id_nomenclature_data_type = ndt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ncm
ON tds.id_nomenclature_collecting_method = ncm.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndo
ON tds.id_nomenclature_data_origin = ndo.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndso
ON tds.id_nomenclature_dataset_objectif = ndso.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nrt
ON tds.id_nomenclature_resource_type = nrt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nss
ON tds.id_nomenclature_source_status = nss.id_nomenclature
GROUP BY tds.id_dataset, tds.id_acquisition_framework, tds.unique_dataset_id, tds.dataset_name,
tds.dataset_desc, tds.dataset_shortname, ndt.cd_nomenclature, ncm.cd_nomenclature,
ndo.cd_nomenclature, ndso.cd_nomenclature, nrt.cd_nomenclature, nss.cd_nomenclature,
ds_protocols.protocols
)
SELECT row_number() over (ORDER BY id_synthese) as gid,
s.id_synthese,
s.entity_source_pk_value AS id_source,
s.unique_id_sinp AS id_perm_sinp,
s.unique_id_sinp_grp AS id_perm_grp_sinp,
s.date_min AS date_debut,
s.date_max AS date_fin,
s.cd_nom,
s.meta_v_taxref AS version_taxref,
s.nom_cite,
s.count_min AS nombre_min,
s.count_max AS nombre_max,
s.altitude_min,
s.altitude_max,
s.depth_min AS profondeur_min,
s.depth_max AS profondeur_max,
s.observers AS observateurs,
s.determiner AS determinateur,
s.validator AS validateur,
s.sample_number_proof AS numero_preuve,
s.digital_proof AS preuve_numerique,
s.non_digital_proof AS preuve_non_numerique,
s.comment_context AS comment_releve,
s.comment_description AS comment_occurrence,
ds.dataset_data AS jdd_data,
af.af_data AS ca_data,
s.reference_biblio,
s.cd_hab AS code_habitat,
h.lb_hab_fr AS habitat,
s.place_name AS nom_lieu,
s.precision,
s.additional_data AS donnees_additionnelles,
st_astext(s.the_geom_4326) AS wkt_4326,
n1.cd_nomenclature AS nature_objet_geo,
n2.cd_nomenclature AS type_regroupement,
s.grp_method AS methode_regroupement,
n3.cd_nomenclature AS comportement,
n4.cd_nomenclature AS technique_obs,
n5.cd_nomenclature AS statut_biologique,
n6.cd_nomenclature AS etat_biologique,
n7.cd_nomenclature AS naturalite,
n8.cd_nomenclature AS preuve_existante,
n9.cd_nomenclature AS precision_diffusion,
n10.cd_nomenclature AS stade_vie,
n11.cd_nomenclature AS sexe,
n12.cd_nomenclature AS objet_denombrement,
n13.cd_nomenclature AS type_denombrement,
n14.cd_nomenclature AS niveau_sensibilite,
n15.cd_nomenclature AS statut_observation,
n16.cd_nomenclature AS floutage_dee,
n17.cd_nomenclature AS statut_source,
n18.cd_nomenclature AS type_info_geo,
n19.cd_nomenclature AS methode_determination,
n20.cd_nomenclature AS statut_validation,
coalesce(s.meta_update_date, s.meta_create_date) AS derniere_action--, s.the_geom_local -- supprimé car bloque GN2PG
FROM gn_synthese.synthese s
JOIN taxonomie.taxref USING (cd_nom)
JOIN ds ON ds.id_dataset = s.id_dataset
JOIN af ON ds.id_acquisition_framework = af.id_acquisition_framework
LEFT JOIN ref_habitats.habref h ON h.cd_hab = s.cd_hab
LEFT JOIN ref_nomenclatures.t_nomenclatures n1 ON s.id_nomenclature_geo_object_nature = n1.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n2 ON s.id_nomenclature_grp_typ = n2.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n3 ON s.id_nomenclature_behaviour = n3.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n4 ON s.id_nomenclature_obs_technique = n4.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n5 ON s.id_nomenclature_bio_status = n5.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n6 ON s.id_nomenclature_bio_condition = n6.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n7 ON s.id_nomenclature_naturalness = n7.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n8 ON s.id_nomenclature_exist_proof = n8.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n9 ON s.id_nomenclature_diffusion_level = n9.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
LEFT JOIN ref_nomenclatures.t_nomenclatures n12 ON s.id_nomenclature_obj_count = n12.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n13 ON s.id_nomenclature_type_count = n13.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n14 ON s.id_nomenclature_sensitivity = n14.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n15 ON s.id_nomenclature_observation_status = n15.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n16 ON s.id_nomenclature_blurring = n16.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n17 ON s.id_nomenclature_source_status = n17.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n18 ON s.id_nomenclature_info_geo_type = n18.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n19 ON s.id_nomenclature_determination_method = n19.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n20 ON s.id_nomenclature_valid_status = n20.id_nomenclature
WHERE (af.af_data#>>'{uuid}') = '97c05888-08f5-4a4b-a224-20c3263594ad'
AND (ds.dataset_data#>>'{uuid}') not in (
'7a29acae-757e-41d7-a0cf-a35c568a5db9',
'089a8dc1-3d50-4b2c-865c-d535a982446f' -- JDD : Expertise écologique - Label Golf pour la biodiversité
)
-- FIN
ORDER BY s.id_synthese;
'''
with con_gn.begin() as cnx:
cnx.execute(sql)
@@ -0,0 +1,45 @@
from pycen import con_gn
sql = '''
DROP VIEW IF EXISTS gn_exports.v_synthese_zh_rhomeosite;
CREATE OR REPLACE VIEW gn_exports.v_synthese_zh_rhomeosite
AS WITH t1 AS (
SELECT t_zh.code,
l_areas.area_name,
st_area(st_intersection(t_zh.geom, l_areas.geom_4326)) AS area_intersect
FROM pr_zh.t_zh
JOIN ref_geo.l_areas ON st_intersects(t_zh.geom, l_areas.geom_4326)
JOIN ref_geo.bib_areas_types bib ON l_areas.id_type = bib.id_type and bib.type_name = 'Zones biogéographiques'
), t2 AS (
SELECT t1.code,
t1.area_name,
row_number() OVER (PARTITION BY t1.code ORDER BY t1.area_intersect DESC) AS ismax_ter
FROM t1
)
SELECT
t_zh.id_zh,
t_zh.main_name AS "NAME",
concat(t_roles.nom_role, ' ', t_roles.prenom_role) AS "REFERENT",
bib.nom_organisme AS "ORG",
CASE
WHEN t_zh.id_sage IS NULL
THEN ref_nomenclatures.get_cd_nomenclature(t_zh.id_sdage)::text
ELSE ref_nomenclatures.get_cd_nomenclature(t_zh.id_sage)::text
END AS "TYPE",
CASE
WHEN t2.area_name = 'alpin'::text THEN '1'::text
WHEN t2.area_name = 'continental'::text THEN '2'::text
WHEN t2.area_name = 'mediterraneen'::text THEN '4'::text
ELSE NULL::text
END AS "ODONATE",
ST_TRANSFORM(t_zh.geom,2154)::geometry(geometry,2154) geom
FROM pr_zh.t_zh
LEFT JOIN utilisateurs.t_roles ON t_zh.update_author = t_roles.id_role
LEFT JOIN utilisateurs.bib_organismes bib USING (id_organisme)
JOIN t2 ON t_zh.code::text = t2.code::text AND t2.ismax_ter = 1;
'''
with con_gn.begin() as cnx:
cnx.execute(sql)
@@ -0,0 +1,391 @@
from pycen import con_gn
sql0 = '''
with habitats as (
SELECT
zh_uuid,
json_agg(lb_code) AS habitats
FROM pr_zh.t_zh
LEFT JOIN pr_zh.cor_zh_cb USING (id_zh)
group by 1 order by 1
), crit_delim as (
SELECT
zh_uuid,
json_agg(ref_nomenclatures.get_nomenclature_label(cor_lim_list.id_lim)) AS crit_delim
FROM pr_zh.t_zh
LEFT JOIN pr_zh.cor_lim_list USING (id_lim_list)
group by 1 order by 1
), esp_fs as (
SELECT
zh_uuid,
json_agg(ref_nomenclatures.get_nomenclature_label(cor_zh_lim_fs.id_lim_fs)) AS crit_esp_fs
FROM pr_zh.t_zh
LEFT JOIN pr_zh.cor_zh_lim_fs USING (id_zh)
group by 1 order by 1
), v_activity AS (
SELECT
id_zh,
json_agg(ref_nomenclatures.get_nomenclature_label(cor_impact_types.id_impact)) impacts
FROM pr_zh.t_activity
LEFT JOIN pr_zh.cor_impact_list USING (id_impact_list)
LEFT JOIN pr_zh.cor_impact_types USING (id_cor_impact_types)
group by 1 order by 1
), activ_hum AS (
SELECT
zh_uuid,
json_agg(CASE WHEN t_activity.id_activity IS NULL
THEN NULL
ELSE json_build_object(
'activite', ref_nomenclatures.get_nomenclature_label(t_activity.id_activity),
'position', ref_nomenclatures.get_nomenclature_label(t_activity.id_position),
'impact', v_activity.impacts,
'rmq_activ', t_activity.remark_activity
)
END) AS activ_hum
FROM pr_zh.t_zh
LEFT JOIN pr_zh.t_activity USING (id_zh)
LEFT JOIN v_activity USING (id_zh)
group by zh_uuid order by 1
--), activ_hum_test AS (
-- SELECT
-- zh_uuid,
-- CASE WHEN t_activity.id_activity IS NOT NULL
-- THEN jsonb_build_object(
-- ref_nomenclatures.get_nomenclature_label(t_activity.id_activity), v_activity.impacts
-- )
-- ELSE NULL
-- END AS activ_hum_test
-- FROM pr_zh.t_zh
-- LEFT JOIN pr_zh.t_activity USING (id_zh)
-- LEFT JOIN v_activity USING (id_zh)
-- --group by zh_uuid order by 1
), inflow as (
SELECT
zh_uuid,
json_agg(CASE WHEN t_inflow.id_inflow IS NULL
THEN NULL
ELSE json_build_object(
'entree_eau', ref_nomenclatures.get_nomenclature_label(t_inflow.id_inflow),
'perm', ref_nomenclatures.get_nomenclature_label(t_inflow.id_permanance),
'topo', t_inflow.topo
)
END) AS entree_eau
FROM pr_zh.t_zh
LEFT JOIN pr_zh.t_inflow USING (id_zh)
group by zh_uuid
), outflow as (
SELECT
zh_uuid,
json_agg(CASE WHEN t_outflow.id_outflow IS NULL
THEN NULL
ELSE json_build_object(
'sortie_eau', ref_nomenclatures.get_nomenclature_label(t_outflow.id_outflow),
'perm', ref_nomenclatures.get_nomenclature_label(t_outflow.id_permanance),
'topo', t_outflow.topo
)
END) AS sortie_eau
FROM pr_zh.t_zh
LEFT JOIN pr_zh.t_outflow USING (id_zh)
group by zh_uuid
), functions as (
WITH hydro as (
SELECT
zh_uuid,
json_agg(json_build_object(
'fonctions', ref_nomenclatures.get_nomenclature_label(t_functions.id_function),
'qualification', ref_nomenclatures.get_nomenclature_label(t_functions.id_qualification),
'connaissance', ref_nomenclatures.get_nomenclature_label(t_functions.id_knowledge),
'justification', t_functions.justification
)) AS hydro
FROM pr_zh.t_zh
LEFT JOIN pr_zh.t_functions USING (id_zh)
WHERE id_function IN (
SELECT
id_nomenclature
FROM ref_nomenclatures.t_nomenclatures
JOIN ref_nomenclatures.bib_nomenclatures_types bib USING (id_type)
WHERE bib.mnemonique = 'FONCTIONS_HYDRO')
group by zh_uuid
), bio as (
SELECT
zh_uuid,
json_agg(json_build_object(
'fonctions', ref_nomenclatures.get_nomenclature_label(t_functions.id_function),
'qualification', ref_nomenclatures.get_nomenclature_label(t_functions.id_qualification),
'connaissance', ref_nomenclatures.get_nomenclature_label(t_functions.id_knowledge),
'justification', t_functions.justification
)) AS bio
FROM pr_zh.t_zh
LEFT JOIN pr_zh.t_functions USING (id_zh)
WHERE id_function IN (
SELECT
id_nomenclature
FROM ref_nomenclatures.t_nomenclatures
JOIN ref_nomenclatures.bib_nomenclatures_types bib USING (id_type)
WHERE bib.mnemonique = 'FONCTIONS_BIO')
group by zh_uuid
), int_patrim as (
SELECT
zh_uuid,
json_agg(json_build_object(
'fonctions', ref_nomenclatures.get_nomenclature_label(t_functions.id_function),
'qualification', ref_nomenclatures.get_nomenclature_label(t_functions.id_qualification),
'connaissance', ref_nomenclatures.get_nomenclature_label(t_functions.id_knowledge),
'justification', t_functions.justification
)) AS int_patrim
FROM pr_zh.t_zh
LEFT JOIN pr_zh.t_functions USING (id_zh)
WHERE id_function IN (
SELECT
id_nomenclature
FROM ref_nomenclatures.t_nomenclatures
JOIN ref_nomenclatures.bib_nomenclatures_types bib USING (id_type)
WHERE bib.mnemonique = 'INTERET_PATRIM')
group by zh_uuid
), val_socio as (
SELECT
zh_uuid,
json_agg(json_build_object(
'fonctions', ref_nomenclatures.get_nomenclature_label(t_functions.id_function),
'qualification', ref_nomenclatures.get_nomenclature_label(t_functions.id_qualification),
'connaissance', ref_nomenclatures.get_nomenclature_label(t_functions.id_knowledge),
'justification', t_functions.justification
)) AS val_socio
FROM pr_zh.t_zh
LEFT JOIN pr_zh.t_functions USING (id_zh)
WHERE id_function IN (
SELECT
id_nomenclature
FROM ref_nomenclatures.t_nomenclatures
JOIN ref_nomenclatures.bib_nomenclatures_types bib USING (id_type)
WHERE bib.mnemonique = 'VAL_SOC_ECO')
group by zh_uuid
)
SELECT
zh_uuid,
hydro.hydro,
bio.bio,
int_patrim.int_patrim,
val_socio.val_socio
FROM pr_zh.t_zh
LEFT JOIN hydro USING (zh_uuid)
LEFT JOIN bio USING (zh_uuid)
LEFT JOIN int_patrim USING (zh_uuid)
LEFT JOIN val_socio USING (zh_uuid)
--group by zh_uuid
), especes as (
SELECT
zh_uuid,
(select distinct count(vm_flora.cd_nom) from pr_zh.vm_flora where id_zh = t.id_zh) nb_flora,
(select distinct count(vm_vertebrates.cd_nom) from pr_zh.vm_vertebrates where id_zh = t.id_zh) nb_vertebrates,
(select distinct count(vm_invertebrates.cd_nom) from pr_zh.vm_invertebrates where id_zh = t.id_zh) nb_invertebrates
--count(vm_vertebrates.cd_nom) nb_vertebrates,
--count(vm_invertebrates.cd_nom) nb_invertebrates
FROM pr_zh.t_zh t
--GROUP BY zh_uuid
), rb as (
SELECT
id_zh,
json_agg(name) river_bassin
FROM pr_zh.cor_zh_rb
JOIN pr_zh.t_river_basin USING (id_rb)
GROUP BY id_zh
), instrument as (
SELECT
id_zh,
json_agg(ref_nomenclatures.get_nomenclature_label(t_instruments.id_instrument)) instrument
FROM pr_zh.t_instruments
GROUP BY id_zh
), urba as (
WITH urban_type as (
SELECT
id_doc,
json_agg(json_build_object(
'typ_doc', ref_nomenclatures.get_nomenclature_label(cor_urban_type_range.id_doc_type),
'zone', ref_nomenclatures.get_nomenclature_label(cor_urban_type_range.id_range_type)
)) doc_range
FROM pr_zh.cor_zh_doc_range
JOIN pr_zh.cor_urban_type_range USING (id_cor)
GROUP BY id_doc
)
SELECT
id_zh,
json_agg(json_build_object(
'typ_doc', ref_nomenclatures.get_nomenclature_label(t_urban_planning_docs.id_doc_type),
'doc_range', doc_range,
'zone', l_areas.area_name,
'remarque', t_urban_planning_docs.remark
)) docs_urba
FROM pr_zh.t_urban_planning_docs
JOIN ref_geo.l_areas USING (id_area)
JOIN urban_type USING (id_doc)
GROUP BY id_zh
), actions AS (
SELECT
id_zh,
json_agg(json_build_object(
'priorite', ref_nomenclatures.get_nomenclature_label(t_actions.id_priority_level),
'action', bib_actions.name,
'remarque', t_actions.remark
) ORDER BY id_priority_level,bib_actions.name) prio_actions
FROM pr_zh.t_actions
JOIN pr_zh.bib_actions USING (id_action)
GROUp BY id_zh
), zh_area_com AS (
SELECT
id_zh,
json_agg(l_areas.area_name||' ('||cover||'%%)' ORDER BY l_areas.area_name) commune
FROM pr_zh.cor_zh_area
JOIN ref_geo.l_areas USING (id_area)
WHERE cover IS NOT NULL
GROUP BY id_zh
), dep AS (
SELECT
id_zh,
json_agg(l_areas.area_name ORDER BY l_areas.area_name) departement
FROM pr_zh.cor_zh_area
JOIN ref_geo.l_areas USING (id_area)
join ref_geo.bib_areas_types bat using (id_type)
WHERE cover IS null and bat.type_code = 'DEP'
GROUP BY id_zh
), inventaire AS (
SELECT
id_zh,
json_agg(json_build_object(
'inventaire',l_areas.area_code ||' - '||l_areas.area_name,
'url', l_areas."source"
) ORDER BY l_areas.area_name) inventaire
FROM pr_zh.cor_zh_area
JOIN ref_geo.l_areas USING (id_area)
join ref_geo.bib_areas_types bat using (id_type)
WHERE cover IS null and bat.type_code not in ('DEP')
GROUP BY id_zh
)
SELECT
zh_uuid,
code,
main_name,
--concat(crea_role.nom_role, ' ', crea_role.prenom_role) AS crea_author,
--bib_org.name AS organisme,
--concat(updt_role.nom_role, ' ', updt_role.prenom_role) AS updt_author,
bib_org_user_updt.nom_organisme as org_updt,
create_date crea_date,
update_date updt_date,
--ST_TRANSFORM(geom,2154)::geometry(geometry,2154) geom,
geom,
area surface,
rb.river_bassin,
dep.departement,
zh_area_com.commune,
ref_nomenclatures.get_nomenclature_label(id_sdage) sdage,
ref_nomenclatures.get_nomenclature_label(id_sage) sage,
CASE WHEN habitats.habitats::text = '[null]'
THEN NULL
ELSE habitats.habitats
END AS habitats,
remark_pres descript,
crit_delim.crit_delim,
remark_lim rmq_delilm,
CASE WHEN esp_fs.crit_esp_fs::text = '[null]'
THEN NULL
ELSE esp_fs.crit_esp_fs
END AS crit_esp_fs,
remark_lim_fs rmq_esp_fs,
--ef_area,
--v_habref v_hab,
CASE WHEN activ_hum.activ_hum::text = '[null]'
THEN NULL
ELSE activ_hum.activ_hum::text
END AS activ_hum,
-- activ_hum_test.activ_hum_test,
ref_nomenclatures.get_nomenclature_label(id_thread) bilan_menace,
CASE WHEN inflow.entree_eau::text = '[null]'
THEN NULL
ELSE inflow.entree_eau::text
END AS entree_eau,
CASE WHEN outflow.sortie_eau::text = '[null]'
THEN NULL
ELSE outflow.sortie_eau::text
END AS sortie_eau,
ref_nomenclatures.get_nomenclature_label(id_frequency) freq_sub,
ref_nomenclatures.get_nomenclature_label(id_spread) extend_sub,
ref_nomenclatures.get_nomenclature_label(id_connexion) connex,
ref_nomenclatures.get_nomenclature_label(id_diag_hydro) diag_hydro,
ref_nomenclatures.get_nomenclature_label(id_diag_bio) diag_bio,
functions.hydro::text,
functions.bio::text,
functions.int_patrim::text,
functions.val_socio::text,
remark_eval_functions eval_fcts,
remark_eval_heritage eval_heritage,
remark_eval_thread eval_menace,
remark_eval_actions eval_actions,
ref_nomenclatures.get_nomenclature_label(id_strat_gestion) strat_gestion,
remark_diag rmq_gestion,
--is_other_inventory,
--is_carto_hab,
--nb_hab,
--total_hab_cover,
especes.nb_flora nb_flora_sp,
especes.nb_vertebrates nb_vertebrate_sp,
especes.nb_invertebrates nb_invertebrate_sp,
inventaire.inventaire::text,
actions.prio_actions::text,
instrument.instrument::text,
urba.docs_urba::text
--remark_is_other_inventory
FROM pr_zh.t_zh
JOIN utilisateurs.t_roles crea_role ON t_zh.create_author = crea_role.id_role
LEFT JOIN utilisateurs.t_roles updt_role ON t_zh.update_author = updt_role.id_role
LEFT JOIN utilisateurs.bib_organismes bib_org_user_updt on updt_role.id_organisme = bib_org_user_updt.id_organisme
LEFT JOIN pr_zh.bib_organismes bib_org USING (id_org)
LEFT JOIN habitats USING (zh_uuid)
LEFT JOIN crit_delim USING (zh_uuid)
LEFT JOIN esp_fs USING (zh_uuid)
LEFT JOIN activ_hum USING (zh_uuid)
--LEFT JOIN activ_hum_test USING (zh_uuid)
LEFT JOIN inflow USING (zh_uuid)
LEFT JOIN outflow USING (zh_uuid)
LEFT JOIN functions USING (zh_uuid)
LEFT JOIN especes USING (zh_uuid)
LEFT JOIN rb USING (id_zh)
LEFT JOIN instrument USING (id_zh)
LEFT JOIN urba USING (id_zh)
LEFT JOIN actions USING (id_zh)
LEFT JOIN zh_area_com USING (id_zh)
LEFT JOIN dep USING (id_zh)
LEFT JOIN inventaire USING (id_zh)
'''
sql_zh_all = '''
DROP VIEW IF EXISTS gn_exports.v_synthese_zones_humides;
CREATE VIEW gn_exports.v_synthese_zones_humides AS
''' + sql0 + '''
--group BY zh_uuid
WHERE code not like '38CENIS%%'
AND ref_nomenclatures.get_cd_nomenclature(id_sdage)::int > 0
--id_sdage > 0
order by code
;
'''
with con_gn.begin() as cnx:
cnx.execute(sql_zh_all)
sql_zh_38 = '''
DROP VIEW IF EXISTS gn_exports.v_synthese_zones_humides_isere;
CREATE VIEW gn_exports.v_synthese_zones_humides_isere AS
''' + sql0 + '''
--group BY zh_uuid
WHERE code not like '38CENIS%%'
AND dep.departement::jsonb @> '"Isère"'
AND ref_nomenclatures.get_cd_nomenclature(id_sdage)::int > 0
order by code
;
'''
with con_gn.begin() as cnx:
cnx.execute(sql_zh_38)
@@ -0,0 +1,276 @@
from pycen import con_gn
sql = '''
DROP VIEW IF EXISTS gn_exports.v_synthese_sinp_with_metadata_vertebre_for_gn2pg;
CREATE VIEW gn_exports.v_synthese_sinp_with_metadata_vertebre_for_gn2pg AS
WITH af_actors AS (
SELECT cafa.id_acquisition_framework,
json_build_object('type_role',
CASE
WHEN cafa.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cafa.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cafa.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cafa.id_role IS NOT NULL
THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_acquisition_framework_actor cafa
LEFT JOIN utilisateurs.bib_organismes borg ON cafa.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cafa.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cafa.id_nomenclature_actor_role = tn.id_nomenclature),
af_territories AS (SELECT caft.id_acquisition_framework,
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS territories
FROM gn_meta.cor_acquisition_framework_territory caft
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON caft.id_nomenclature_territory =
t_nomenclatures.id_nomenclature
GROUP BY caft.id_acquisition_framework),
af_objectives AS (SELECT cafo.id_acquisition_framework,
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS objectives
FROM gn_meta.cor_acquisition_framework_objectif cafo
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON cafo.id_nomenclature_objectif =
t_nomenclatures.id_nomenclature
GROUP BY cafo.id_acquisition_framework),
af_voletsinp AS (SELECT cafv.id_acquisition_framework,
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS voletsinp
FROM gn_meta.cor_acquisition_framework_voletsinp cafv
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON cafv.id_nomenclature_voletsinp =
t_nomenclatures.id_nomenclature
GROUP BY cafv.id_acquisition_framework),
af_publication AS (SELECT cafp.id_acquisition_framework,
array_agg(DISTINCT
jsonb_build_object('uuid', sinp_datatype_publications.unique_publication_id,
'reference',
sinp_datatype_publications.publication_reference,
'url',
sinp_datatype_publications.publication_url)) AS publications
FROM gn_meta.cor_acquisition_framework_publication cafp
LEFT JOIN gn_meta.sinp_datatype_publications
ON cafp.id_publication = sinp_datatype_publications.id_publication
GROUP BY cafp.id_acquisition_framework)
,
af AS (SELECT taf.id_acquisition_framework,
jsonb_build_object('uuid', taf.unique_acquisition_framework_id, 'name',
taf.acquisition_framework_name,
'desc', taf.acquisition_framework_desc, 'start_date',
taf.acquisition_framework_start_date, 'end_date',
taf.acquisition_framework_end_date,
'initial_closing_date', taf.initial_closing_date, 'territories',
af_territories.territories, 'territorial_level',
ntl.cd_nomenclature, 'territory_desc', taf.territory_desc, 'objectives',
af_objectives.objectives, 'publications', af_publication.publications,
'financing_type', nft.cd_nomenclature,
'target_description',
taf.target_description, 'ecologic_or_geologic_target',
taf.ecologic_or_geologic_target, 'actors',
json_agg(af_actors.json_data), 'is_parent', taf.is_parent, 'parent_uuid',
tafp.unique_acquisition_framework_id) AS af_data
FROM gn_meta.t_acquisition_frameworks taf
LEFT JOIN gn_meta.t_acquisition_frameworks tafp
ON tafp.id_acquisition_framework = taf.acquisition_framework_parent_id
JOIN af_actors ON af_actors.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN ref_nomenclatures.t_nomenclatures ntl
ON taf.id_nomenclature_territorial_level = ntl.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nft
ON taf.id_nomenclature_financing_type = nft.id_nomenclature
LEFT JOIN af_territories ON af_territories.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN af_objectives ON af_objectives.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN af_voletsinp ON af_voletsinp.id_acquisition_framework = taf.id_acquisition_framework
LEFT JOIN af_publication ON af_publication.id_acquisition_framework = taf.id_acquisition_framework
GROUP BY taf.id_acquisition_framework, taf.acquisition_framework_name, taf.acquisition_framework_desc,
taf.acquisition_framework_start_date, taf.acquisition_framework_end_date, taf.initial_closing_date,
ntl.cd_nomenclature, nft.cd_nomenclature, af_territories.territories, af_objectives.objectives,
af_voletsinp.voletsinp, af_publication.publications, taf.is_parent,
tafp.unique_acquisition_framework_id),
ds_actors AS (SELECT cda.id_dataset,
json_build_object('type_role',
CASE
WHEN cda.id_organism IS NOT NULL THEN 'organism'::TEXT
WHEN cda.id_role IS NOT NULL THEN 'role'::TEXT
ELSE NULL::TEXT
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
CASE
WHEN cda.id_organism IS NOT NULL
THEN json_build_object('organism_name', borg.nom_organisme)
WHEN cda.id_role IS NOT NULL THEN json_build_object('first_name',
tro.nom_role,
'last_name',
tro.prenom_role) END,
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
FROM gn_meta.cor_dataset_actor cda
LEFT JOIN utilisateurs.bib_organismes borg ON cda.id_organism = borg.id_organisme
LEFT JOIN utilisateurs.t_roles tro ON cda.id_role = tro.id_role
JOIN ref_nomenclatures.t_nomenclatures tn
ON cda.id_nomenclature_actor_role = tn.id_nomenclature),
ds_protocols AS (SELECT cdp.id_dataset,
jsonb_build_object(
'uuid', sdp.unique_protocol_id,
'name', sdp.protocol_name,
'desc', sdp.protocol_desc,
'url', sdp.protocol_url,
'type', t_nomenclatures.cd_nomenclature) AS protocols
FROM gn_meta.cor_dataset_protocol cdp
JOIN gn_meta.sinp_datatype_protocols sdp
ON cdp.id_protocol = sdp.id_protocol
LEFT JOIN ref_nomenclatures.t_nomenclatures
ON sdp.id_nomenclature_protocol_type = t_nomenclatures.id_nomenclature)
,
ds AS (SELECT tds.id_dataset,
tds.id_acquisition_framework,
-- tds.additional_data,
jsonb_build_object('uuid', tds.unique_dataset_id, 'name', tds.dataset_name, 'desc', tds.dataset_desc,
'shortname', tds.dataset_shortname, 'data_type', ndt.cd_nomenclature,
'keywords', tds.keywords, 'marine_domain', tds.marine_domain,
'terrestrial_domain', tds.terrestrial_domain, 'collecting_method',
ncm.cd_nomenclature, 'protocols',
ds_protocols.protocols,
'data_origin', ndo.cd_nomenclature,
'dataset_objectif', ndso.cd_nomenclature, 'resource_type', nrt.cd_nomenclature,
'source_status', nss.cd_nomenclature, 'territories', array_agg(DISTINCT
ref_nomenclatures.get_cd_nomenclature(cdt.id_nomenclature_territory)),
'actors', json_agg(ds_actors.json_data)) AS dataset_data
FROM gn_meta.t_datasets tds
JOIN ds_actors ON ds_actors.id_dataset = tds.id_dataset
LEFT JOIN gn_meta.cor_dataset_territory cdt ON cdt.id_dataset = tds.id_dataset
LEFT JOIN ds_protocols ON ds_protocols.id_dataset = tds.id_dataset
LEFT JOIN ref_nomenclatures.t_nomenclatures ndt
ON tds.id_nomenclature_data_type = ndt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ncm
ON tds.id_nomenclature_collecting_method = ncm.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndo
ON tds.id_nomenclature_data_origin = ndo.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures ndso
ON tds.id_nomenclature_dataset_objectif = ndso.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nrt
ON tds.id_nomenclature_resource_type = nrt.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures nss
ON tds.id_nomenclature_source_status = nss.id_nomenclature
GROUP BY tds.id_dataset, tds.id_acquisition_framework, tds.unique_dataset_id, tds.dataset_name,
tds.dataset_desc, tds.dataset_shortname, ndt.cd_nomenclature, ncm.cd_nomenclature,
ndo.cd_nomenclature, ndso.cd_nomenclature, nrt.cd_nomenclature, nss.cd_nomenclature,
ds_protocols.protocols)
SELECT s.id_synthese,
s.entity_source_pk_value AS id_source,
s.unique_id_sinp AS id_perm_sinp,
s.unique_id_sinp_grp AS id_perm_grp_sinp,
s.date_min AS date_debut,
s.date_max AS date_fin,
s.cd_nom,
s.meta_v_taxref AS version_taxref,
s.nom_cite,
s.count_min AS nombre_min,
s.count_max AS nombre_max,
s.altitude_min,
s.altitude_max,
s.depth_min AS profondeur_min,
s.depth_max AS profondeur_max,
s.observers AS observateurs,
s.determiner AS determinateur,
s.validator AS validateur,
s.sample_number_proof AS numero_preuve,
s.digital_proof AS preuve_numerique,
s.non_digital_proof AS preuve_non_numerique,
s.comment_context AS comment_releve,
s.comment_description AS comment_occurrence,
ds.dataset_data AS jdd_data,
af.af_data AS ca_data,
s.reference_biblio,
s.cd_hab AS code_habitat,
h.lb_hab_fr AS habitat,
s.place_name AS nom_lieu,
s.precision,
s.additional_data AS donnees_additionnelles,
st_astext(s.the_geom_4326) AS wkt_4326,
n1.cd_nomenclature AS nature_objet_geo,
n2.cd_nomenclature AS type_regroupement,
s.grp_method AS methode_regroupement,
n3.cd_nomenclature AS comportement,
n4.cd_nomenclature AS technique_obs,
n5.cd_nomenclature AS statut_biologique,
n6.cd_nomenclature AS etat_biologique,
n7.cd_nomenclature AS naturalite,
n8.cd_nomenclature AS preuve_existante,
n9.cd_nomenclature AS precision_diffusion,
n10.cd_nomenclature AS stade_vie,
n11.cd_nomenclature AS sexe,
n12.cd_nomenclature AS objet_denombrement,
n13.cd_nomenclature AS type_denombrement,
n14.cd_nomenclature AS niveau_sensibilite,
n15.cd_nomenclature AS statut_observation,
n16.cd_nomenclature AS floutage_dee,
n17.cd_nomenclature AS statut_source,
n18.cd_nomenclature AS type_info_geo,
n19.cd_nomenclature AS methode_determination,
n20.cd_nomenclature AS statut_validation,
coalesce(s.meta_update_date, s.meta_create_date) AS derniere_action
FROM gn_synthese.synthese s
JOIN ds ON ds.id_dataset = s.id_dataset
JOIN af ON ds.id_acquisition_framework = af.id_acquisition_framework
LEFT JOIN ref_habitats.habref h ON h.cd_hab = s.cd_hab
LEFT JOIN ref_nomenclatures.t_nomenclatures n1 ON s.id_nomenclature_geo_object_nature = n1.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n2 ON s.id_nomenclature_grp_typ = n2.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n3 ON s.id_nomenclature_behaviour = n3.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n4 ON s.id_nomenclature_obs_technique = n4.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n5 ON s.id_nomenclature_bio_status = n5.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n6 ON s.id_nomenclature_bio_condition = n6.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n7 ON s.id_nomenclature_naturalness = n7.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n8 ON s.id_nomenclature_exist_proof = n8.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n9 ON s.id_nomenclature_diffusion_level = n9.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
LEFT JOIN ref_nomenclatures.t_nomenclatures n12 ON s.id_nomenclature_obj_count = n12.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n13 ON s.id_nomenclature_type_count = n13.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n14 ON s.id_nomenclature_sensitivity = n14.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n15 ON s.id_nomenclature_observation_status = n15.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n16 ON s.id_nomenclature_blurring = n16.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n17 ON s.id_nomenclature_source_status = n17.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n18 ON s.id_nomenclature_info_geo_type = n18.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n19 ON s.id_nomenclature_determination_method = n19.id_nomenclature
LEFT JOIN ref_nomenclatures.t_nomenclatures n20 ON s.id_nomenclature_valid_status = n20.id_nomenclature
-- ADD CEN_38
JOIN taxonomie.taxref t ON t.cd_nom = s.cd_nom
JOIN gn_synthese.t_sources ts ON ts.id_source = s.id_source
WHERE t.regne = 'Animalia'
AND t.phylum = 'Chordata'
-- exclision CA ([SICEN] Echange données partenaires,[TEST] : migration sicen,)
AND ds.id_acquisition_framework NOT IN (
53,1,2,6, -- CA tests
84, -- Echange de données PG Chravas
85, -- Echange de données
116 -- Echange de données issus de SICEN
)
-- exclision JDD `Observations opportunistes du CEN Isère importé depuis Faune Isère`
AND ds.id_dataset NOT IN (185,377,236,409)
-- exclision CA (`Gestion de l'Espace Naturel Sensible du Méandre des Oves`, `Gestion de la Réserve Naturelle Nationale de l'Ile de la Platière`, `Gestion des Natura 2000 FR 8201749 « Milieux alluviaux et aquatiques de l’Île de la Platière » et FR 8212012 « Île de la Platière »`, `RNN Platière`
--AND (ts.id_module = 7 AND ds.id_acquisition_framework IN (7,38,39,42,44,45,46,48,55,57,58,60)
AND (
unaccent(observers) LIKE ANY (array['%%Conservatoire d%%Espaces Naturels Isere%%', '%%Conservatoire d%%Espaces Naturels d%%Isere%%', '%%CEN Isere%%', '%%Association des Amis de l%%Ile de la Platiere%%'])
OR observers NOT LIKE '%%(%%)%%'
)
AND unaccent(observers) NOT LIKE ALL(array[
'%%Sympetrum%%','%%Departement%%','%%Rhone%%','%%Oxalis%%',
'%%LPO%%','%%GRPLS%%','%%Parvi%%','%%CD Isere%%','%%Personnel%%','%%Independant%%'
'%%DELOCHE Denis%%'
])
AND observers NOT IN ('', 'Benoit Dodelin',', ')
-- statut_validation = 'Certain - très probable'
-- AND n20.cd_nomenclature = '1'
ORDER BY s.id_synthese;
'''
with con_gn.begin() as cnx:
cnx.execute(sql)