[CG] : add read layer
This commit is contained in:
parent
aadf7313b6
commit
a3f9289e5c
@ -152,6 +152,35 @@ def _set_geom(df, hex=True, crs=2154):
|
||||
|
||||
return df
|
||||
|
||||
def _get_layer(table,con,schema,columns:list=None,args:None=None,bbox:None=None):
|
||||
import geopandas as gpd
|
||||
sql = '''
|
||||
SELECT {cols} FROM {sch}.{tab} t
|
||||
'''.format(
|
||||
cols = ','.join(columns) if columns else '*',
|
||||
sch=schema,
|
||||
tab=table)
|
||||
if args or bbox:
|
||||
sql += ' WHERE '
|
||||
if args :
|
||||
w = []
|
||||
for a in args:
|
||||
w.append('{col} {sym} {val}'.format(
|
||||
col = 't.'+a,
|
||||
sym = '=' if isinstance(args[a],str) else 'IN',
|
||||
val = "'"+args[a]+"'" if isinstance(args[a],str) else tuple(args[a])
|
||||
))
|
||||
b = []
|
||||
if bbox :
|
||||
b = ['''
|
||||
ST_INTERSECTS(t.geom,'SRID={epsg};{poly}')
|
||||
'''.format(
|
||||
epsg = 2154,
|
||||
poly = bbox,
|
||||
)]
|
||||
sql += ' AND '.join([*w,*b])
|
||||
return gpd.read_postgis(sql,con)
|
||||
|
||||
|
||||
|
||||
def _get_param(schema, param_table, type_table=None, type_court=True):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user