geopandas.read_postgis¶
- geopandas.read_postgis(sql, con, geom_col='geom', crs=None, index_col=None, coerce_float=True, parse_dates=None, params=None, chunksize=None)¶
Returns a GeoDataFrame corresponding to the result of the query string, which must contain a geometry column in WKB representation.
- Parameters
- sqlstring
SQL query to execute in selecting entries from database, or name of the table to read from the database.
- consqlalchemy.engine.Connection or sqlalchemy.engine.Engine
Active connection to the database to query.
- geom_colstring, default ‘geom’
column name to convert to shapely geometries
- crsdict or str, optional
CRS to use for the returned GeoDataFrame; if not set, tries to determine CRS from the SRID associated with the first geometry in the database, and assigns that to all geometries.
- chunksizeint, default None
If specified, return an iterator where chunksize is the number of rows to include in each chunk.
- See the documentation for pandas.read_sql for further explanation
- of the following parameters:
- index_col, coerce_float, parse_dates, params, chunksize
- Returns
- GeoDataFrame
Examples
PostGIS
>>> from sqlalchemy import create_engine >>> db_connection_url = "postgresql://myusername:mypassword@myhost:5432/mydatabase" >>> con = create_engine(db_connection_url) >>> sql = "SELECT geom, highway FROM roads" >>> df = geopandas.read_postgis(sql, con)
SpatiaLite
>>> sql = "SELECT ST_Binary(geom) AS geom, highway FROM roads" >>> df = geopandas.read_postgis(sql, con)