from geoalchemy2 import Geometry import geopandas as gpd from sqlalchemy import create_engine user_cad = 'cgeier' # utilisateur de connexion à la bdd pwd_cad = 'adm1n*bdCen' # mot de passe de la bdd adr_cad = '91.134.194.221' # adresse ip de la bdd port_cad = '5432' # port de la bdd base_cad = 'rhomeo' # nom de la bdd schema_cad = 'refgeo' con = create_engine('postgresql+psycopg2://{0}:{1}@{2}:{3}/{4}'.format(user_cad,pwd_cad,adr_cad,port_cad,base_cad), echo=False) file = '/home/colas/Documents/5_BDD/BASSIN_VERSANT/AGENCE EAU/bvmdo/bvmdo.shp' df = gpd.read_file(file) df.rename_geometry('geom', inplace=True) has_z = True if df.has_z.all() else False unique_geom = df.geom_type.unique() geom_type = df.geom_type[0].upper() if len(unique_geom) == 1 else 'GEOMETRY' geom_type = geom_type+'Z'if has_z else geom_type (df .to_wkt() .to_sql( 'zh', con, schema_cad, if_exists='append', index=False, dtype={ 'geom':Geometry(geometry_type=geom_type,srid=2154) } ) ) sql = 'SELECT * FROM tachenew.tache_urbaine' sql = 'SELECT * FROM arvfnew.arvf_global_buffer' df = gpd.read_postgis(sql,con)