Skip to content

Commit

Permalink
Suppression appel fonction fct_get_altitude_intersection et récupérat…
Browse files Browse the repository at this point in the history
…ion de l'altitude du site
  • Loading branch information
amandine-sahl committed Dec 30, 2024
1 parent ca836cd commit a712c57
Show file tree
Hide file tree
Showing 36 changed files with 148 additions and 195 deletions.
16 changes: 7 additions & 9 deletions POPAmphibien/exports/csv/export_csv.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ SELECT
s.base_site_name AS nom_site,
st_x(s.geom_local) AS x_lambert93,
st_y(s.geom_local) AS y_lambert93,
alt.altitude_min AS altitude_min,
alt.altitude_max AS altitude_max,
s.altitude_min AS altitude_min,
s.altitude_max AS altitude_max,
ref_nomenclatures.get_nomenclature_label(nullif(json_extract_path(sc.data::json,'milieu_aquatique')::text,'null')::integer, 'fr') AS milieu_aquatique,
ref_nomenclatures.get_nomenclature_label(nullif(json_extract_path(sc.data::json,'variation_eau')::text,'null')::integer, 'fr') AS variation_eau,
ref_nomenclatures.get_nomenclature_label(nullif(json_extract_path(sc.data::json,'courant')::text,'null')::integer, 'fr') AS courant,
Expand Down Expand Up @@ -85,11 +85,10 @@ LEFT JOIN LATERAL ( SELECT array_agg(r.id_role) AS ids_observers,
JOIN utilisateurs.t_roles r ON r.id_role = cvo.id_role
LEFT JOIN utilisateurs.bib_organismes org ON org.id_organisme =r.id_organisme
WHERE cvo.id_base_visit = v.id_base_visit) obs ON true
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt(altitude_min, altitude_max) ON true
LEFT JOIN LATERAL (SELECT ref_nomenclatures.get_nomenclature_label(json_array_elements(vc.data::json #> '{methode_de_prospection}')::text::integer,'fr') AS methodes ) meth ON TRUE
WHERE m.module_code = 'popamphibien'
GROUP BY o.uuid_observation, obs.organismes_rattaches, dep.area_name, dep.area_code, tsg.sites_group_name, o.cd_nom, t.lb_nom, t.nom_vern, o.comments, oc.data, v.visit_date_min, v.id_dataset, d.dataset_name, v.comments, v.uuid_base_visit,
s.base_site_name, sc.data, vc.data, alt.altitude_min, alt.altitude_max, obs.observers, com.area_name, s.geom_local;
s.base_site_name, sc.data, vc.data, s.altitude_min, s.altitude_max, obs.observers, com.area_name, s.geom_local;


---------------------------------------------------POPAmphibien analyses------------------------------------------
Expand All @@ -116,8 +115,8 @@ SELECT
s.base_site_name AS nom_site,
st_x(s.geom_local) AS x_lambert93,
st_y(s.geom_local) AS y_lambert93,
alt.altitude_min AS altitude_min,
alt.altitude_max AS altitude_max,
s.altitude_min AS altitude_min,
s.altitude_max AS altitude_max,
ref_nomenclatures.get_nomenclature_label(nullif(json_extract_path(sc.data::json,'milieu_aquatique')::text,'null')::integer, 'fr') AS milieu_aquatique,
ref_nomenclatures.get_nomenclature_label(nullif(json_extract_path(sc.data::json,'variation_eau')::text,'null')::integer, 'fr') AS variation_eau,
ref_nomenclatures.get_nomenclature_label(nullif(json_extract_path(sc.data::json,'courant')::text,'null')::integer, 'fr') AS courant,
Expand Down Expand Up @@ -182,9 +181,8 @@ LEFT JOIN LATERAL ( SELECT array_agg(r.id_role) AS ids_observers,
FROM gn_monitoring.cor_visit_observer cvo
JOIN utilisateurs.t_roles r ON r.id_role = cvo.id_role
LEFT JOIN utilisateurs.bib_organismes org ON org.id_organisme =r.id_organisme
WHERE cvo.id_base_visit = v.id_base_visit) obs ON true
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt(altitude_min, altitude_max) ON true
WHERE cvo.id_base_visit = v.id_base_visit) obs ON true
LEFT JOIN lateral (SELECT ref_nomenclatures.get_nomenclature_label(json_array_elements(vc.data::json #> '{methode_de_prospection}')::text::integer,'fr') as methodes ) meth on true
WHERE m.module_code = 'popamphibien'
GROUP BY v.id_base_visit, v.id_dataset, d.dataset_name, tsg.sites_group_name, s.base_site_name, s.geom_local, alt.altitude_min, alt.altitude_max, sc.data, dep.area_name, dep.area_code, com.area_name, sp.area_name,
GROUP BY v.id_base_visit, v.id_dataset, d.dataset_name, tsg.sites_group_name, s.base_site_name, s.geom_local, s.altitude_min, s.altitude_max, sc.data, dep.area_name, dep.area_code, com.area_name, sp.area_name,
vc.data, obs.observers, obs.organismes_rattaches, observations.diversite, observations.taxons_latin, observations.taxons_fr, observations.count_min, observations.count_max ;
5 changes: 2 additions & 3 deletions POPAmphibien/synthese.sql
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ AS WITH source AS (
o.id_observation,
o.cd_nom,
t.nom_complet AS nom_cite,
alt.altitude_min,
alt.altitude_max,
s.altitude_min,
s.altitude_max,
s.geom AS the_geom_4326,
st_centroid(s.geom) AS the_geom_point,
s.geom_local AS the_geom_local,
Expand Down Expand Up @@ -95,5 +95,4 @@ AS WITH source AS (
FROM gn_monitoring.cor_visit_observer cvo
JOIN utilisateurs.t_roles r ON r.id_role = cvo.id_role
WHERE cvo.id_base_visit = v.id_base_visit) obs ON true
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt(altitude_min, altitude_max) ON true
WHERE m.module_code = :module_code;
14 changes: 6 additions & 8 deletions POPReptile/exports/csv/export_csv.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ SELECT
st_astext(s.geom) AS wkt,
st_x(st_centroid(s.geom_local)) AS x_centroid_L93,
st_y(st_centroid(s.geom_local)) AS y_centroid_L93,
alt.altitude_min AS altitude_min,
alt.altitude_max AS altitude_max,
s.altitude_min AS altitude_min,
s.altitude_max AS altitude_max,
dep.area_name AS departement,
dep.area_code AS code_dep,
com.area_name AS commune,
Expand Down Expand Up @@ -96,8 +96,7 @@ LEFT JOIN LATERAL ( SELECT array_agg(r.id_role) AS ids_observers,
FROM gn_monitoring.cor_visit_observer cvo
JOIN utilisateurs.t_roles r ON r.id_role = cvo.id_role
LEFT JOIN utilisateurs.bib_organismes org ON org.id_organisme =r.id_organisme
WHERE cvo.id_base_visit = v.id_base_visit) obs ON true
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt(altitude_min, altitude_max) ON true
WHERE cvo.id_base_visit = v.id_base_visit) obs ON true
LEFT JOIN LATERAL (SELECT ref_nomenclatures.get_nomenclature_label(json_array_elements(vc.data::json #> '{methode_de_prospection}')::text::integer,'fr') AS methodes ) meth ON TRUE
WHERE m.module_code = 'popreptile'
GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52
Expand Down Expand Up @@ -142,8 +141,8 @@ SELECT
st_astext(s.geom) AS wkt,
st_x(st_centroid(s.geom_local)) AS x_centroid_L93,
st_y(st_centroid(s.geom_local)) AS y_centroid_L93,
alt.altitude_min AS altitude_min,
alt.altitude_max AS altitude_max,
s.altitude_min AS altitude_min,
s.altitude_max AS altitude_max,
dep.area_name AS departement,
dep.area_code AS code_dep,
com.area_name AS commune,
Expand Down Expand Up @@ -210,8 +209,7 @@ LEFT JOIN LATERAL ( SELECT array_agg(r.id_role) AS ids_observers,
FROM gn_monitoring.cor_visit_observer cvo
JOIN utilisateurs.t_roles r ON r.id_role = cvo.id_role
LEFT JOIN utilisateurs.bib_organismes org ON org.id_organisme =r.id_organisme
WHERE cvo.id_base_visit = v.id_base_visit) obs ON true
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt(altitude_min, altitude_max) ON true
WHERE cvo.id_base_visit = v.id_base_visit) obs ON true
LEFT JOIN lateral (SELECT ref_nomenclatures.get_nomenclature_label(json_array_elements(vc.data::json #> '{methode_de_prospection}')::text::integer,'fr') as methodes ) meth on true
WHERE m.module_code = 'popreptile'
GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45
Expand Down
7 changes: 3 additions & 4 deletions POPReptile/synthese.sql
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ AS WITH source AS (
END AS count_max,
o.cd_nom,
t.nom_complet AS nom_cite,
alt.altitude_min,
alt.altitude_max,
s.altitude_min,
s.altitude_max,
s.geom AS the_geom_4326,
st_centroid(s.geom) AS the_geom_point,
s.geom_local AS the_geom_local,
Expand Down Expand Up @@ -116,7 +116,6 @@ AS WITH source AS (
string_agg(concat(r.nom_role, ' ', r.prenom_role), ' ; '::text) AS observers
FROM gn_monitoring.cor_visit_observer cvo
JOIN utilisateurs.t_roles r ON r.id_role = cvo.id_role
WHERE cvo.id_base_visit = v.id_base_visit) obs ON true
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt(altitude_min, altitude_max) ON true
WHERE cvo.id_base_visit = v.id_base_visit) obs ON true
WHERE m.module_code = :module_code;

6 changes: 0 additions & 6 deletions RHOMEOAmphibien/exports/csv/export_csv.sql
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,6 @@ SELECT
JOIN source
ON TRUE
JOIN observers obs ON obs.id_base_visit = v.id_base_visit

LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt (altitude_min, altitude_max)
ON TRUE
WHERE m.module_code = 'RHOMEOAmphibien'
;

Expand Down Expand Up @@ -380,8 +377,5 @@ SELECT
JOIN source
ON TRUE
--JOIN observers obs ON obs.id_base_visit = v.id_base_visit

-- LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt (altitude_min, altitude_max)
-- ON TRUE
WHERE m.module_code = 'RHOMEOAmphibien'
;
12 changes: 6 additions & 6 deletions RHOMEOAmphibien/synthese.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ WITH source AS (
(sc.data::json#>>'{esp_veget}')::text AS esp_veget,
(sc.data::json#>>'{esp_poisson}')::text AS esp_poisson,
(sc.data::json#>>'{esp_ecrevisse}')::text AS esp_ecrevisse,
base_site_description
base_site_description,
s.altitude_min,
s.altitude_max
FROM gn_monitoring.t_base_sites s
JOIN gn_monitoring.t_site_complements sc USING (id_base_site)
LEFT JOIN gn_monitoring.t_sites_groups sg USING (id_sites_group)
Expand Down Expand Up @@ -144,8 +146,8 @@ SELECT
--meta_v_taxref
--sample_number_proof
--digital_proofvue
alt.altitude_min,
alt.altitude_max,
s.altitude_min,
s.altitude_max,
s.the_geom_4326,
s.the_geom_point,
s.the_geom_local,
Expand Down Expand Up @@ -205,8 +207,6 @@ SELECT
JOIN source
ON TRUE
JOIN observers obs
ON obs.id_base_visit = v.id_base_visit
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.the_geom_local) alt (altitude_min, altitude_max)
ON TRUE
ON obs.id_base_visit = v.id_base_visit
WHERE m.module_code = :module_code
;
5 changes: 1 addition & 4 deletions RHOMEOFlore/exports/csv/export_csv.sql
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,7 @@ SELECT
ON t.cd_nom = o.cd_nom
JOIN source
ON TRUE
JOIN observers obs ON obs.id_base_visit = v.id_base_visit

LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt (altitude_min, altitude_max)
ON TRUE
JOIN observers obs ON obs.id_base_visit = v.id_base_visit
WHERE m.module_code = 'RHOMEOFlore'
;

Expand Down
13 changes: 6 additions & 7 deletions RHOMEOFlore/synthese.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ WITH source AS (
base_site_name,
(sc.data::json#>>'{expo}')::text AS expo_terrain,
(sc.data::json#>>'{desc_pente}')::text AS profil_pente,
base_site_description
base_site_description,
s.altitude_min,
s.altitude_max
FROM gn_monitoring.t_base_sites s
JOIN gn_monitoring.t_site_complements sc USING (id_base_site)
LEFT JOIN gn_monitoring.t_sites_groups sg USING (id_sites_group)
Expand Down Expand Up @@ -155,8 +157,8 @@ SELECT
--meta_v_taxref
--sample_number_proof
--digital_proofvue
alt.altitude_min,
alt.altitude_max,
s.altitude_min,
s.altitude_max,
s.the_geom_4326,
s.the_geom_point,
s.the_geom_local,
Expand Down Expand Up @@ -193,9 +195,6 @@ SELECT
ON t.cd_nom = o.cd_nom
JOIN source
ON TRUE
JOIN observers obs ON obs.id_base_visit = v.id_base_visit

LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.the_geom_local) alt (altitude_min, altitude_max)
ON TRUE
JOIN observers obs ON obs.id_base_visit = v.id_base_visit
WHERE m.module_code = :module_code
;
5 changes: 1 addition & 4 deletions RHOMEOOdonate/exports/csv/export_csv.sql
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,7 @@ SELECT
ON t.cd_nom = o.cd_nom
JOIN source
ON TRUE
JOIN observers obs ON obs.id_base_visit = v.id_base_visit

LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt (altitude_min, altitude_max)
ON TRUE
JOIN observers obs ON obs.id_base_visit = v.id_base_visit
WHERE m.module_code = 'RHOMEOOdonate'
;

Expand Down
12 changes: 6 additions & 6 deletions RHOMEOOdonate/synthese.sql
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ WITH source AS (
id_base_site,
geom AS the_geom_4326,
ST_CENTROID(geom) AS the_geom_point,
geom_local as the_geom_local
geom_local as the_geom_local,
altitude_min,
altitude_max

FROM gn_monitoring.t_base_sites

Expand Down Expand Up @@ -155,8 +157,8 @@ SELECT
--meta_v_taxref
--sample_number_proof
--digital_proofvue
alt.altitude_min,
alt.altitude_max,
s.altitude_min,
s.altitude_max,
s.the_geom_4326,
s.the_geom_point,
s.the_geom_local,
Expand Down Expand Up @@ -194,8 +196,6 @@ JOIN taxonomie.taxref t
JOIN source
ON TRUE
JOIN observers obs
ON obs.id_base_visit = v.id_base_visit
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.the_geom_local) alt (altitude_min, altitude_max)
ON TRUE
ON obs.id_base_visit = v.id_base_visit
WHERE m.module_code = :module_code
;
19 changes: 8 additions & 11 deletions RHOMEOOrthoptere/synthese.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ WITH source AS (
WHERE name_source = CONCAT('MONITORING_', UPPER(:module_code))
LIMIT 1

), sites AS (

SELECT

), sites AS (
SELECT
id_base_site,
geom AS the_geom_4326,
ST_CENTROID(geom) AS the_geom_point,
geom_local as the_geom_local

geom_local as the_geom_local ,
altitude_min,
altitude_max
FROM gn_monitoring.t_base_sites

), visits AS (
Expand Down Expand Up @@ -143,8 +142,8 @@ SELECT
--meta_v_taxref
--sample_number_proof
--digital_proofvue
alt.altitude_min,
alt.altitude_max,
s.altitude_min,
s.altitude_max,
s.the_geom_4326,
s.the_geom_point,
s.the_geom_local,
Expand Down Expand Up @@ -181,8 +180,6 @@ JOIN taxonomie.taxref t
JOIN source
ON TRUE
JOIN observers obs
ON obs.id_base_visit = v.id_base_visit
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.the_geom_local) alt (altitude_min, altitude_max)
ON TRUE
ON obs.id_base_visit = v.id_base_visit
WHERE m.module_code = :module_code
;
5 changes: 2 additions & 3 deletions apollons/synthese.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ WITH source AS (
COALESCE((vc.DATA->>'count_stade_l5')::int, 0) AS count_max,
t.cd_nom,
t.nom_complet AS nom_cite,
alt.altitude_min,
alt.altitude_max,
s.altitude_min,
s.altitude_max,
s.geom AS the_geom_4326,
st_centroid(s.geom) AS the_geom_point,
s.geom_local AS the_geom_local,
Expand All @@ -66,7 +66,6 @@ WITH source AS (
JOIN taxonomie.taxref t ON t.cd_nom = ((vc.data ->> 'cd_nom'::text)::integer)
LEFT JOIN observers obs ON obs.id_base_visit = v.id_base_visit
JOIN source ON true
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt(altitude_min, altitude_max) ON true
WHERE m.module_code = :module_code
AND COALESCE((vc.DATA->>'count_stade_l1')::int, 0) +
COALESCE((vc.DATA->>'count_stade_l2')::int, 0) +
Expand Down
8 changes: 3 additions & 5 deletions cheveches/synthese.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ SELECT
--meta_v_taxref
--sample_number_proof
--digital_proofvue
alt.altitude_min,
alt.altitude_max,
s.altitude_min,
s.altitude_max,
s.geom AS the_geom_4326,
ST_CENTROID(s.geom) AS the_geom_point,
s.geom_local AS the_geom_local,
Expand Down Expand Up @@ -89,8 +89,6 @@ SELECT
JOIN taxonomie.taxref t ON cd_nom = (vc.data->>'cd_nom')::int
LEFT OUTER JOIN observers obs ON obs.id_base_visit = v.id_base_visit
JOIN source
ON TRUE
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt (altitude_min, altitude_max)
ON TRUE
ON TRUE
WHERE m.module_code = :module_code
;
7 changes: 3 additions & 4 deletions chiro/synthese.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ SELECT
ref_nomenclatures.get_id_nomenclature('TYP_GRP', 'REL') as id_nomenclature_grp_typ,
t.cd_nom,
t.nom_complet AS nom_cite,
alt.altitude_min,
alt.altitude_max,
s.altitude_min,
s.altitude_max,
s.geom AS the_geom_4326,
st_centroid(s.geom) AS the_geom_point,
s.geom_local AS the_geom_local,
Expand Down Expand Up @@ -66,7 +66,6 @@ JOIN gn_monitoring.t_observations to2 ON to2.id_base_visit = vc.id_base_visit
JOIN gn_monitoring.t_observation_complements toc ON toc.id_observation = to2.id_observation
JOIN taxonomie.taxref t ON t.cd_nom = to2.cd_nom
JOIN observers obs ON obs.id_base_visit = v.id_base_visit
JOIN source ON true
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt(altitude_min, altitude_max) ON true
JOIN source ON true
WHERE m.module_code = 'chiro'
ORDER BY to2.uuid_observation;
12 changes: 6 additions & 6 deletions chronocapture/synthese.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ WITH source AS (
uuid_base_site,
geom AS the_geom_4326,
ST_CENTROID(geom) AS the_geom_point,
geom_local as geom_local

FROM gn_monitoring.t_base_sites
geom_local as geom_local,
s.altitude_min,
s.altitude_max
FROM gn_monitoring.t_base_sites s

), visits AS (

Expand Down Expand Up @@ -85,8 +86,8 @@ SELECT
--meta_v_taxref
--sample_number_proof
--digital_proofvue
alt.altitude_min,
alt.altitude_max,
s.altitude_min,
s.altitude_max,
s.the_geom_4326, -- v.
s.the_geom_point, -- v.
s.geom_local as the_geom_local, -- v.
Expand Down Expand Up @@ -120,5 +121,4 @@ SELECT
--JOIN gn_monitoring.t_observations o ON o.id_base_visit = v.id_base_visit
JOIN gn_monitoring.t_observation_complements oc ON oc.id_observation=o.id_observation
JOIN taxonomie.taxref t ON t.cd_nom = o.cd_nom
LEFT JOIN LATERAL ref_geo.fct_get_altitude_intersection(s.geom_local) alt (altitude_min, altitude_max) ON true
WHERE m.module_code = 'chronocapture';
Loading

0 comments on commit a712c57

Please sign in to comment.