Compare commits
No commits in common. "ca84adc12ec317d04d1f9e21586801bd92a2e767" and "4ff41ed91a9c94a12f4c155023b6f0b613f16e64" have entirely different histories.
ca84adc12e
...
4ff41ed91a
@ -8,9 +8,9 @@
|
|||||||
|
|
||||||
# import re
|
# import re
|
||||||
from contextlib import AsyncExitStack
|
from contextlib import AsyncExitStack
|
||||||
from os import register_at_fork,path
|
from os import register_at_fork
|
||||||
import types
|
import types
|
||||||
# from numpy.lib.shape_base import expand_dims
|
from numpy.lib.shape_base import expand_dims
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import geopandas as gpd
|
import geopandas as gpd
|
||||||
from pandas.io.pytables import incompatibility_doc
|
from pandas.io.pytables import incompatibility_doc
|
||||||
@ -340,7 +340,6 @@ def normalize_colname(df):
|
|||||||
'remarque' :'remarques',
|
'remarque' :'remarques',
|
||||||
'remarq_' :'remarques',
|
'remarq_' :'remarques',
|
||||||
'rmq_intere' :'remarques',
|
'rmq_intere' :'remarques',
|
||||||
# 'rmq_site' :'remarques',
|
|
||||||
'legendes' :'legende',
|
'legendes' :'legende',
|
||||||
'legend' :'legende',
|
'legend' :'legende',
|
||||||
'sources' :'source',
|
'sources' :'source',
|
||||||
@ -399,7 +398,6 @@ def existing_ps(df):
|
|||||||
|
|
||||||
return df
|
return df
|
||||||
|
|
||||||
|
|
||||||
def define_siteOrg(df):
|
def define_siteOrg(df):
|
||||||
gdf = pycen.get_districtNat()[['abrev','geom']]
|
gdf = pycen.get_districtNat()[['abrev','geom']]
|
||||||
tmp = df[['geom']].copy().set_geometry('geom')
|
tmp = df[['geom']].copy().set_geometry('geom')
|
||||||
@ -417,7 +415,6 @@ def define_siteOrg(df):
|
|||||||
return df
|
return df
|
||||||
# tmp[tmp.id_site==334]
|
# tmp[tmp.id_site==334]
|
||||||
|
|
||||||
|
|
||||||
# 'touches', None, 'contains', 'overlaps', 'contains_properly', 'within', 'intersects', 'crosses', 'covers', 'covered_by'
|
# 'touches', None, 'contains', 'overlaps', 'contains_properly', 'within', 'intersects', 'crosses', 'covers', 'covered_by'
|
||||||
def ident_newsite(df,rcvmt=10):
|
def ident_newsite(df,rcvmt=10):
|
||||||
'''
|
'''
|
||||||
@ -470,7 +467,7 @@ def ident_newsite(df,rcvmt=10):
|
|||||||
tmpp[['site_code','id_origine']], on=['id_origine'])
|
tmpp[['site_code','id_origine']], on=['id_origine'])
|
||||||
maj2['id_site'] = maj2['site_code']
|
maj2['id_site'] = maj2['site_code']
|
||||||
del maj2['site_code']
|
del maj2['site_code']
|
||||||
if not maj.empty : df_maj = pd.concat([maj,maj2])
|
if maj : df_maj = pd.concat([maj,maj2])
|
||||||
else : df_maj = maj2
|
else : df_maj = maj2
|
||||||
# Isolement des nouveaux sites
|
# Isolement des nouveaux sites
|
||||||
orig_maj_all = df_maj.id_origine
|
orig_maj_all = df_maj.id_origine
|
||||||
@ -486,6 +483,7 @@ def ident_newsite(df,rcvmt=10):
|
|||||||
return df_new, df_cor, df_maj
|
return df_new, df_cor, df_maj
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def define_siteName(df,rcvmt=10):
|
def define_siteName(df,rcvmt=10):
|
||||||
'''
|
'''
|
||||||
Return df_new, df_replace, df_maj
|
Return df_new, df_replace, df_maj
|
||||||
@ -538,6 +536,7 @@ def define_siteName(df,rcvmt=10):
|
|||||||
return df_new, df_replace, df_maj
|
return df_new, df_replace, df_maj
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def normalize_formatIdsite(id_site):
|
def normalize_formatIdsite(id_site):
|
||||||
import re
|
import re
|
||||||
df = pd.DataFrame({'id_site':id_site})
|
df = pd.DataFrame({'id_site':id_site})
|
||||||
@ -754,12 +753,12 @@ def insert_site(df):
|
|||||||
df['type_site'] = 'N.D.'
|
df['type_site'] = 'N.D.'
|
||||||
if 'type_milieu' not in df.columns:
|
if 'type_milieu' not in df.columns:
|
||||||
df['type_milieu'] = 'Pelouses sèches'
|
df['type_milieu'] = 'Pelouses sèches'
|
||||||
if 'remarques' not in df.columns:
|
# if 'remarques' not in df.columns:
|
||||||
df['remarques'] = None
|
# df['remarques'] = None
|
||||||
|
|
||||||
df = df[['id_site','nom','date','auteur','type_site','type_milieu',
|
df = df[['id_site','nom','date','auteur','type_site','type_milieu',
|
||||||
'structure'
|
'structure'
|
||||||
,'remarques'
|
# 'remarques'
|
||||||
]]
|
]]
|
||||||
drop_col = ['auteur','structure']
|
drop_col = ['auteur','structure']
|
||||||
typs = pycen.sites._get_typ_site()
|
typs = pycen.sites._get_typ_site()
|
||||||
@ -837,7 +836,7 @@ def insert_geom(df):
|
|||||||
colindict = [ *df.columns[df.columns.isin(dic.keys())] ]
|
colindict = [ *df.columns[df.columns.isin(dic.keys())] ]
|
||||||
if colindict:
|
if colindict:
|
||||||
df.rename(
|
df.rename(
|
||||||
columns=dic,
|
columns={'remarques':'rmq_interet_patri','legende':'rmq_usage_process'},
|
||||||
inplace=True,
|
inplace=True,
|
||||||
)
|
)
|
||||||
if 'table_org' in df.columns:
|
if 'table_org' in df.columns:
|
||||||
@ -1167,20 +1166,15 @@ def filter_saisierror(df):
|
|||||||
continue
|
continue
|
||||||
print('\t'+cod + ' : '+ perc.astype(str))
|
print('\t'+cod + ' : '+ perc.astype(str))
|
||||||
lst_error1 = [*lst_error1,*tmp[(tmp.hab_ == hab)&(tmp.code_hab==cod)].sort_values('id_site').id_site.unique()]
|
lst_error1 = [*lst_error1,*tmp[(tmp.hab_ == hab)&(tmp.code_hab==cod)].sort_values('id_site').id_site.unique()]
|
||||||
try:
|
df[df.id_site.isin(lst_error1)].to_postgis(
|
||||||
df[df.id_site.isin(lst_error1)].to_postgis(
|
name='incoherence_habVScodehab',
|
||||||
name='incoherence_habVScodehab',
|
con=con,
|
||||||
con=con,
|
schema=schema,
|
||||||
schema=schema,
|
if_exists='replace',
|
||||||
if_exists='replace',
|
index=False,
|
||||||
index=False,
|
# geom_col='geom',
|
||||||
# geom_col='geom',
|
index_label='id_site',
|
||||||
index_label='id_site',
|
)
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
df[df.id_site.isin(lst_error1)].to_file(path.join(path0,'incoherence_habVScodehab.geojson'),driver='GeoJSON')
|
|
||||||
|
|
||||||
if lst_error1:
|
if lst_error1:
|
||||||
print('%i'%len(lst_error1))
|
print('%i'%len(lst_error1))
|
||||||
|
|
||||||
@ -1202,51 +1196,42 @@ def filter_saisierror(df):
|
|||||||
|
|
||||||
if lst_error2:
|
if lst_error2:
|
||||||
print('ERROR code_hab : %i'%len(lst_error2))
|
print('ERROR code_hab : %i'%len(lst_error2))
|
||||||
try:
|
df[df.id_site.isin(lst_error2)].to_postgis(
|
||||||
df[df.id_site.isin(lst_error2)].to_postgis(
|
name='PB_codehab_nonPresent_dans_corineBiotope',
|
||||||
name='PB_codehab_nonPresent_dans_corineBiotope',
|
con=con,
|
||||||
con=con,
|
schema=schema,
|
||||||
schema=schema,
|
if_exists='append',
|
||||||
if_exists='append',
|
index=False,
|
||||||
index=False,
|
# geom_col='geom',
|
||||||
# geom_col='geom',
|
index_label='id_site',
|
||||||
index_label='id_site',
|
)
|
||||||
)
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
df[df.id_site.isin(lst_error2)].to_file(path.join(path0,'PB_codehab_nonPresent_dans_corineBiotope.geojson'),driver='GeoJSON')
|
|
||||||
|
|
||||||
lst_iderror = [*lst_error1,*lst_error2]
|
lst_iderror = [*lst_error1,*lst_error2]
|
||||||
lst_iderrorindex = df[df.id_site.isin(lst_iderror)].index
|
lst_iderrorindex = df[df.id_site.isin(lst_iderror)].index
|
||||||
df.drop(lst_iderrorindex,inplace=True)
|
df.drop(lst_iderrorindex,inplace=True)
|
||||||
return df.sort_values('id_site')
|
return df.sort_values('id_site')
|
||||||
|
|
||||||
|
def _insert_site_(df,ps_statut='actif'):
|
||||||
def _insert_geomsite(df):
|
|
||||||
df_ins, ins = insert_geom(df)
|
df_ins, ins = insert_geom(df)
|
||||||
if ins:
|
if ins:
|
||||||
insert_authordata(df_ins,id_data='id_site',tab_data='r_sites_geom',colname_rsite='id_geom_site', tab_auteur='r_geomsites_auteur')
|
insert_authordata(df_ins,id_data='id_site',tab_data='r_sites_geom',colname_rsite='id_geom_site', tab_auteur='r_geomsites_auteur')
|
||||||
|
|
||||||
|
df_ins, ins = insert_attrsPS(df,ps_statut)
|
||||||
|
if ins:
|
||||||
|
insert_authordata(df_ins,id_data='id_geom_site',tab_data='r_site_param',colname_rsite='id_siteparam', tab_auteur='r_siteparam_auteur')
|
||||||
|
|
||||||
def _insert_site_(df,ps_statut='actif'):
|
df_ins, ins = insert_habPS(df,ps_statut)
|
||||||
_insert_geomsite(df)
|
if ins:
|
||||||
|
if df_ins.shape[0] > 4000:
|
||||||
df_ins, ins = insert_attrsPS(df,ps_statut)
|
df_ins1 = df_ins.iloc[:round(df_ins.shape[0]/2)].copy()
|
||||||
if ins:
|
df_ins2 = df_ins.iloc[round(df_ins.shape[0]/2):].copy()
|
||||||
insert_authordata(df_ins,id_data='id_geom_site',tab_data='r_site_param',colname_rsite='id_siteparam', tab_auteur='r_siteparam_auteur')
|
insert_cbPS(df_ins1)
|
||||||
|
insert_cbPS(df_ins2)
|
||||||
df_ins, ins = insert_habPS(df,ps_statut)
|
else:
|
||||||
if ins:
|
insert_cbPS(df_ins)
|
||||||
if df_ins.shape[0] > 4000:
|
insert_authordata(
|
||||||
df_ins1 = df_ins.iloc[:round(df_ins.shape[0]/2)].copy()
|
df_ins[df_ins.columns.drop('code_hab')],id_data='id_geom_site',tab_data='r_site_habitat',
|
||||||
df_ins2 = df_ins.iloc[round(df_ins.shape[0]/2):].copy()
|
colname_rsite='id_sitehab', tab_auteur='r_sitehab_auteur')
|
||||||
insert_cbPS(df_ins1)
|
|
||||||
insert_cbPS(df_ins2)
|
|
||||||
else:
|
|
||||||
insert_cbPS(df_ins)
|
|
||||||
insert_authordata(
|
|
||||||
df_ins[df_ins.columns.drop('code_hab')],id_data='id_geom_site',tab_data='r_site_habitat',
|
|
||||||
colname_rsite='id_sitehab', tab_auteur='r_sitehab_auteur')
|
|
||||||
|
|
||||||
|
|
||||||
def maj_site(df):
|
def maj_site(df):
|
||||||
@ -1320,7 +1305,7 @@ if __name__ == "__main__":
|
|||||||
from_table = None
|
from_table = None
|
||||||
from_file = 'PS prioritaire.geojson'
|
from_file = 'PS prioritaire.geojson'
|
||||||
from_tab = 'Tableau_saisie_PS_2026.xlsx'
|
from_tab = 'Tableau_saisie_PS_2026.xlsx'
|
||||||
path0 = '/home/cgeier/Documents/9_PROJETS/2_PS/TO IMPORT/2026'
|
path0 = '/home/colas/Documents/9_PROJETS/2_PS/TO IMPORT/2026/'
|
||||||
|
|
||||||
# org = from_file.split('/')[1]
|
# org = from_file.split('/')[1]
|
||||||
tutu = pd.DataFrame()
|
tutu = pd.DataFrame()
|
||||||
@ -1369,13 +1354,11 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
if from_file is not None:
|
if from_file is not None:
|
||||||
table = from_file.split('/')[-1]#.split('.')[0]
|
table = from_file.split('/')[-1]#.split('.')[0]
|
||||||
df = gpd.read_file(path.join(path0,from_file))
|
df = gpd.read_file(path0+from_file)
|
||||||
df.dropna(axis=1, how='all', inplace=True)
|
|
||||||
df = normalize_colname(df)
|
df = normalize_colname(df)
|
||||||
df = format_date(df)
|
df = format_date(df)
|
||||||
df['table_org'] = table
|
df['table_org'] = table
|
||||||
df['structure'] = 'CEN Isère'
|
df['structure'] = 'CEN Isère'
|
||||||
df['structure'] = df.organisme.copy()
|
|
||||||
# df['type_pat'].replace(['Indéterminé','/'],None,inplace=True)
|
# df['type_pat'].replace(['Indéterminé','/'],None,inplace=True)
|
||||||
# df.loc[df.type_pat.notna(),'pratiques'] = \
|
# df.loc[df.type_pat.notna(),'pratiques'] = \
|
||||||
# df[df.type_pat.notna()].pratiques + ' ' + df[df.type_pat.notna()].type_pat.str.lower()
|
# df[df.type_pat.notna()].pratiques + ' ' + df[df.type_pat.notna()].type_pat.str.lower()
|
||||||
@ -1401,14 +1384,14 @@ if __name__ == "__main__":
|
|||||||
tutu.rename(columns={'ident':'id_origine'}, inplace=True)
|
tutu.rename(columns={'ident':'id_origine'}, inplace=True)
|
||||||
cols = tutu.columns[tutu.columns.isin(c)]
|
cols = tutu.columns[tutu.columns.isin(c)]
|
||||||
df = tutu[cols].copy()
|
df = tutu[cols].copy()
|
||||||
df = df.set_geometry('geom', crs=2154)
|
df = df.set_geometry('geom',crs=2154)
|
||||||
# df.code_hab3.replace({
|
# df.code_hab3.replace({
|
||||||
# '43.171':'41.171',
|
# '43.171':'41.171',
|
||||||
# '31.4B':'31.4'
|
# '31.4B':'31.4'
|
||||||
# }, inplace=True)
|
# }, inplace=True)
|
||||||
|
|
||||||
df = pycen.tools.Polygons_to_MultiPolygon(df)
|
df = pycen.tools.Polygons_to_MultiPolygon(df)
|
||||||
df_new, df_replace, df_maj = define_siteName(df, rcvmt=5)
|
df_new, df_replace, df_maj = define_siteName(df,rcvmt=10)
|
||||||
|
|
||||||
df_new_tmp = df_new.copy()
|
df_new_tmp = df_new.copy()
|
||||||
df_new = df_new_tmp[df_new_tmp.id_site.notna()].copy()
|
df_new = df_new_tmp[df_new_tmp.id_site.notna()].copy()
|
||||||
|
|||||||
@ -1,41 +0,0 @@
|
|||||||
import geopandas as gpd
|
|
||||||
from os import path
|
|
||||||
|
|
||||||
PATH = '/home/cgeier/Documents/9_PROJETS/2_PS/2026/Anne BELET - couchepelousessches'
|
|
||||||
anne = gpd.read_file(path.join(PATH,'couche_finale_modif_CEN.gpkg')).set_index('site_code')
|
|
||||||
mosa = gpd.read_file(path.join(PATH,'couche_finale_modif_mosaique.gpkg')).set_index('site_code')
|
|
||||||
call = gpd.read_file(path.join(PATH,'couche_finale2.gpkg')).set_index('site_code')
|
|
||||||
|
|
||||||
date_cols = anne.columns[anne.columns.str.contains('date')]
|
|
||||||
for tab in [anne,mosa,call]:
|
|
||||||
for d in date_cols :
|
|
||||||
tab[d] = (gpd.pd.to_datetime(tab[d],format='mixed',utc=True)
|
|
||||||
.astype(str)
|
|
||||||
.str.split(' ', expand=True)[0]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
anne.loc[anne.auteur_attrs=='Anne BELET (GAM)','organisme'] = 'Grenoble Alpes Métropole'
|
|
||||||
anne.loc[anne.auteur_geom=='Anne BELET (GAM)','organisme'] = 'Grenoble Alpes Métropole'
|
|
||||||
anne.loc[anne.auteur_geom=='Ag Mosaique Env','organisme'] = 'Mosaïque Environnement'
|
|
||||||
anne.loc[anne.auteur_geom=='Ag Mosaique Env','auteur_geom'] = 'Mosaïque Environnement'
|
|
||||||
|
|
||||||
anne.loc[anne.auteur_attrs=='Anne BELET (GAM)','auteur'] = 'BELET Anne'
|
|
||||||
anne.loc[anne.auteur_geom=='Anne BELET (GAM)','auteur'] = 'BELET Anne'
|
|
||||||
anne.loc[anne.auteur_geom=='Mosaïque Environnement','auteur'] = 'Mosaïque Environnement'
|
|
||||||
|
|
||||||
anne['id_origine'] = anne.index.str[:10]
|
|
||||||
anne['id_site'] = anne.index.copy()
|
|
||||||
anne.loc[anne.index.str.len()<10,'id_site'] = None
|
|
||||||
anne.loc[anne.index.str.len()>10,'id_site'] = None
|
|
||||||
|
|
||||||
anne.rename(columns={
|
|
||||||
'rmq_interet_patri':'remarques','rmq_usage_process':'legende'
|
|
||||||
}, inplace=True)
|
|
||||||
|
|
||||||
anne.to_file(path.join(PATH,'GAM2026_couche_finale_modif_CEN (corrige).gpkg'),index=False)
|
|
||||||
mosa.to_file(path.join(PATH,'GAM2026_couche_finale_modif_mosaique (corrige).gpkg'))
|
|
||||||
call.to_file(path.join(PATH,'GAM2026_couche_finale (corrige).gpkg'))
|
|
||||||
|
|
||||||
anne.to_excel(path.join(PATH,'couche_finale_modif_CEN.xlsx'),index=False)
|
|
||||||
mosa.to_excel(path.join(PATH,'couche_finale_modif_mosaique.xlsx'))
|
|
||||||
@ -7,35 +7,34 @@ import geopandas as gpd
|
|||||||
|
|
||||||
|
|
||||||
def update_psInf1200(df):
|
def update_psInf1200(df):
|
||||||
|
|
||||||
from rasterstats import zonal_stats
|
from rasterstats import zonal_stats
|
||||||
path0 = '/home/cgeier/Documents/9_PROJETS/2_PS/'
|
path0 = '/home/colas/Documents/9_PROJETS/2_PS/'
|
||||||
path2_mnt = path0+'MNT/'
|
path2_mnt = path0+'MNT/'
|
||||||
file_mnt5 = 'MNT_5m.tif'
|
file_mnt5 = 'MNT_5m.tif'
|
||||||
|
|
||||||
zonal_tmp = zonal_stats(df,path2_mnt+file_mnt5,stats="max",nodata=0,all_touched=True)
|
zonal_tmp = zonal_stats(df,path2_mnt+file_mnt5,stats="max",nodata=0,all_touched=True)
|
||||||
zonal = gpd.pd.DataFrame(zonal_tmp)
|
zonal = gpd.pd.DataFrame(zonal_tmp)
|
||||||
zonal.columns = ['max_alti']
|
zonal.columns = ['max_alti']
|
||||||
tmp = gpd.pd.concat([df.reset_index(drop=True),zonal], axis=1)
|
tmp = gpd.pd.concat([df.reset_index(drop=True),zonal], axis=1)
|
||||||
tmp = tmp.set_geometry('geom', crs=2154)
|
tmp = tmp.set_geometry('geom', crs=2154)
|
||||||
tmp['infeq_1200'] = tmp.max_alti <= 1200
|
tmp.infeq_1200 = tmp.max_alti <= 1200
|
||||||
|
|
||||||
PS = (tmp[['site_code','infeq_1200']]
|
PS = tmp[['site_code','infeq_1200']]\
|
||||||
.rename(columns={'site_code':'id_site'},errors='ignore')
|
.rename(columns={'site_code':'id_site'})
|
||||||
)
|
|
||||||
|
|
||||||
PS.to_sql('r_infeq_1200m',con,'ps',if_exists='append',index=False)
|
PS.to_sql('r_infeq_1200m',con,'ps',if_exists='append',index=False)
|
||||||
# update_to_sql(PS,con,'r_infeq_1200m','ps','id_site')
|
# update_to_sql(PS,con,'r_infeq_1200m','ps','id_site')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ps_all = gpd.read_postgis('''
|
ps_all = gpd.read_postgis('''
|
||||||
SELECT vp.*,s7.infeq_1200
|
SELECT vp.*,s7.infeq_1200
|
||||||
FROM ps."v_pelouseseches_all" vp
|
FROM ps."v_pelouseseches_all" vp
|
||||||
LEFT JOIN ps.r_infeq_1200m s7 ON vp.site_code::text = s7.id_site::text
|
LEFT JOIN ps.r_infeq_1200m s7 ON vp.site_code::text = s7.id_site::text
|
||||||
ORDER BY vp.site_code DESC NULLS LAST;
|
ORDER BY vp.site_code DESC NULLS LAST;
|
||||||
''', con)
|
''',con)
|
||||||
isnot_1200 = ps_all.infeq_1200.isna()
|
isnot_1200 = ps_all.infeq_1200.isna()
|
||||||
ps_all[~ps_all.infeq_1200]
|
|
||||||
|
|
||||||
update_psInf1200(ps_all[isnot_1200])
|
update_psInf1200(ps_all[isnot_1200])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -263,7 +263,6 @@ WHERE t.regne = 'Animalia'
|
|||||||
-- exclision JDD `Observations opportunistes du CEN Isère importé depuis Faune Isère`
|
-- exclision JDD `Observations opportunistes du CEN Isère importé depuis Faune Isère`
|
||||||
-- statut_validation = 'Certain - très probable'
|
-- statut_validation = 'Certain - très probable'
|
||||||
-- AND n20.cd_nomenclature = '1'
|
-- AND n20.cd_nomenclature = '1'
|
||||||
AND s.cd_nom != 781926 -- Paradiarsia punicea (Hübner, 1803) ; Espèce en danger critique à faire remonter une fois la liste de sensibilité invertébrée sortie !
|
|
||||||
ORDER BY s.id_synthese;
|
ORDER BY s.id_synthese;
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
from pycen import con_gn
|
|
||||||
|
|
||||||
sql = '''
|
|
||||||
CREATE OR REPLACE VIEW gn_exports.v_bam_widget AS
|
|
||||||
SELECT
|
|
||||||
t.cd_ref AS cd_ref,
|
|
||||||
t.nom_vern AS nom_vernaculaire,
|
|
||||||
t.lb_nom AS nom_scientifique,
|
|
||||||
s.id_synthese AS id_synthese,
|
|
||||||
s.date_min AS date_min,
|
|
||||||
s.date_max AS date_max,
|
|
||||||
s.the_geom_4326 AS the_geom_4326,
|
|
||||||
t.classe AS classe
|
|
||||||
FROM gn_synthese.synthese s
|
|
||||||
JOIN taxonomie.taxref t USING(cd_nom)
|
|
||||||
;
|
|
||||||
'''
|
|
||||||
|
|
||||||
with con_gn.begin() as cnx:
|
|
||||||
cnx.execute(sql)
|
|
||||||
@ -1,273 +0,0 @@
|
|||||||
from pycen import con_gn
|
|
||||||
|
|
||||||
sql = '''
|
|
||||||
|
|
||||||
DROP VIEW IF EXISTS gn_exports.v_synthese_negria_forcenra;
|
|
||||||
|
|
||||||
CREATE OR REPLACE VIEW gn_exports.v_synthese_negria_forcenra
|
|
||||||
AS
|
|
||||||
WITH af_actors AS (
|
|
||||||
SELECT
|
|
||||||
cafa.id_acquisition_framework,
|
|
||||||
json_build_object('type_role',
|
|
||||||
CASE
|
|
||||||
WHEN cafa.id_organism IS NOT NULL THEN 'organism'::TEXT
|
|
||||||
WHEN cafa.id_role IS NOT NULL THEN 'role'::TEXT
|
|
||||||
ELSE NULL::TEXT
|
|
||||||
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
|
|
||||||
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
|
|
||||||
CASE
|
|
||||||
WHEN cafa.id_organism IS NOT NULL
|
|
||||||
THEN json_build_object('organism_name', borg.nom_organisme)
|
|
||||||
WHEN cafa.id_role IS NOT NULL THEN json_build_object('first_name',
|
|
||||||
tro.nom_role,
|
|
||||||
'last_name',
|
|
||||||
tro.prenom_role) END,
|
|
||||||
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
|
|
||||||
FROM gn_meta.cor_acquisition_framework_actor cafa
|
|
||||||
LEFT JOIN utilisateurs.bib_organismes borg ON cafa.id_organism = borg.id_organisme
|
|
||||||
LEFT JOIN utilisateurs.t_roles tro ON cafa.id_role = tro.id_role
|
|
||||||
JOIN ref_nomenclatures.t_nomenclatures tn
|
|
||||||
ON cafa.id_nomenclature_actor_role = tn.id_nomenclature
|
|
||||||
), af_territories AS (
|
|
||||||
SELECT
|
|
||||||
caft.id_acquisition_framework,
|
|
||||||
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS territories
|
|
||||||
FROM gn_meta.cor_acquisition_framework_territory caft
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures
|
|
||||||
ON caft.id_nomenclature_territory =
|
|
||||||
t_nomenclatures.id_nomenclature
|
|
||||||
GROUP BY caft.id_acquisition_framework
|
|
||||||
), af_objectives AS (
|
|
||||||
SELECT
|
|
||||||
cafo.id_acquisition_framework,
|
|
||||||
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS objectives
|
|
||||||
FROM gn_meta.cor_acquisition_framework_objectif cafo
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures
|
|
||||||
ON cafo.id_nomenclature_objectif =
|
|
||||||
t_nomenclatures.id_nomenclature
|
|
||||||
GROUP BY cafo.id_acquisition_framework
|
|
||||||
), af_voletsinp AS (
|
|
||||||
SELECT
|
|
||||||
cafv.id_acquisition_framework,
|
|
||||||
array_agg(DISTINCT t_nomenclatures.cd_nomenclature) AS voletsinp
|
|
||||||
FROM gn_meta.cor_acquisition_framework_voletsinp cafv
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures
|
|
||||||
ON cafv.id_nomenclature_voletsinp =
|
|
||||||
t_nomenclatures.id_nomenclature
|
|
||||||
GROUP BY cafv.id_acquisition_framework
|
|
||||||
), af_publication AS (
|
|
||||||
SELECT
|
|
||||||
cafp.id_acquisition_framework,
|
|
||||||
array_agg(DISTINCT
|
|
||||||
jsonb_build_object('uuid', sinp_datatype_publications.unique_publication_id,
|
|
||||||
'reference',
|
|
||||||
sinp_datatype_publications.publication_reference,
|
|
||||||
'url',
|
|
||||||
sinp_datatype_publications.publication_url)) AS publications
|
|
||||||
FROM gn_meta.cor_acquisition_framework_publication cafp
|
|
||||||
LEFT JOIN gn_meta.sinp_datatype_publications
|
|
||||||
ON cafp.id_publication = sinp_datatype_publications.id_publication
|
|
||||||
GROUP BY cafp.id_acquisition_framework
|
|
||||||
), af AS (
|
|
||||||
SELECT
|
|
||||||
taf.id_acquisition_framework,
|
|
||||||
jsonb_build_object('uuid', taf.unique_acquisition_framework_id, 'name',
|
|
||||||
taf.acquisition_framework_name,
|
|
||||||
'desc', taf.acquisition_framework_desc, 'start_date',
|
|
||||||
taf.acquisition_framework_start_date, 'end_date',
|
|
||||||
taf.acquisition_framework_end_date,
|
|
||||||
'initial_closing_date', taf.initial_closing_date, 'territories',
|
|
||||||
af_territories.territories, 'territorial_level',
|
|
||||||
ntl.cd_nomenclature, 'territory_desc', taf.territory_desc, 'objectives',
|
|
||||||
af_objectives.objectives, 'publications', af_publication.publications,
|
|
||||||
'financing_type', nft.cd_nomenclature,
|
|
||||||
'target_description',
|
|
||||||
taf.target_description, 'ecologic_or_geologic_target',
|
|
||||||
taf.ecologic_or_geologic_target, 'actors',
|
|
||||||
json_agg(af_actors.json_data), 'is_parent', taf.is_parent, 'parent_uuid',
|
|
||||||
tafp.unique_acquisition_framework_id) AS af_data
|
|
||||||
FROM gn_meta.t_acquisition_frameworks taf
|
|
||||||
LEFT JOIN gn_meta.t_acquisition_frameworks tafp
|
|
||||||
ON tafp.id_acquisition_framework = taf.acquisition_framework_parent_id
|
|
||||||
JOIN af_actors ON af_actors.id_acquisition_framework = taf.id_acquisition_framework
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures ntl
|
|
||||||
ON taf.id_nomenclature_territorial_level = ntl.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures nft
|
|
||||||
ON taf.id_nomenclature_financing_type = nft.id_nomenclature
|
|
||||||
LEFT JOIN af_territories ON af_territories.id_acquisition_framework = taf.id_acquisition_framework
|
|
||||||
LEFT JOIN af_objectives ON af_objectives.id_acquisition_framework = taf.id_acquisition_framework
|
|
||||||
LEFT JOIN af_voletsinp ON af_voletsinp.id_acquisition_framework = taf.id_acquisition_framework
|
|
||||||
LEFT JOIN af_publication ON af_publication.id_acquisition_framework = taf.id_acquisition_framework
|
|
||||||
GROUP BY taf.id_acquisition_framework, taf.acquisition_framework_name, taf.acquisition_framework_desc,
|
|
||||||
taf.acquisition_framework_start_date, taf.acquisition_framework_end_date, taf.initial_closing_date,
|
|
||||||
ntl.cd_nomenclature, nft.cd_nomenclature, af_territories.territories, af_objectives.objectives,
|
|
||||||
af_voletsinp.voletsinp, af_publication.publications, taf.is_parent,
|
|
||||||
tafp.unique_acquisition_framework_id
|
|
||||||
), ds_actors AS (
|
|
||||||
SELECT
|
|
||||||
cda.id_dataset,
|
|
||||||
json_build_object('type_role',
|
|
||||||
CASE
|
|
||||||
WHEN cda.id_organism IS NOT NULL THEN 'organism'::TEXT
|
|
||||||
WHEN cda.id_role IS NOT NULL THEN 'role'::TEXT
|
|
||||||
ELSE NULL::TEXT
|
|
||||||
END, 'uuid_actor', coalesce(borg.uuid_organisme, tro.uuid_role),
|
|
||||||
'cd_nomenclature_actor_role', tn.cd_nomenclature, 'identity',
|
|
||||||
CASE
|
|
||||||
WHEN cda.id_organism IS NOT NULL
|
|
||||||
THEN json_build_object('organism_name', borg.nom_organisme)
|
|
||||||
WHEN cda.id_role IS NOT NULL THEN json_build_object('first_name',
|
|
||||||
tro.nom_role,
|
|
||||||
'last_name',
|
|
||||||
tro.prenom_role) END,
|
|
||||||
'email', coalesce(borg.email_organisme, tro.email)) AS json_data
|
|
||||||
FROM gn_meta.cor_dataset_actor cda
|
|
||||||
LEFT JOIN utilisateurs.bib_organismes borg ON cda.id_organism = borg.id_organisme
|
|
||||||
LEFT JOIN utilisateurs.t_roles tro ON cda.id_role = tro.id_role
|
|
||||||
JOIN ref_nomenclatures.t_nomenclatures tn
|
|
||||||
ON cda.id_nomenclature_actor_role = tn.id_nomenclature
|
|
||||||
), -- FIN
|
|
||||||
ds_protocols AS (
|
|
||||||
SELECT
|
|
||||||
cdp.id_dataset,
|
|
||||||
jsonb_build_object(
|
|
||||||
'uuid', sdp.unique_protocol_id,
|
|
||||||
'name', sdp.protocol_name,
|
|
||||||
'desc', sdp.protocol_desc,
|
|
||||||
'url', sdp.protocol_url,
|
|
||||||
'type', t_nomenclatures.cd_nomenclature) AS protocols
|
|
||||||
FROM gn_meta.cor_dataset_protocol cdp
|
|
||||||
JOIN gn_meta.sinp_datatype_protocols sdp
|
|
||||||
ON cdp.id_protocol = sdp.id_protocol
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures
|
|
||||||
ON sdp.id_nomenclature_protocol_type = t_nomenclatures.id_nomenclature
|
|
||||||
), ds AS (
|
|
||||||
SELECT
|
|
||||||
tds.id_dataset,
|
|
||||||
tds.id_acquisition_framework,
|
|
||||||
-- tds.additional_data,
|
|
||||||
jsonb_build_object('uuid', tds.unique_dataset_id, 'name', tds.dataset_name, 'desc', tds.dataset_desc,
|
|
||||||
'shortname', tds.dataset_shortname, 'data_type', ndt.cd_nomenclature,
|
|
||||||
'keywords', tds.keywords, 'marine_domain', tds.marine_domain,
|
|
||||||
'terrestrial_domain', tds.terrestrial_domain, 'collecting_method',
|
|
||||||
ncm.cd_nomenclature, 'protocols',
|
|
||||||
ds_protocols.protocols,
|
|
||||||
'data_origin', ndo.cd_nomenclature,
|
|
||||||
'dataset_objectif', ndso.cd_nomenclature, 'resource_type', nrt.cd_nomenclature,
|
|
||||||
'source_status', nss.cd_nomenclature, 'territories', array_agg(DISTINCT
|
|
||||||
ref_nomenclatures.get_cd_nomenclature(cdt.id_nomenclature_territory)),
|
|
||||||
'actors', json_agg(ds_actors.json_data)) AS dataset_data
|
|
||||||
FROM gn_meta.t_datasets tds
|
|
||||||
JOIN ds_actors ON ds_actors.id_dataset = tds.id_dataset
|
|
||||||
LEFT JOIN gn_meta.cor_dataset_territory cdt ON cdt.id_dataset = tds.id_dataset
|
|
||||||
LEFT JOIN ds_protocols ON ds_protocols.id_dataset = tds.id_dataset
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures ndt
|
|
||||||
ON tds.id_nomenclature_data_type = ndt.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures ncm
|
|
||||||
ON tds.id_nomenclature_collecting_method = ncm.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures ndo
|
|
||||||
ON tds.id_nomenclature_data_origin = ndo.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures ndso
|
|
||||||
ON tds.id_nomenclature_dataset_objectif = ndso.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures nrt
|
|
||||||
ON tds.id_nomenclature_resource_type = nrt.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures nss
|
|
||||||
ON tds.id_nomenclature_source_status = nss.id_nomenclature
|
|
||||||
GROUP BY tds.id_dataset, tds.id_acquisition_framework, tds.unique_dataset_id, tds.dataset_name,
|
|
||||||
tds.dataset_desc, tds.dataset_shortname, ndt.cd_nomenclature, ncm.cd_nomenclature,
|
|
||||||
ndo.cd_nomenclature, ndso.cd_nomenclature, nrt.cd_nomenclature, nss.cd_nomenclature,
|
|
||||||
ds_protocols.protocols
|
|
||||||
)
|
|
||||||
SELECT row_number() over (ORDER BY id_synthese) as gid,
|
|
||||||
s.id_synthese,
|
|
||||||
s.entity_source_pk_value AS id_source,
|
|
||||||
s.unique_id_sinp AS id_perm_sinp,
|
|
||||||
s.unique_id_sinp_grp AS id_perm_grp_sinp,
|
|
||||||
s.date_min AS date_debut,
|
|
||||||
s.date_max AS date_fin,
|
|
||||||
s.cd_nom,
|
|
||||||
s.meta_v_taxref AS version_taxref,
|
|
||||||
s.nom_cite,
|
|
||||||
s.count_min AS nombre_min,
|
|
||||||
s.count_max AS nombre_max,
|
|
||||||
s.altitude_min,
|
|
||||||
s.altitude_max,
|
|
||||||
s.depth_min AS profondeur_min,
|
|
||||||
s.depth_max AS profondeur_max,
|
|
||||||
s.observers AS observateurs,
|
|
||||||
s.determiner AS determinateur,
|
|
||||||
s.validator AS validateur,
|
|
||||||
s.sample_number_proof AS numero_preuve,
|
|
||||||
s.digital_proof AS preuve_numerique,
|
|
||||||
s.non_digital_proof AS preuve_non_numerique,
|
|
||||||
s.comment_context AS comment_releve,
|
|
||||||
s.comment_description AS comment_occurrence,
|
|
||||||
ds.dataset_data AS jdd_data,
|
|
||||||
af.af_data AS ca_data,
|
|
||||||
s.reference_biblio,
|
|
||||||
s.cd_hab AS code_habitat,
|
|
||||||
h.lb_hab_fr AS habitat,
|
|
||||||
s.place_name AS nom_lieu,
|
|
||||||
s.precision,
|
|
||||||
s.additional_data AS donnees_additionnelles,
|
|
||||||
st_astext(s.the_geom_4326) AS wkt_4326,
|
|
||||||
n1.cd_nomenclature AS nature_objet_geo,
|
|
||||||
n2.cd_nomenclature AS type_regroupement,
|
|
||||||
s.grp_method AS methode_regroupement,
|
|
||||||
n3.cd_nomenclature AS comportement,
|
|
||||||
n4.cd_nomenclature AS technique_obs,
|
|
||||||
n5.cd_nomenclature AS statut_biologique,
|
|
||||||
n6.cd_nomenclature AS etat_biologique,
|
|
||||||
n7.cd_nomenclature AS naturalite,
|
|
||||||
n8.cd_nomenclature AS preuve_existante,
|
|
||||||
n9.cd_nomenclature AS precision_diffusion,
|
|
||||||
n10.cd_nomenclature AS stade_vie,
|
|
||||||
n11.cd_nomenclature AS sexe,
|
|
||||||
n12.cd_nomenclature AS objet_denombrement,
|
|
||||||
n13.cd_nomenclature AS type_denombrement,
|
|
||||||
n14.cd_nomenclature AS niveau_sensibilite,
|
|
||||||
n15.cd_nomenclature AS statut_observation,
|
|
||||||
n16.cd_nomenclature AS floutage_dee,
|
|
||||||
n17.cd_nomenclature AS statut_source,
|
|
||||||
n18.cd_nomenclature AS type_info_geo,
|
|
||||||
n19.cd_nomenclature AS methode_determination,
|
|
||||||
n20.cd_nomenclature AS statut_validation,
|
|
||||||
coalesce(s.meta_update_date, s.meta_create_date) AS derniere_action--, s.the_geom_local -- supprimé car bloque GN2PG
|
|
||||||
FROM gn_synthese.synthese s
|
|
||||||
JOIN taxonomie.taxref USING (cd_nom)
|
|
||||||
JOIN ds ON ds.id_dataset = s.id_dataset
|
|
||||||
JOIN af ON ds.id_acquisition_framework = af.id_acquisition_framework
|
|
||||||
LEFT JOIN ref_habitats.habref h ON h.cd_hab = s.cd_hab
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n1 ON s.id_nomenclature_geo_object_nature = n1.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n2 ON s.id_nomenclature_grp_typ = n2.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n3 ON s.id_nomenclature_behaviour = n3.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n4 ON s.id_nomenclature_obs_technique = n4.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n5 ON s.id_nomenclature_bio_status = n5.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n6 ON s.id_nomenclature_bio_condition = n6.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n7 ON s.id_nomenclature_naturalness = n7.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n8 ON s.id_nomenclature_exist_proof = n8.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n9 ON s.id_nomenclature_diffusion_level = n9.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n10 ON s.id_nomenclature_life_stage = n10.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n11 ON s.id_nomenclature_sex = n11.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n12 ON s.id_nomenclature_obj_count = n12.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n13 ON s.id_nomenclature_type_count = n13.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n14 ON s.id_nomenclature_sensitivity = n14.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n15 ON s.id_nomenclature_observation_status = n15.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n16 ON s.id_nomenclature_blurring = n16.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n17 ON s.id_nomenclature_source_status = n17.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n18 ON s.id_nomenclature_info_geo_type = n18.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n19 ON s.id_nomenclature_determination_method = n19.id_nomenclature
|
|
||||||
LEFT JOIN ref_nomenclatures.t_nomenclatures n20 ON s.id_nomenclature_valid_status = n20.id_nomenclature
|
|
||||||
|
|
||||||
WHERE (af.af_data#>>'{uuid}') = '97c05888-08f5-4a4b-a224-20c3263594ad'
|
|
||||||
AND (ds.dataset_data#>>'{uuid}') not in (
|
|
||||||
'7a29acae-757e-41d7-a0cf-a35c568a5db9',
|
|
||||||
'089a8dc1-3d50-4b2c-865c-d535a982446f' -- JDD : Expertise écologique - Label Golf pour la biodiversité
|
|
||||||
)
|
|
||||||
-- FIN
|
|
||||||
ORDER BY s.id_synthese;
|
|
||||||
'''
|
|
||||||
|
|
||||||
with con_gn.begin() as cnx:
|
|
||||||
cnx.execute(sql)
|
|
||||||
@ -1,60 +0,0 @@
|
|||||||
import pandas as pd
|
|
||||||
from os import path
|
|
||||||
from pycen import con_gn
|
|
||||||
|
|
||||||
# PARAMS
|
|
||||||
PATH = '/media/cgeier/SRV/FICHIERS/OUTILS/CARTOGRAPHIE/ESPACE DE TRAVAIL/SITES/Lone de la Negria/Faune-Flore/Données partenaires/1.Données nettoyées/Golf Club Lyon Faune Flore Oxalis 2021/'
|
|
||||||
file = 'Golf Club Lyon Faune Flore Oxalis 2021.csv'
|
|
||||||
|
|
||||||
# READ DATA
|
|
||||||
tax = pd.read_sql('SELECT * FROM taxonomie.taxref',con_gn)
|
|
||||||
df = pd.read_csv(path.join(PATH,file),index_col=0)
|
|
||||||
|
|
||||||
# MAKE DICTIONARY
|
|
||||||
dic_tax_comp = dict(zip(tax.nom_complet,tax.cd_ref.astype(str)))
|
|
||||||
dic_tax_vali = dict(zip(tax.nom_valide,tax.cd_ref.astype(str)))
|
|
||||||
dic_tax_lbno = dict(zip(tax.lb_nom,tax.cd_ref.astype(str)))
|
|
||||||
dic_tax_vern = dict(zip(tax.nom_vern,tax.cd_ref.astype(str)))
|
|
||||||
|
|
||||||
# MANIP DATA
|
|
||||||
df['cd_ref'] = df.NOMCITE.copy()
|
|
||||||
df.replace({'cd_ref':dic_tax_comp},inplace=True)
|
|
||||||
df.replace({'cd_ref':dic_tax_vali},inplace=True)
|
|
||||||
df.replace({'cd_ref':dic_tax_lbno},inplace=True)
|
|
||||||
df.replace({'cd_ref':dic_tax_vern},inplace=True)
|
|
||||||
|
|
||||||
df['tmp'] = df.COMMENT.str.lower().copy()
|
|
||||||
df.tmp.replace({
|
|
||||||
'â':'a',
|
|
||||||
'ê':'e'
|
|
||||||
}, regex=True)
|
|
||||||
|
|
||||||
df.loc[df.tmp.str.contains("mâle",na=False),'sexe'] = "Mâle"
|
|
||||||
df.loc[df.tmp.str.contains("adulte",na=False),'stade_vie'] = "Adulte"
|
|
||||||
df.loc[df.tmp.str.contains("imago",na=False),'stade_vie'] = "Imago"
|
|
||||||
df.loc[df.tmp.str.contains("larve",na=False),'stade_vie'] = "Larve"
|
|
||||||
df.loc[df.tmp.str.contains("tetard",na=False),'stade_vie'] = "Têtard"
|
|
||||||
df.loc[df.tmp.str.contains("immature",na=False),'stade_vie'] = "Immature"
|
|
||||||
df.loc[df.tmp.str.contains("flor",na=False),'stade_vie'] = "Fleur"
|
|
||||||
df.loc[df.tmp.str.contains("cris",na=False),'comportement'] = "Cris"
|
|
||||||
df.loc[df.tmp.str.contains("cht",na=False),'comportement'] = "Chant"
|
|
||||||
df.loc[df.tmp.str.contains("chant",na=False),'comportement'] = "Chant"
|
|
||||||
df.loc[df.tmp.str.contains("transit",na=False),'comportement'] = "Passage en vol"
|
|
||||||
df.loc[df.tmp.str.contains("vol",na=False),'comportement'] = "Passage en vol"
|
|
||||||
df.loc[df.tmp.str.contains("chasse",na=False),'comportement'] = "Chasse/alimentation"
|
|
||||||
df.loc[df.tmp.str.contains("andem",na=False),'comportement'] = "Tandem"
|
|
||||||
df.loc[df.tmp.str.contains("ponte",na=False),'obj_denombrement'] = "Ponte"
|
|
||||||
|
|
||||||
df.sexe.fillna('Non renseigné', inplace=True)
|
|
||||||
df.stade_vie.fillna('Inconnu', inplace=True)
|
|
||||||
df.comportement.fillna('Inconnu', inplace=True)
|
|
||||||
df.obj_denombrement.fillna('Individu', inplace=True)
|
|
||||||
|
|
||||||
df['typ_denombre'] = 'Compté'
|
|
||||||
df['etat_bio'] = 'Observé vivant'
|
|
||||||
df['tech_obs'] = 'Vu'
|
|
||||||
df['OBSE_NOMBR'] = df.OBSE_NOMBR.astype(int)
|
|
||||||
df.loc[~df.PRECISGEO.isna(),'precisgeo'] = df[~df.PRECISGEO.isna()].PRECISGEO.astype(int).astype(str)
|
|
||||||
|
|
||||||
del df['tmp']
|
|
||||||
df.to_csv(path.join(PATH,'Golf Club Lyon Faune Flore Oxalis 2021 (remanié).csv'))
|
|
||||||
@ -127,29 +127,7 @@ def resolve_missing_data(con):
|
|||||||
|
|
||||||
def resolve_synthese_errors(con):
|
def resolve_synthese_errors(con):
|
||||||
sql = '''
|
sql = '''
|
||||||
with t1 as (
|
|
||||||
SELECT
|
|
||||||
--tro.*,too.*
|
|
||||||
tro.unique_id_sinp_grp
|
|
||||||
FROM pr_occtax.t_occurrences_occtax AS too
|
|
||||||
JOIN pr_occtax.t_releves_occtax tro using (id_releve_occtax)
|
|
||||||
),t2 as (
|
|
||||||
select
|
|
||||||
s.id_synthese,
|
|
||||||
too.id_releve_occtax,
|
|
||||||
too.id_occurrence_occtax,
|
|
||||||
too.id_nomenclature_exist_proof
|
|
||||||
FROM pr_occtax.t_occurrences_occtax AS too
|
|
||||||
JOIN pr_occtax.t_releves_occtax tro using (id_releve_occtax)
|
|
||||||
JOIN pr_occtax.cor_counting_occtax cco using (id_occurrence_occtax)
|
|
||||||
JOIN gn_synthese.synthese s on s.unique_id_sinp = cco.unique_id_sinp_occtax
|
|
||||||
WHERE tro.unique_id_sinp_grp IN (SELECT t1.unique_id_sinp_grp FROM t1)
|
|
||||||
AND (too.nom_cite != s.nom_cite)
|
|
||||||
)
|
|
||||||
UPDATE pr_occtax.t_occurrences_occtax too
|
|
||||||
SET id_nomenclature_exist_proof = t2.id_nomenclature_exist_proof
|
|
||||||
FROM t2
|
|
||||||
WHERE too.id_occurrence_occtax = t2.id_occurrence_occtax;
|
|
||||||
'''
|
'''
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@ -1,49 +0,0 @@
|
|||||||
from pycen import con_fon, con_gn
|
|
||||||
import geopandas as gpd
|
|
||||||
|
|
||||||
zh = gpd.read_postgis('SELECT * FROM gn_exports.v_synthese_zh_rhomeosite', con_gn)
|
|
||||||
|
|
||||||
_ens = gpd.read_postgis('SELECT * FROM sites.sites', con_fon,geom_col='geom')
|
|
||||||
_ens.sort_values('site_id',inplace=True)
|
|
||||||
_ens.site_id = _ens.site_id.str.replace('_ZI','')
|
|
||||||
site = gpd.read_postgis('SELECT * FROM _tdbfcen.vm_sites_cen_2026_shp',con_fon)
|
|
||||||
site['area_mastery'] = site.area / 10000
|
|
||||||
|
|
||||||
|
|
||||||
ens = _ens[_ens.site_id.isin(site.id_site_cen.tolist())]
|
|
||||||
# ens = gpd.pd.concat([ens,_ens[(_ens.site_id.str.strip('_ZO').isin(site[~site.id_site_cen.isin(ens.site_id)].id_site_cen.tolist()))]])
|
|
||||||
# ens.site_id = ens.site_id.str.strip('_ZO')
|
|
||||||
ens['area_total'] = ens.area / 10000
|
|
||||||
zh_over_ens = zh.overlay(ens).dissolve('site_id')
|
|
||||||
zh_over_ens['area_zh_total'] = zh_over_ens.area / 10000
|
|
||||||
zh_over_ens.to_file('/home/cgeier/Téléchargements/foret_sitecen/overlay_ens_zh.geojson',driver='GeoJSON')
|
|
||||||
|
|
||||||
foret = gpd.read_file('/home/cgeier/Téléchargements/foret_sitecen/ign_masque_foret.geojson')
|
|
||||||
over = foret.overlay(site).dissolve('id_site_cen')
|
|
||||||
over['area_forest_master'] = over.area / 10000
|
|
||||||
over.to_file('/home/cgeier/Téléchargements/foret_sitecen/overlay_sites_foret.geojson',driver='GeoJSON')
|
|
||||||
|
|
||||||
peup = gpd.read_file('/home/cgeier/Téléchargements/foret_sitecen/peuplier_onsites.geojson')
|
|
||||||
p_over = peup.overlay(site).dissolve('id_site_cen')
|
|
||||||
p_over['area_peuplier_master'] = p_over.area / 10000
|
|
||||||
p_over.to_file('/home/cgeier/Téléchargements/foret_sitecen/overlay_sites_peupleraie.geojson',driver='GeoJSON')
|
|
||||||
|
|
||||||
zh_over = zh.overlay(site).dissolve('id_site_cen')
|
|
||||||
zh_over['area_zh_master'] = zh_over.area / 10000
|
|
||||||
zh_over.to_file('/home/cgeier/Téléchargements/foret_sitecen/overlay_site_maitrise_zh.geojson',driver='GeoJSON')
|
|
||||||
|
|
||||||
df = (
|
|
||||||
ens[['site_id','site_nom','geom','area_total']]
|
|
||||||
.merge(over[['area_mastery','area_forest_master']].reset_index(drop=False), how='left', right_on='id_site_cen',left_on='site_id')
|
|
||||||
.drop(columns='id_site_cen')
|
|
||||||
.merge(p_over[['area_peuplier_master']].reset_index(drop=False), how='left', right_on='id_site_cen',left_on='site_id')
|
|
||||||
.drop(columns='id_site_cen')
|
|
||||||
.merge(zh_over_ens[['area_zh_total']].reset_index(drop=False), on='site_id', how='left')
|
|
||||||
.merge(zh_over[['area_zh_master']].reset_index(drop=False), how='left', right_on='id_site_cen',left_on='site_id')
|
|
||||||
.drop(columns='id_site_cen')
|
|
||||||
.sort_values('site_id')
|
|
||||||
.fillna(0)
|
|
||||||
)
|
|
||||||
df = df[~df.site_id.isin(['CACH','N2GL','N2IP','RNGL','RNIP','NDDM'])]
|
|
||||||
|
|
||||||
df.to_file('/home/cgeier/Téléchargements/foret_sitecen/sites_foret.geojson',driver='GeoJSON')
|
|
||||||
Loading…
x
Reference in New Issue
Block a user