【问题标题】:Load table with GEOMETRY column to Pandas DataFrame将带有 GEOMETRY 列的表加载到 Pandas DataFrame
【发布时间】:2019-12-16 20:53:50
【问题描述】:

我正在尝试使用 pd.read_sql_table 方法将带有 GEOMETRY 列的表(来自 Postgres DB)加载到 Pandas DataFrame。我收到错误,因为 GEOMETRY 类型似乎不受支持:

C:\Anaconda3\lib\site-packages\sqlalchemy\dialects\postgresql\base.py:3010: SAWarning: 未识别列 'geometry' 的类型 'geometry' “未识别类型 '% '%s' 列的 s'" % (attype, name)

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

【问题讨论】:

    标签: python python-3.x pandas gis


    【解决方案1】:

    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)
    

    【讨论】:

      猜你喜欢
      • 2021-05-21
      • 2019-05-24
      • 2016-03-25
      • 2020-12-28
      • 2019-07-06
      • 1970-01-01
      • 2013-10-06
      • 2021-01-16
      相关资源
      最近更新 更多