Compare commits
No commits in common. "79625741366070cc904c5e3909047aa69c4a3c45" and "a3f9289e5cefcddcb3ee656410fd6d9145fc573b" have entirely different histories.
7962574136
...
a3f9289e5c
@ -8,7 +8,7 @@ from .pers import pers
|
||||
from .sites import sites
|
||||
from .ps import *
|
||||
from .ref import *
|
||||
from .params import con,con_sicen,con_bdcen,con_fon,con_gn,con_cad,con_rho
|
||||
from .params import con,con_sicen,con_bdcen,con_fon,con_gn
|
||||
|
||||
|
||||
|
||||
|
||||
@ -7,29 +7,13 @@ from sqlalchemy.engine import URL
|
||||
isin_bdd = True
|
||||
# Parametres bdd CEN38 OUT
|
||||
user = 'xxxxxx'
|
||||
pwd = 'xxxxxx'
|
||||
pwd = "xxxxxx"
|
||||
adr = 'xxxxxx'
|
||||
base = 'azalee'
|
||||
url = URL.create("postgresql+psycopg2", username=user, password=pwd, host=adr, database=base)
|
||||
con = create_engine(url)
|
||||
# con = create_engine('postgresql+psycopg2://{0}:{1}@{2}/{3}'.format(user,pwd,adr,base), echo=False)
|
||||
|
||||
# Parametres bdd CADASTRE
|
||||
cad_user = 'xxxxxx'
|
||||
cad_pwd = 'xxxxxx'
|
||||
cad_adr = 'xxxxxx'
|
||||
cad_base = 'cadastre'
|
||||
cad_url = URL.create("postgresql+psycopg2", username=cad_user, password=cad_pwd, host=cad_adr, database=cad_base)
|
||||
con_cad = create_engine(cad_url)
|
||||
|
||||
# Parametres bdd RHOMEO
|
||||
rho_user = 'xxxxxx'
|
||||
rho_pwd = 'xxxxxx'
|
||||
rho_adr = 'xxxxxx'
|
||||
rho_base = 'rhomeo'
|
||||
rho_url = URL.create("postgresql+psycopg2", username=cad_user, password=cad_pwd, host=cad_adr, database=cad_base)
|
||||
con_rho = create_engine(rho_url)
|
||||
|
||||
# Parametres bdd SICEN OUT
|
||||
sicen_user = 'xxxxxx'
|
||||
sicen_pwd = 'xxxxxx'
|
||||
|
||||
@ -1,13 +1,4 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
from .territoire import (
|
||||
comcom_syndicat,
|
||||
get_districtNat,
|
||||
sdr_ressources_en_eau,
|
||||
dept_isere,
|
||||
ref_biogeo,
|
||||
rpg2021_reg_ilot,
|
||||
rpg2021_reg_parc,
|
||||
rpg2021_dep_ilot,
|
||||
rpg2021_dep_parc)
|
||||
from .territoire import get_districtNat
|
||||
@ -3,33 +3,9 @@
|
||||
|
||||
|
||||
from ...params import con
|
||||
from ...tools import _get_table, _get_layer
|
||||
from ...tools import _get_table
|
||||
schema = 'ref_territoire'
|
||||
|
||||
|
||||
def comcom_syndicat():
|
||||
return _get_table(con,schema,'comcom_syndicat')
|
||||
|
||||
def get_districtNat():
|
||||
return _get_table(con,schema,'districts_naturels')
|
||||
|
||||
def sdr_ressources_en_eau():
|
||||
return _get_table(con,schema,'sdr_ressources_en_eau')
|
||||
|
||||
def dept_isere():
|
||||
return _get_table(con,schema,'dept_isere')
|
||||
|
||||
def ref_biogeo():
|
||||
return _get_table(con,schema,'ref_biogeo')
|
||||
|
||||
def rpg2021_reg_ilot():
|
||||
return _get_table(con,schema,'rpg2020_ilots_anonymes_reg')
|
||||
|
||||
def rpg2021_reg_parc():
|
||||
return _get_table(con,schema,'rpg2020_parcelles_graphiques_reg')
|
||||
|
||||
def rpg2021_dep_ilot():
|
||||
return _get_table(con,schema,'v_rpg2021_ilots_anonymes_isere')
|
||||
|
||||
def rpg2021_dep_parc(columns:list=None,args:None=None,bbox:None=None):
|
||||
return _get_layer('v_rpg2021_parcelles_graphiques_isere',con,schema,columns,args,bbox)
|
||||
return _get_table(con,schema,'districts_naturels')
|
||||
@ -32,7 +32,6 @@ def _get_typ_milieux(ids=None, nom=None):
|
||||
def _get_typo_sdage(ids=None, nom=None):
|
||||
table = 'typo_sdage'
|
||||
df = _get_table(con, schema, table, ids=ids, nom=nom)
|
||||
df['libelle'] = df['id'] + ' - ' + df['nom']
|
||||
return df
|
||||
|
||||
def _get_typ_site(ids=None, nom=None):
|
||||
@ -79,7 +78,7 @@ def get_sitesInfos(ids=None, nom=None, columns=None, with_nameOrga=False, detail
|
||||
if 'id_typo_sdage' in df.columns:
|
||||
df = merge(df, 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','libelle':'lib_typo_sdage'})
|
||||
.rename(columns={'nom_y': 'typo_sdage', 'description': 'desc_typo_sdage'})
|
||||
drop += ['desc_typo_sdage']
|
||||
# merge type_milieu
|
||||
if 'id_type_milieu' in df.columns:
|
||||
@ -134,10 +133,10 @@ def get_sitesGeom(id_site=None, nom_site=None, columns=None, last_update=False,
|
||||
|
||||
return df
|
||||
|
||||
# def new_site(df):
|
||||
# from ..tools.sites import tab_sites
|
||||
# final_col = [col['name'] for col in columns_sitetab]
|
||||
# aut = df['auteur']
|
||||
def new_site(df):
|
||||
from ..tools.sites import tab_sites
|
||||
final_col = [col['name'] for col in columns_sitetab]
|
||||
aut = df['auteur']
|
||||
|
||||
|
||||
|
||||
|
||||
@ -179,7 +179,7 @@ def _get_layer(table,con,schema,columns:list=None,args:None=None,bbox:None=None)
|
||||
poly = bbox,
|
||||
)]
|
||||
sql += ' AND '.join([*w,*b])
|
||||
return gpd.read_postgis(sql,con)
|
||||
return gpd.read_postgis(sql,con)
|
||||
|
||||
|
||||
|
||||
@ -436,7 +436,6 @@ def Polygons_to_MultiPolygon(df,geom_col=None):
|
||||
df.sort_index(inplace=True)
|
||||
return df
|
||||
|
||||
|
||||
def dump_bd(host,bd_name, user):
|
||||
from os import system
|
||||
from datetime import datetime as dt
|
||||
|
||||
@ -3,10 +3,10 @@
|
||||
|
||||
from owslib.wfs import WebFeatureService
|
||||
|
||||
def get_wfs(url, layer, version:str='1.0.0', bbox=None):
|
||||
def get_wfs(url, layer, bbox=None):
|
||||
from geopandas import read_file
|
||||
from requests import Request
|
||||
wfs = WebFeatureService(url=url,version=version,)
|
||||
wfs = WebFeatureService(url=url)
|
||||
item = dict(wfs.items())[layer]
|
||||
crs = item.crsOptions[0].getcode()
|
||||
params = dict(service='WFS', version=wfs.version, request='GetFeature',
|
||||
@ -18,7 +18,7 @@ def get_wfs(url, layer, version:str='1.0.0', bbox=None):
|
||||
data.to_crs(epsg=2154, inplace=True)
|
||||
return data
|
||||
|
||||
def list_layer(url,version:str='1.0.0'):
|
||||
wfs = WebFeatureService(url=url,version=version)
|
||||
def list_layer(url):
|
||||
wfs = WebFeatureService(url=url)
|
||||
lst = list(wfs.contents)
|
||||
return lst
|
||||
199
pycen/zh.py
199
pycen/zh.py
@ -19,6 +19,196 @@ 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 ###
|
||||
#####################################
|
||||
@ -41,18 +231,15 @@ class zh:
|
||||
self.columns_r_SiteSub = con.dialect.get_columns(con,schema=self.schema,table_name='r_site_sub')
|
||||
self.columns_r_SiteUsgPrss = con.dialect.get_columns(con,schema=self.schema,table_name='r_site_usageprocess')
|
||||
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def _get_param(self, param_table, type_table=None, type_court=True):
|
||||
if type_table:
|
||||
typ = _get_table(self.con, self.schema, table=type_table)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user