init depot renew
This commit is contained in:
@@ -0,0 +1,145 @@
|
||||
import geopandas as gpd
|
||||
from pycen import con_bdcen
|
||||
|
||||
###############
|
||||
#### TOPO #####
|
||||
###############
|
||||
sql = '''
|
||||
ALTER TABLE sites_topo.topo_ligne RENAME column "Geometry" to geom;
|
||||
ALTER TABLE sites_topo.topo_ligne OWNER TO cen_admin;
|
||||
|
||||
CREATE SEQUENCE sites_topo.topo_ligne_id_seq OWNED BY sites_topo.topo_ligne."PK_UID";
|
||||
SELECT setval('sites_topo.topo_ligne_id_seq', coalesce(max("PK_UID"), 0) + 1, false) FROM sites_topo.topo_ligne;
|
||||
ALTER TABLE sites_topo.topo_ligne ALTER COLUMN "PK_UID" SET DEFAULT nextval('sites_topo.topo_ligne_id_seq');
|
||||
'''
|
||||
with con_bdcen.begin() as cnx:
|
||||
cnx.execute(sql)
|
||||
|
||||
tline_clt = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_consultation.sqlite',layer='topo_ligne')
|
||||
tline_sai = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_saisie.sqlite',layer='topo_ligne')
|
||||
tmp = gpd.pd.concat([tline_clt,tline_sai])
|
||||
isdupl = tmp.geometry.to_wkt().duplicated(keep=False)
|
||||
tmp[isdupl]
|
||||
iners = tline_sai.buffer(-1).intersects(tline_clt.unary_union)
|
||||
(tline_sai[~iners]
|
||||
.rename_geometry('geom')
|
||||
.to_postgis(
|
||||
'topo_ligne',
|
||||
con_bdcen,
|
||||
schema='sites_topo',
|
||||
if_exists='append',
|
||||
index=False,
|
||||
))
|
||||
|
||||
tpoly_clt = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_consultation.sqlite',layer='topo_polygone')
|
||||
tpoly_sai = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_saisie.sqlite',layer='topo_polygone')
|
||||
gpd.pd.concat([tpoly_clt,tpoly_sai]).drop_duplicates(subset='geometry')
|
||||
iners = tpoly_sai.intersects(tpoly_clt.unary_union)
|
||||
(tpoly_sai[~iners]
|
||||
.rename_geometry('geom')
|
||||
.to_postgis(
|
||||
'topo_polygone',
|
||||
con_bdcen,
|
||||
schema='sites_topo',
|
||||
if_exists='append',
|
||||
index=False,
|
||||
))
|
||||
|
||||
tpnt_clt = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_consultation.sqlite',layer='topo_point')
|
||||
tpnt_sai = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_saisie.sqlite',layer='topo_point')
|
||||
tmp = gpd.pd.concat([tpnt_clt,tpnt_sai])
|
||||
isdupl = tmp.geometry.to_wkt().duplicated(keep=False)
|
||||
tmp[isdupl].drop_duplicates(subset='geometry')
|
||||
|
||||
gpd.pd.concat([tpnt_clt,tpnt_sai]).drop_duplicates(subset='geometry')
|
||||
iners = tpnt_sai.intersects(tpnt_clt.unary_union)
|
||||
(tpnt_sai[~iners]
|
||||
.rename_geometry('geom')
|
||||
.to_postgis(
|
||||
'topo_point',
|
||||
con_bdcen,
|
||||
schema='sites_topo',
|
||||
if_exists='append',
|
||||
index=False,
|
||||
))
|
||||
|
||||
###############
|
||||
#### HYDRO ####
|
||||
###############
|
||||
sql = '''
|
||||
--ALTER TABLE sites_hydro.hydro_point RENAME column "Geometry" to geom;
|
||||
ALTER TABLE sites_hydro.hydro_point OWNER TO cen_admin;
|
||||
|
||||
CREATE SEQUENCE sites_hydro.hydro_point_id_seq OWNED BY sites_hydro.hydro_point."PK_UID";
|
||||
SELECT setval('sites_hydro.hydro_point_id_seq', coalesce(max("PK_UID"), 0) + 1, false) FROM sites_hydro.hydro_point;
|
||||
ALTER TABLE sites_hydro.hydro_point ALTER COLUMN "PK_UID" SET DEFAULT nextval('sites_hydro.hydro_point_id_seq');
|
||||
'''
|
||||
with con_bdcen.begin() as cnx:
|
||||
cnx.execute(sql)
|
||||
|
||||
|
||||
hline_clt = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_consultation.sqlite',layer='hydro_ligne')
|
||||
hline_sai = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_saisie.sqlite',layer='hydro_ligne')
|
||||
hline_sai.dropna(subset='geometry',inplace=True)
|
||||
tmp = gpd.pd.concat([hline_clt,hline_sai])
|
||||
isdupl = tmp.geometry.to_wkt().duplicated(keep=False)
|
||||
tmp[isdupl]
|
||||
hline_clt[hline_clt.geometry.to_wkt().duplicated(keep=False)]
|
||||
hline_sai[hline_sai.geometry.to_wkt().duplicated(keep=False)]
|
||||
iners = hline_sai.buffer(-1).intersects(hline_clt.unary_union)
|
||||
(hline_sai[~iners]
|
||||
.rename_geometry('geom')
|
||||
.to_postgis(
|
||||
'hydro_ligne',
|
||||
con_bdcen,
|
||||
schema='sites_hydro',
|
||||
if_exists='append',
|
||||
index=False,
|
||||
))
|
||||
res = gpd.read_postgis('SELECT * FROM sites_hydro.hydro_ligne',con_bdcen)
|
||||
res['geom_wkt'] = res.geom.to_wkt()
|
||||
res[res.geom_wkt.duplicated(keep=False)].sort_values(['geom_wkt','Type']).PK_UID.to_list()
|
||||
|
||||
|
||||
hpoly_clt = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_consultation.sqlite',layer='hydro_polygone')
|
||||
hpoly_sai = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_saisie.sqlite',layer='hydro_polygone')
|
||||
tmp = gpd.pd.concat([hpoly_clt,hpoly_sai])
|
||||
isdupl = tmp.geometry.to_wkt().duplicated(keep=False)
|
||||
tmp[isdupl]
|
||||
iners = hpoly_sai.buffer(-1).intersects(hpoly_clt.unary_union)
|
||||
(hpoly_sai
|
||||
.rename_geometry('geom')
|
||||
.to_postgis(
|
||||
'hydro_polygone',
|
||||
con_bdcen,
|
||||
schema='sites_hydro',
|
||||
if_exists='append',
|
||||
index=False,
|
||||
))
|
||||
res = gpd.read_postgis('SELECT * FROM sites_hydro.hydro_polygone',con_bdcen)
|
||||
res['geom_wkt'] = res.geom.to_wkt()
|
||||
res[res.geom_wkt.duplicated(keep=False)].sort_values(['geom_wkt','Type','NOM']).PK_UID.to_list()
|
||||
|
||||
|
||||
hpnt_clt = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_consultation.sqlite',layer='hydro_point')
|
||||
hpnt_clt.dropna(subset='geometry', inplace=True)
|
||||
hpnt_sai = gpd.read_file('/home/colas/Documents/5_BDD/7_CEN38/topographie_saisie.sqlite',layer='hydro_point')
|
||||
hpnt_sai.replace({'':None}, inplace=True)
|
||||
tmp = gpd.pd.concat([hpnt_clt,hpnt_sai])
|
||||
isdupl = tmp.geometry.to_wkt().duplicated(keep=False)
|
||||
tmp[isdupl].drop_duplicates(subset='geometry')
|
||||
|
||||
gpd.pd.concat([hpnt_clt,hpnt_sai]).drop_duplicates(subset='geometry')
|
||||
iners = hpnt_sai.intersects(hpnt_clt.unary_union)
|
||||
(hpnt_sai
|
||||
.rename_geometry('geom')
|
||||
.to_postgis(
|
||||
'hydro_point',
|
||||
con_bdcen,
|
||||
schema='sites_hydro',
|
||||
if_exists='append',
|
||||
index=False,
|
||||
))
|
||||
res = gpd.read_postgis('SELECT * FROM sites_hydro.hydro_point',con_bdcen)
|
||||
res['geom_wkt'] = res.geom.to_wkt()
|
||||
res[res.geom_wkt.duplicated(keep=False)].sort_values(['geom_wkt','Type','TYPE_PRINC']).PK_UID.to_list()
|
||||
Reference in New Issue
Block a user