intersection v_zh
This commit is contained in:
parent
94d2ccd513
commit
05cb232bec
@ -2,10 +2,11 @@
|
|||||||
# -*- coding: UTF-8 -*-.
|
# -*- coding: UTF-8 -*-.
|
||||||
|
|
||||||
import geopandas as gpd
|
import geopandas as gpd
|
||||||
from pycen import con
|
from pycen import con,zh
|
||||||
from os import path,listdir
|
from os import path,listdir
|
||||||
from re import findall
|
from re import findall
|
||||||
|
|
||||||
|
v_zh = zh().v_zoneshumides()
|
||||||
PATH = '/media/colas/SRV/FICHIERS/OUTILS/CARTOGRAPHIE/ESPACE DE TRAVAIL/ETUDES/Zones humides'
|
PATH = '/media/colas/SRV/FICHIERS/OUTILS/CARTOGRAPHIE/ESPACE DE TRAVAIL/ETUDES/Zones humides'
|
||||||
lst_layer = [x for x in listdir(PATH) if (x.endswith('.shp') or x.endswith('.gpkg')) and x.startswith('ZHP')]
|
lst_layer = [x for x in listdir(PATH) if (x.endswith('.shp') or x.endswith('.gpkg')) and x.startswith('ZHP')]
|
||||||
|
|
||||||
@ -61,6 +62,7 @@ if __name__ == "__main__":
|
|||||||
gdf.sort_values(['datemodif'],inplace=True,ignore_index=True,ascending=False)
|
gdf.sort_values(['datemodif'],inplace=True,ignore_index=True,ascending=False)
|
||||||
gdf.drop(columns=['X','Y'],inplace=True,errors='ignore')
|
gdf.drop(columns=['X','Y'],inplace=True,errors='ignore')
|
||||||
gdf.rename_geometry('geom',inplace=True)
|
gdf.rename_geometry('geom',inplace=True)
|
||||||
|
# Suppression des doublons de géometries - temps de calcul long
|
||||||
gdf.drop_duplicates(subset='geom',inplace=True,ignore_index=True,keep='first')
|
gdf.drop_duplicates(subset='geom',inplace=True,ignore_index=True,keep='first')
|
||||||
|
|
||||||
tmp = (gdf.descripti2
|
tmp = (gdf.descripti2
|
||||||
@ -200,6 +202,9 @@ if __name__ == "__main__":
|
|||||||
statut_isna = gdf['statut'].isna()
|
statut_isna = gdf['statut'].isna()
|
||||||
gdf.loc[is_interpret&statut_isna,'statut'] = 'A visiter'
|
gdf.loc[is_interpret&statut_isna,'statut'] = 'A visiter'
|
||||||
|
|
||||||
|
is_zh2 = gdf['statut'].isna()&gdf['comment'].str.startswith('Zh',na=False)
|
||||||
|
gdf.loc[is_zh2,'statut'] = 'A décrire'
|
||||||
|
|
||||||
dict_type = {
|
dict_type = {
|
||||||
**dict.fromkeys(['Barrage','Bassin','Lagunage'],'Artificiel'),
|
**dict.fromkeys(['Barrage','Bassin','Lagunage'],'Artificiel'),
|
||||||
**dict.fromkeys(['Mégaphorbiaie','Prairie','Prairie humide','Roselière'],'Prairie humide et roselière'),
|
**dict.fromkeys(['Mégaphorbiaie','Prairie','Prairie humide','Roselière'],'Prairie humide et roselière'),
|
||||||
@ -210,18 +215,58 @@ if __name__ == "__main__":
|
|||||||
gdf['classe'] = (gdf['type']
|
gdf['classe'] = (gdf['type']
|
||||||
.replace(dict_type))
|
.replace(dict_type))
|
||||||
|
|
||||||
|
# Harmonisation des observateurs
|
||||||
|
dict_obs = {
|
||||||
|
'NB':'CEN Isère (N. Biron)',
|
||||||
|
'Nico':'CEN Isère (N. Biron)',
|
||||||
|
'Alix':'CEN Isère (A. Guedou)',
|
||||||
|
'N BIRON':'CEN Isère (N. Biron)',
|
||||||
|
'N. Biron (CEN Isère)':'CEN Isère (N. Biron)',
|
||||||
|
'Nicolas Biron':'CEN Isère (N. Biron)',
|
||||||
|
'M. Juton (CEN Isère)':'CEN Isère (M. Juton)',
|
||||||
|
'CEN Isère (J.-L. Grossi)':'CEN Isère (J. L. Grossi)',
|
||||||
|
'Lpo Isère (F. Frossard)':'LPO Isère (F. Frossard)',
|
||||||
|
'Lpo Isère (H. Coffre)':'LPO Isère (H. Coffre)',
|
||||||
|
'Lpo Isère (D. Loose)':'LPO Isère (D. Loose)',
|
||||||
|
'J. F. Noblet':'Le Pic Vert (J. F. Noblet)',
|
||||||
|
'R. Fonters':'LPO Isère (R. Fonters)',
|
||||||
|
'R. Marciau':'CEN Isère (R. Marciau)',
|
||||||
|
}
|
||||||
|
gdf.replace(dict_obs,inplace=True)
|
||||||
|
|
||||||
|
# Suppression des ZH taguer Absence
|
||||||
|
not_zh = gdf['statut']=='Absence ZH'
|
||||||
|
idx_notzh = gdf[not_zh].index
|
||||||
|
gdf.drop(idx_notzh,inplace=True)
|
||||||
|
|
||||||
|
# Intersection des zh_ponctuelles et zh_surfacique - temps de calcul long
|
||||||
|
v_zh_union = v_zh.unary_union
|
||||||
|
is_intersect = gdf.intersects(v_zh_union)
|
||||||
|
|
||||||
|
lst_drop = ['Tourbière','Culture','Boisement','Prairie humide','Roselière','Grève','Barrage','Lac']
|
||||||
|
drop_prospect_pontc = ~gdf['type'].isin(lst_drop)
|
||||||
|
gdf_zh = gdf[is_intersect&drop_prospect_pontc].copy()
|
||||||
|
gdf_ponct= gdf[~is_intersect].copy()
|
||||||
|
|
||||||
|
|
||||||
# A faire :
|
# A faire :
|
||||||
# - Vérifier la suppression des zhAbsentes
|
|
||||||
# - Intersecter avec la couche zh surfacique,
|
# - Intersecter avec la couche zh surfacique,
|
||||||
# dissocier les donner d'intersection et conserver
|
# dissocier les donner d'intersection et conserver
|
||||||
# dans une autre couche les zones ponctuelles correspondant à des Mares/Etangs/bassin/Lac
|
# dans une autre couche les zones ponctuelles correspondant à des Mares/Etangs/bassin/Lac
|
||||||
|
|
||||||
|
bdd_table = 'zh_ponctuelles'
|
||||||
|
gdf_ponct.to_postgis(bdd_table,con,'zones_humides',if_exists='replace',index=True if 'gid' not in gdf.columns else False,index_label='gid')
|
||||||
|
|
||||||
|
sql = """
|
||||||
|
ALTER TABLE zones_humides.{tab} ADD PRIMARY KEY (gid);
|
||||||
|
GRANT ALL ON TABLE zones_humides.{tab} TO grp_admin;
|
||||||
|
GRANT SELECT ON TABLE zones_humides.{tab} TO grp_consult;
|
||||||
|
""".format(tab=bdd_table)
|
||||||
|
with con.begin() as cnx:
|
||||||
|
cnx.execute(sql)
|
||||||
|
|
||||||
|
bdd_table = 'zh_ponctuelles_in_zh'
|
||||||
bdd_table = 'zh_ponctuelles_encours'
|
gdf_zh.to_postgis(bdd_table,con,'zones_humides',if_exists='replace',index=True if 'gid' not in gdf.columns else False,index_label='gid')
|
||||||
gdf.to_postgis(bdd_table,con,'zones_humides',if_exists='replace',index=True if 'gid' not in gdf.columns else False,index_label='gid')
|
|
||||||
|
|
||||||
sql = """
|
sql = """
|
||||||
ALTER TABLE zones_humides.{tab} ADD PRIMARY KEY (gid);
|
ALTER TABLE zones_humides.{tab} ADD PRIMARY KEY (gid);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user