如何从geoalchemy2的查询结果中获取lng lat值 [英] How to get lng lat value from query results of geoalchemy2

查看:90
本文介绍了如何从geoalchemy2的查询结果中获取lng lat值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,

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'>

我也尝试过 lake.point.ST_X() 但它也没有给出预期的纬度

I also tried to do lake.point.ST_X() but it didn't give the expected latitude neither

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

What is the correct way to transform the value from WKBElement to readable and useful format, say (lng, lat)?

谢谢

推荐答案

您可以解析 WKB (众所周知的二进制) 点,甚至其他几何形状,使用 shapely.

You can parse WKB (well-known binary) points, and even other geometry shapes, using shapely.

from shapely import wkb
for lake in query:
    point = wkb.loads(bytes(lake.point.data))
    print point.x, point.y

这篇关于如何从geoalchemy2的查询结果中获取lng lat值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆