Commit 1403020b authored by ARCHER's avatar ARCHER

deprecated (not needed) : add_postgis(gpd)

parent df0bfbe0
......@@ -11,13 +11,14 @@ from sqlalchemy.sql import except_all
import csv
from io import StringIO
import pandas as pd
import geopandas as gpd
import os
import logging
logging.basicConfig()
logger = logging.getLogger(os.path.basename(__file__))
logger.setLevel(logging.ERROR)
logger.setLevel(logging.WARNING)
logging.getLogger('sqlalchemy.dialects.postgresql').setLevel(logging.ERROR)
shapely_handled_types=[
......@@ -326,7 +327,7 @@ def to_postgis(gdf,*args,**kwargs):
try:
column_srid=int(con.execute('''SELECT Find_SRID('', '%s', '%s');''' % (table , geom_col)).fetchone()[0])
except:
logger.warning('no column srid on existing %s.%s assuming 0' % (table, geom_col))
logger.info('no column srid on existing %s.%s assuming 0' % (table, geom_col))
column_srid=0
trans.rollback()
......@@ -358,22 +359,23 @@ def to_postgis(gdf,*args,**kwargs):
def add_postgis(gpd):
# psycopg2 adapter for shapely.geometry object
def shapelyAdapter(shapely_geo):
# need to use wkt representation ( pycopg2 fail with wkb :
# sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedFunction) function st_geogfromtext(bytea) does not exist
return AsIs(adapt(shapely_geo.wkt))
for Shapely_geo in shapely_handled_types:
register_adapter(Shapely_geo,shapelyAdapter)
logger.warning('add_postgis is deprecated and not needed')
# psycopg2 adapter for shapely.geometry object
def shapelyAdapter(shapely_geo):
# need to use wkt representation ( pycopg2 fail with wkb :
# sqlalchemy.exc.ProgrammingError: (psycopg2.errors.UndefinedFunction) function st_geogfromtext(bytea) does not exist
return AsIs(adapt(shapely_geo.wkt))
for Shapely_geo in shapely_handled_types:
register_adapter(Shapely_geo,shapelyAdapter)
gpd.GeoDataFrame.to_postgis=to_postgis
gpd.GeoDataFrame.to_sql_legacy = gpd.GeoDataFrame.to_sql
gpd.GeoDataFrame.to_sql = to_sql
gpd.GeoDataFrame.get_all_geometry_names = get_all_geometry_names
gpd.GeoDataFrame.to_postgis=to_postgis
gpd.GeoDataFrame.to_sql_legacy = gpd.GeoDataFrame.to_sql
gpd.GeoDataFrame.to_sql = to_sql
gpd.GeoDataFrame.get_all_geometry_names = get_all_geometry_names
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment