From bfcc86a5a7787fafd8e335ecf42a9d3574b07c92 Mon Sep 17 00:00:00 2001 From: Colas Geier Date: Mon, 26 Feb 2024 15:31:45 +0100 Subject: [PATCH] view cadastre --- 0_FONCIER/CADASTRE/view_cadastre.py | 70 +++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 0_FONCIER/CADASTRE/view_cadastre.py diff --git a/0_FONCIER/CADASTRE/view_cadastre.py b/0_FONCIER/CADASTRE/view_cadastre.py new file mode 100644 index 0000000..4870f2e --- /dev/null +++ b/0_FONCIER/CADASTRE/view_cadastre.py @@ -0,0 +1,70 @@ +from pycen import con_fon + +view_typprop_x = ''' +DROP VIEW IF EXISTS {sch}.{view}; +CREATE OR REPLACE VIEW {sch}.{view} +AS + SELECT + p.par_id, + p.codcom, + p.ccopre, + p.ccosec, + p.dnupla, + p.dparpi, + p.dcntpa, + p.ccocomm, + p.ccoprem, + p.ccosecm, + p.dnuplam, + p.type, + p.geom, + typprop_lib, + typprop, + array_agg(dnuper) dnuper, + array_agg(ddenom) ddenom + FROM "{sch}".parcelles{_cen} p + LEFT JOIN "{sch}".d_typprop USING (typprop_id) + LEFT JOIN "{sch}".lots{_cen} USING (par_id) + LEFT JOIN "{sch}".cadastre{_cen} USING (lot_id) + LEFT JOIN "{sch}".cptprop{_cen} USING (dnupro) + LEFT JOIN "{sch}".r_prop_cptprop{_cen} USING (dnupro) + LEFT JOIN "{sch}".proprios{_cen} USING (dnuper) + GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 +''' + +grant = """ +GRANT ALL ON TABLE {sch}.{view} TO grp_admin; +GRANT SELECT ON TABLE {sch}.{view} TO grp_consult; +""" + +with con_fon.begin() as cnx: + cnx.execute(view_typprop_x.format(sch='cadastre', _cen= '', view='v_prop_parcelles')) + cnx.execute(view_typprop_x.format(sch='cadastre', _cen= '_cen', view='v_prop_parcelles_cen')) + cnx.execute(grant.format(sch='cadastre', view='v_prop_parcelles')) + cnx.execute(grant.format(sch='cadastre', view='v_prop_parcelles_cen')) + + +view_natcult_x = ''' +DROP VIEW IF EXISTS {sch}.{view}; +CREATE OR REPLACE VIEW {sch}.{view} +AS + SELECT + p.par_id, + p.geom, + array_agg(d_dsgrpf.natcult_ssgrp) natcult_ssgrp, + array_agg(d_cgrnum.natcult_grp) natcult_grp, + array_agg(d_cnatsp.natcult_natspe) natcult_natspe + FROM "{sch}".parcelles{_cen} p + LEFT JOIN "{sch}".lots{_cen} USING (par_id) + LEFT JOIN "{sch}".lots_natcult{_cen} USING (lot_id) + LEFT JOIN "{sch}".d_dsgrpf USING (dsgrpf) + LEFT JOIN "{sch}".d_cgrnum USING (cgrnum) + LEFT JOIN "{sch}".d_cnatsp USING (cnatsp) + GROUP BY par_id +''' + +with con_fon.begin() as cnx: + cnx.execute(view_natcult_x.format(sch='cadastre', _cen= '', view='v_natcult')) + cnx.execute(view_natcult_x.format(sch='cadastre', _cen= '_cen', view='v_natcult_cen')) + cnx.execute(grant.format(sch='cadastre', view='v_natcult')) + cnx.execute(grant.format(sch='cadastre', view='v_natcult_cen')) \ No newline at end of file