如何从geoalchemy2的查询结果中获取lng lat值

2023-12-22

例如,

class Lake(Base):
     __tablename__ = 'lake'
     id = Column(Integer, primary_key=True)
     name = Column(String)
     geom = Column(Geometry('POLYGON'))
     point = Column(Geometry('Point'))


lake = Lake(name='Orta', geom='POLYGON((3 0,6 0,6 3,3 3,3 0))', point="POINT(2 9)")
query = session.query(Lake).filter(Lake.geom.ST_Contains('POINT(4 1)'))
for lake in query:
     print lake.point

它回来了<WKBElement at 0x2720ed0; '010100000000000000000000400000000000002240'>

我也尝试过做湖点.ST_X()但它也没有给出预期的自由度

将值从 WKBElement 转换为可读且有用的格式(例如(lng,lat))的正确方法是什么?

Thanks


您可以解析 WKB (众所周知的二进制文件 http://edndoc.esri.com/arcsde/9.1/general_topics/wkb_representation.htm)点,甚至其他几何形状,使用shapely.

from shapely import wkb
for lake in query:
    point = wkb.loads(bytes(lake.point.data))
    print point.x, point.y
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从geoalchemy2的查询结果中获取lng lat值 的相关文章

随机推荐