How to get lng lat value from query results of geoalchemy2

后端 未结 2 1689
日久生厌
日久生厌 2021-02-19 00:45

For exammple,

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


        
相关标签:
2条回答
  • 2021-02-19 01:05

    http://geoalchemy-2.readthedocs.org/en/0.2.4/spatial_functions.html#geoalchemy2.functions.ST_AsText is what you are looking for. This will return 'POINT (lng, lat)'. ST_X ought to work, though, so you may have another issue if it isn't returning the correct value.

    0 讨论(0)
  • 2021-02-19 01:08

    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
    
    0 讨论(0)
提交回复
热议问题