[CG] add zh ponctuelles
This commit is contained in:
parent
1e1796bbff
commit
aa5bbee227
197
pycen/zh.py
197
pycen/zh.py
@ -19,196 +19,6 @@ from .sites.sites import _get_typ_milieux
|
||||
from .tools import _get_relation_autor2, _get_table
|
||||
|
||||
|
||||
#####################################
|
||||
### schema personnes ###
|
||||
#####################################
|
||||
# class pers:
|
||||
# def __init__(self):
|
||||
# from .params import con
|
||||
# self.schema = 'personnes'
|
||||
# self.con = con
|
||||
# # self._get_table = _get_table
|
||||
|
||||
# def get_auteur(self, nom=None, prenom=None):
|
||||
# sql = 'SELECT * FROM %s.personne'%self.schema
|
||||
# if nom or prenom : sql = sql + ' WHERE '
|
||||
# if nom :
|
||||
# sql = sql + 'nom IN %(nom)s'
|
||||
# nom = to_upper(nom)
|
||||
# if nom and prenom : sql = sql + ' AND '
|
||||
# if prenom :
|
||||
# sql = sql + 'prenom IN %(prenom)s'
|
||||
# prenom = to_upperfirst(prenom)
|
||||
# df = pd.read_sql(
|
||||
# sql = sql,
|
||||
# con = self.con,
|
||||
# params = {'nom': to_tuple(nom), 'prenom': to_tuple(prenom) })
|
||||
# return df
|
||||
|
||||
# def get_organisme(self, ids=None, nom=None):
|
||||
# table = 'organisme'
|
||||
# return _get_table(self.con, self.schema, table, ids=ids, nom=nom)
|
||||
|
||||
#####################################
|
||||
### schema sites ###
|
||||
#####################################
|
||||
# class sites:
|
||||
# def __init__(self):
|
||||
# from .params import con
|
||||
# from .pers import pers
|
||||
# self.schema = 'sites'
|
||||
# self.con = con
|
||||
# self.typ_milieux = self._get_typ_milieux()
|
||||
# self.typo_sdage = self._get_typo_sdage()
|
||||
# self.typ_site = self._get_typ_site()
|
||||
# self.auteur = pers.get_auteur()
|
||||
# self.organisme = pers.get_organisme()
|
||||
|
||||
# def _get_typ_milieux(self, ids=None, nom=None):
|
||||
# table = 'type_milieu'
|
||||
# df = _get_table(self.con, self.schema, table, ids=ids, nom=nom)
|
||||
# return df
|
||||
|
||||
# def _get_typo_sdage(self, ids=None, nom=None):
|
||||
# table = 'typo_sdage'
|
||||
# df = _get_table(self.con, self.schema, table, ids=ids, nom=nom)
|
||||
# return df
|
||||
|
||||
# def _get_typ_site(self, ids=None, nom=None):
|
||||
# table = 'type_site'
|
||||
# df = _get_table(self.con, self.schema, table, ids=ids, nom=nom)
|
||||
# return df
|
||||
|
||||
# def _merge_orga(self, df, split_cols):
|
||||
# org = self.organisme
|
||||
# aut = self.auteur
|
||||
# df = df.copy()
|
||||
# for c in split_cols:
|
||||
# if not isinstance(df[c], int): df[c] = df[c].astype(float)
|
||||
# df[c].replace(aut.id.tolist(), aut.id_organisme.tolist(), inplace=True)
|
||||
# df[c].replace(org.id.tolist(), org.nom.tolist(), inplace=True)
|
||||
# df['organisme'] = None
|
||||
# for c in split_cols:
|
||||
# df.loc[df.organisme.isna(), 'organisme'] = df.loc[df['organisme'].isna(), c]
|
||||
# for c in split_cols:
|
||||
# comp = df.loc[~df[c].isna(),'organisme'].compare(df.loc[~df[c].isna(), c])
|
||||
# if not comp.empty:
|
||||
# comp['test'] = comp.apply(lambda x: x['other'] in x['self'], axis=1)
|
||||
# comp = comp[~comp.test]
|
||||
# if not comp.empty:
|
||||
# df.loc[comp.index,'organisme'] = comp.self + ' & ' + comp.other
|
||||
# df.drop(columns=split_cols, inplace=True)
|
||||
# return df
|
||||
|
||||
# def _merge_author(self, df, col_aut, orga=False):
|
||||
# # récupération des auteurs
|
||||
# aut = self.auteur.fillna('')
|
||||
# aut['nom_prenom'] = (aut['nom'] + ' ' + aut['prenom']).str.strip()
|
||||
# aut['id'] = aut['id'].astype(str)
|
||||
# # merge des auteurs
|
||||
# r_id = df[['id', col_aut]].copy()
|
||||
# r_idSplit = r_id[col_aut].str.split(' & ', expand=True)
|
||||
# r_id = r_id.join(r_idSplit)
|
||||
# cSplit = r_idSplit.shape[1]
|
||||
# cSplit = list(range(cSplit))
|
||||
# if orga:
|
||||
# # récup des organismes
|
||||
# org = self._merge_orga(r_id, cSplit)
|
||||
# r_id[cSplit] = r_id[cSplit].replace(aut['id'].tolist(),aut['nom_prenom'].tolist())
|
||||
# r_id = _aggr_cols(r_id,cSplit,' & ') \
|
||||
# .rename(columns={'aggreg': 'auteur'}) \
|
||||
# .drop(columns=cSplit)
|
||||
# if orga:
|
||||
# # merge des organismes
|
||||
# r_id = pd.merge(r_id,org, on=['id', col_aut])
|
||||
# df = pd.merge(df,r_id, on=['id', col_aut]) \
|
||||
# .drop(columns=[col_aut])
|
||||
# return df
|
||||
|
||||
# def _merge_relation(self, df, table, schema, id=None, left_id=None,right_id=None):
|
||||
# con = self.con
|
||||
# if id:
|
||||
# params = {id: df[id].tolist() }
|
||||
# elif left_id and right_id:
|
||||
# params = {right_id: df[left_id].tolist() }
|
||||
# mrg = _get_table(con, schema, table, params_col=params)
|
||||
# if table == 'r_sites_auteur' or table == 'r_geomsites_auteur':
|
||||
# mrg = mrg[[right_id,'id_auteur']].groupby(
|
||||
# [right_id])['id_auteur'].apply(lambda x: ' & '.join(x.astype(str)))
|
||||
# mrg = pd.DataFrame(data=mrg)
|
||||
# if id:
|
||||
# df = pd.merge(df,mrg, how='left', on=id)
|
||||
# elif left_id and right_id:
|
||||
# df = pd.merge(df,mrg, how='left', left_on=left_id, right_on=right_id)
|
||||
# return df
|
||||
|
||||
|
||||
# def get_sitesInfos(self, ids=None, nom=None, columns=None, with_nameOrga=False, details=False, params_col={}):
|
||||
# drop = []
|
||||
# table = 'sites'
|
||||
# df = _get_table(self.con, self.schema, table, ids=ids, nom=nom, cols=columns, params_col=params_col)
|
||||
# # récupération des auteurs
|
||||
# if 'id_auteur' in df.columns:
|
||||
# df.drop(columns='id_auteur', inplace=True)
|
||||
# df = _merge_relation(df=df,table='r_sites_auteur',schema=self.schema, left_id='id',right_id='id_site')
|
||||
# df = _merge_author(df=df, col_aut='id_auteur', orga=with_nameOrga)
|
||||
# # merge type_site
|
||||
# if 'id_type_site' in df.columns:
|
||||
# df = pd.merge(df, self.typ_site, how='left', left_on='id_type_site', right_on='id', suffixes=('','_y') ) \
|
||||
# .drop(columns=['id_type_site', 'id_y']) \
|
||||
# .rename(columns={'nom_y': 'type_site', 'description': 'desc_type_site'})
|
||||
# drop += ['desc_type_site']
|
||||
# # merge typo_sdage
|
||||
# if 'id_typo_sdage' in df.columns:
|
||||
# df = pd.merge(df, self.typo_sdage, how='left', left_on='id_typo_sdage', right_on='id', suffixes=('','_y') ) \
|
||||
# .drop(columns=['id_typo_sdage', 'id_y']) \
|
||||
# .rename(columns={'nom_y': 'typo_sdage', 'description': 'desc_typo_sdage'})
|
||||
# drop += ['desc_typo_sdage']
|
||||
# # merge type_milieu
|
||||
# if 'id_type_milieu' in df.columns:
|
||||
# df = pd.merge(df, self.typ_milieux, how='left', left_on='id_type_milieu', right_on='id', suffixes=('','_y') ) \
|
||||
# .drop(columns=['id_type_milieu', 'id_y']) \
|
||||
# .rename(columns={'nom_y': 'type_milieu', 'description': 'desc_type_milieu', 'nom_court': 'nom_court_milieu'})
|
||||
# drop += ['desc_type_milieu', 'nom_court_milieu']
|
||||
|
||||
# if not details:
|
||||
# df.drop(columns=drop, inplace=True)
|
||||
|
||||
# return df.sort_values('id')
|
||||
|
||||
# def get_sitesGeom(self, id_site=None, nom_site=None, columns=None, last_update=False, with_nameOrga=False, params_col={}):
|
||||
# # from shapely.wkb import loads
|
||||
# # import geopandas as gpd # set_geometry
|
||||
|
||||
# if columns:
|
||||
# if not isinstance(columns, list): columns = [columns]
|
||||
# if 'id' not in columns: columns.insert(0,'id')
|
||||
# if 'id_site' not in columns: columns.insert(1,'id_site')
|
||||
# if 'geom' not in columns: columns.insert(2,'geom')
|
||||
|
||||
# table = 'sites'
|
||||
# df = _get_table(self.con, self.schema, table, ids=id_site, nom=nom_site, cols='id', params_col=params_col)
|
||||
# idSite = df.id.tolist()
|
||||
# table = 'r_sites_geom'
|
||||
# df = _get_table(self.con, self.schema, table, params_col={'id_site':idSite}, cols=columns)
|
||||
# if last_update:
|
||||
# df.drop_duplicates(subset=['id_site'], keep='last', inplace=True)
|
||||
# df.reset_index(inplace=True, drop=True)
|
||||
|
||||
|
||||
# # df = _set_geom(df)
|
||||
# # df['geom'] = [(loads(geom, hex=True)) for geom in df['geom']]
|
||||
# # df = df.set_geometry('geom', crs='EPSG:2154')
|
||||
# # merge auteur
|
||||
# if 'id_auteur' in df.columns:
|
||||
# df.drop(columns='id_auteur', inplace=True)
|
||||
# df = _merge_relation(df=df,table='r_geomsites_auteur',schema=self.schema, left_id='id',right_id='id_geom_site')
|
||||
# df = _merge_author(df=df, col_aut='id_auteur', orga=with_nameOrga)
|
||||
|
||||
# return df
|
||||
|
||||
|
||||
|
||||
#####################################
|
||||
### schema zh ###
|
||||
#####################################
|
||||
@ -234,7 +44,12 @@ class zh:
|
||||
|
||||
def v_zoneshumides(self,ids=None,columns=None, params_col={}):
|
||||
return _get_table(self.con,self.schema,'v_zoneshumides',ids=ids,cols=columns,params_col=params_col)
|
||||
|
||||
|
||||
def zh_ponctuelles(self,ids=None,columns=None, params_col={}):
|
||||
return _get_table(self.con,self.schema,'zh_ponctuelles',ids=ids,cols=columns,params_col=params_col)
|
||||
|
||||
def zh_ponctuelles_in_zh(self,ids=None,columns=None, params_col={}):
|
||||
return _get_table(self.con,self.schema,'zh_ponctuelles_in_zh',ids=ids,cols=columns,params_col=params_col)
|
||||
|
||||
def v_rhomeosite(self,ids=None,columns=None, params_col={}):
|
||||
return _get_table(self.con,self.schema,'v_rhomeosite',ids=ids,cols=columns,params_col=params_col)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user