我一直在尝试使用 GeoAlchemy2,但在解析它的字段时遇到了一些麻烦geom
。
我尝试在 WKB 元素上使用内置to_shape
函数:
示例如下:
lake = Session.query(Lake).get(1)
polygon = to_shape(lake.geom)
我用过:
house = config.database.db_session.query(House)\
.filter_by(house_id=1).first()
print "geom:", house.geom
01e90300009aea561e53634140ffb86b0da20a40400000000000000000
from geoalchemy2 import shape
print "to_shape:", shape.to_shape(house.geom)
to_shape:
Traceback (most recent call last):
File "ranker_tester.py", line 40, in <module>
print "to_shape:", shape.to_shape(house.geom)
File ".../lib/python2.7/site-packages/GeoAlchemy2-0.2.4-py2.7.egg/geoalchemy2/shape.py", line 24, in to_shape
return shapely.wkb.loads(bytes(element.data))
File ".../lib/python2.7/site-packages/shapely/wkb.py", line 16, in loads
return reader.read(data)
File ".../lib/python2.7/site-packages/shapely/geos.py", line 361, in read
raise ReadingError("Could not create geometry because of errors "
shapely.geos.ReadingError: Could not create geometry because of errors while reading input.
知道如何解析这个 GeoAlchemy2 geom 字段吗?数据库值有效。