2

我正在尝试将 PostGIS 表中的列读入 GeoDataFrame 并遇到以下问题:

df = geo.GeoDataFrame.from_postgis("select geom __geometry__, id 
from hist_line limit 5",con, geom_col='__geometry__')

Traceback (most recent call last):
  File "/Users/stephen/anaconda/lib/python2.7/site-    packages/IPython/core/interactiveshell.py", line 3066, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-137-0f8eeafc0543>", line 1, in <module>
    df9 = geo.GeoDataFrame.from_postgis("select geom as __geometry__, id     from hist_line limit 5",con, geom_col='__geometry__')
  File "/Users/stephen/anaconda/lib/python2.7/site-    packages/geopandas/geodataframe.py", line 201, in from_postgis
coerce_float, params)
  File "/Users/stephen/anaconda/lib/python2.7/site-packages/geopandas/io/sql.py", line 42, in read_postgis
    s = wkb_geoms.apply(lambda x: shapely.wkb.loads(binascii.unhexlify(x.encode())))
  File "/Users/stephen/anaconda/lib/python2.7/site-    packages/pandas/core/series.py", line 2169, in apply
    mapped = lib.map_infer(values, f, convert=convert_dtype)
  File "pandas/src/inference.pyx", line 1059, in pandas.lib.map_infer (pandas/lib.c:62578)
  File "/Users/stephen/anaconda/lib/python2.7/site-packages/geopandas/io/sql.py", line 42, in <lambda>
    s = wkb_geoms.apply(lambda x: shapely.wkb.loads(binascii.unhexlify(x.encode())))
AttributeError: 'NoneType' object has no attribute 'encode'

该表具有以下结构:

CREATE TABLE hist_point (
id BIGINT NOT NULL,
version SMALLINT NOT NULL,
visible BOOLEAN,
user_id INTEGER,
user_name TEXT,
valid_from TIMESTAMP,
valid_to TIMESTAMP,
tags HSTORE,
geom GEOMETRY(POINT,900913),
typ1 CHAR,
typ TEXT,
minor INTEGER,
CONSTRAINT hist_point_pkey PRIMARY KEY (id, version   )

该表填充了来自 OpenStreetMaps 的数据。我已经能够将此表中的数据加载到普通的 Pandas DataFrames 中 - 所以数据库连接没有问题,所以我不确定为什么它不适用于 GeoPandas。

我在 OSX 10.11 上使用通过 Anaconda 加载的 Python 2.7(以及使用“pip install geopandas”加载的 GeoPandas)。

洞察力将不胜感激。

谢谢你,斯蒂芬。

4

0 回答 0