diff --git a/0_FONCIER/v_veillefonciere.py b/0_FONCIER/v_veillefonciere.py new file mode 100644 index 0000000..1415bd8 --- /dev/null +++ b/0_FONCIER/v_veillefonciere.py @@ -0,0 +1,27 @@ + +from sqlalchemy import text +from pycen import con_fon + +v_veillefonciere = """ +DROP VIEW IF EXISTS _tdb_f6cen.v_veillefonciere; +CREATE OR REPLACE VIEW _tdb_f6cen.v_veillefonciere +AS +SELECT + row_number() OVER (ORDER BY SPLIT_PART(site_id,'_',1) ASC) AS gid, + SPLIT_PART(site_id,'_',1) AS site_id, + SPLIT_PART(site_nom,' - Z',1) AS site_nom, + enjeu_lib, + 'CONSERVATOIRE D''ESPACES NATURELS ISERE'::text AS cen, + 38::int AS dept, + st_area(st_union(geom_vf)) AS superficie, + st_union(geom_vf) geom +FROM sites.sites +JOIN sites.d_enjeux USING (enjeu_id) +WHERE veillefonciere +GROUP BY 2,3,4 +ORDER BY 1 +; +""" + +with con_fon.begin() as cnx: + cnx.execute(text(v_veillefonciere))