/usr/lib/python3/dist-packages/geopandas/io/sql.py is in python3-geopandas 0.1.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import binascii
from pandas import read_sql
import shapely.wkb
from geopandas import GeoSeries, GeoDataFrame
def read_postgis(sql, con, geom_col='geom', crs=None, index_col=None,
coerce_float=True, params=None):
"""
Returns a GeoDataFrame corresponding to the result of the query
string, which must contain a geometry column.
Examples:
sql = "SELECT geom, kind FROM polygons;"
df = geopandas.read_postgis(sql, con)
Parameters
----------
sql: string
con: DB connection object or SQLAlchemy engine
geom_col: string, default 'geom'
column name to convert to shapely geometries
crs: optional
CRS to use for the returned GeoDataFrame
See the documentation for pandas.read_sql for further explanation
of the following parameters:
index_col, coerce_float, params
"""
df = read_sql(sql, con, index_col=index_col, coerce_float=coerce_float,
params=params)
if geom_col not in df:
raise ValueError("Query missing geometry column '{0}'".format(
geom_col))
wkb_geoms = df[geom_col]
s = wkb_geoms.apply(lambda x: shapely.wkb.loads(binascii.unhexlify(x.encode())))
df[geom_col] = GeoSeries(s)
return GeoDataFrame(df, crs=crs, geometry=geom_col)
|