diff --git a/5_GEONATURE/EXPORT/flore_export_sinp_with_metadata.py b/5_GEONATURE/EXPORT/flore_export_sinp_with_metadata.py index e7cd8de..f1e3c12 100644 --- a/5_GEONATURE/EXPORT/flore_export_sinp_with_metadata.py +++ b/5_GEONATURE/EXPORT/flore_export_sinp_with_metadata.py @@ -1,7 +1,7 @@ from pycen import con_gn sql = ''' -DROP VIEW IF EXISTS gn_exports.v_synthese_sinp_with_metadata_flora_for_gn2pg; +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 ( @@ -10,27 +10,31 @@ CREATE VIEW gn_exports.v_synthese_sinp_with_metadata_flora_for_gn2pg AS 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 + 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, + 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, - geo_1.area_code AS commune, + 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.synthese s_1 ON st_intersects(s_1.the_geom_4326, st_transform(geo_1.geom, 4326)) + 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, @@ -169,13 +173,13 @@ CREATE VIEW gn_exports.v_synthese_sinp_with_metadata_flora_for_gn2pg AS 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 + --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,65,66,1,2,6) + 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`