update rpg 2023
This commit is contained in:
parent
8727af5ada
commit
079c675dc6
@ -7,11 +7,11 @@ from datetime import datetime as dt
|
||||
|
||||
|
||||
|
||||
file = '/home/colas/Documents/tmp/rpg/RPG_2-0__SHP_LAMB93_R84_2022-01-01.7z/RPG_2-0__SHP_LAMB93_R84_2022-01-01/RPG/1_DONNEES_LIVRAISON_2023-08-01/RPG_2-0_SHP_LAMB93_R84-2022/PARCELLES_GRAPHIQUES.shp'
|
||||
file = '/home/colas/Documents/tmp/rpg/RPG_2-2__SHP_LAMB93_R84_2023-01-01/RPG/1_DONNEES_LIVRAISON_2023/RPG_2-2__SHP_LAMB93_R84_2023-01-01/PARCELLES_GRAPHIQUES.shp'
|
||||
|
||||
name_table = 'rpg_parcelles_graphiques_reg'
|
||||
name_schema = 'ref_territoire'
|
||||
thisyear = dt.now().year-2
|
||||
thisyear = dt.now().year-1
|
||||
|
||||
df = gpd.read_file(file)
|
||||
df.columns = df.columns.str.lower()
|
||||
@ -26,12 +26,19 @@ if df.crs.srs != 'epsg:2154':
|
||||
|
||||
exist_table = con.dialect.get_table_names(con, schema = name_schema)
|
||||
if name_table in exist_table:
|
||||
sql = """ALTER TABLE {sch}.{tab} RENAME TO {sch}.{othertab};
|
||||
""".format(sch=name_schema,tab=name_table,othertab=name_table.replace('rpg','rpg'+str(thisyear-1)))
|
||||
other_table = name_table.replace('rpg','rpg'+str(thisyear-1))
|
||||
view = 'v_'+name_table.replace('reg','isere')
|
||||
other_view = view.replace('rpg','rpg'+str(thisyear-1))
|
||||
sql = """
|
||||
ALTER TABLE IF EXISTS {sch}.{tab} RENAME TO "{othertab}";
|
||||
ALTER VIEW IF EXISTS {sch}.{view} RENAME TO "v_{otherview}";
|
||||
ALTER INDEX IF EXISTS {sch}.idx_rpg_parcelles_graphiques_reg_geom RENAME TO "idx_rpg{old_year}_parcelles_graphiques_reg_geom";
|
||||
|
||||
""".format(sch=name_schema,tab=name_table,othertab=other_table,old_year=thisyear-1,view=view,otherview=other_view)
|
||||
with con.begin() as cnx:
|
||||
cnx.execute(sql)
|
||||
|
||||
df.to_postgis(
|
||||
df.drop_duplicates().to_postgis(
|
||||
name = name_table,
|
||||
con = con,
|
||||
schema = name_schema,
|
||||
@ -39,10 +46,11 @@ df.to_postgis(
|
||||
index = False
|
||||
)
|
||||
|
||||
sql = """ALTER TABLE {sch}.{tab} OWNER TO cen_admin;
|
||||
GRANT ALL ON TABLE {sch}.{tab} TO cen_admin;
|
||||
GRANT ALL ON TABLE {sch}.{tab} TO grp_admin;
|
||||
GRANT SELECT ON TABLE {sch}.{tab} TO grp_consult;
|
||||
sql = """
|
||||
ALTER TABLE {sch}.{tab} OWNER TO cen_admin;
|
||||
GRANT ALL ON TABLE {sch}.{tab} TO cen_admin;
|
||||
GRANT ALL ON TABLE {sch}.{tab} TO grp_admin;
|
||||
GRANT SELECT ON TABLE {sch}.{tab} TO grp_consult;
|
||||
""".format(sch=name_schema,tab=name_table)
|
||||
comment = """COMMENT ON TABLE {sch}.{tab} IS 'Version {v} 2.1 - Table des parcelles graphiques de la région Auvergne Rhône-Alpes.'""".format(sch=name_schema,tab=name_table,v=thisyear)
|
||||
with con.begin() as cnx:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user