将带有 GEOMETRY 列的 table 加载到 Pandas DataFrame

Load table with GEOMETRY column to Pandas DataFrame

我正在尝试使用 pd.read_sql_table 方法将带有 GEOMETRY 列的 table(从 Postgres 数据库)加载到 Pandas DataFrame。我收到错误消息,因为似乎不支持 GEOMETRY 类型:

C:\Anaconda3\lib\site-packages\sqlalchemy\dialects\postgresql\base.py:3010: SAWarning: 无法识别列 'geometry' 的类型 'geometry' "Did not recognize type '%s' of column '%s'" % (attype, name )

有谁知道如何将此类数据加载到 Pandas df?在 Pandas "read_sql_table" 的文档页面上,我没有看到定义列数据类型的选项。

just GeoPandas ,安装它

git clone https://github.com/geopandas/geopandas.git
cd geopandas
pip install .

也可以直接从 GitHub 存储库安装最新的开发版本:

pip install git+git://github.com/geopandas/geopandas.git

对于从源代码安装 GeoPandas,同样需要正确安装所有依赖项。但是,这些依赖项也可以在从源代码安装 GeoPandas 之前使用 conda 独立安装:

conda install pandas fiona shapely pyproj rtree

并像这样使用 from_postgis 方法:

import geopandas as gpd
sql = "SELECT ST_asBinary(geom) AS geom, highway FROM roads"
df = gpd.GeoDataFrame.from_postgis(sql, con)