考虑以下具有几何字段的SQLAalchemy / GeoAlchemy2 ORM:
from geoalchemy2 import Geometry, WKTElement
class Item(Base):
__tablename__ = 'item'
id = Column(Integer, primary_key=True)
...
geom = Column(Geometry(geometry_type='POINTZ', srid=4326))当我更新PostgreSQL外壳中的项时:
UPDATE item SET geom = st_geomFromText('POINT(2 3 0)', 4326) WHERE id = 5;获取字段:
items = session.query(Item).\
filter(Item.id == 3)
for item in items:
print item.geom给予:
01e9030000000000000000004000000000000008400000000000000000这不是一个正确的WKB --至少,它不使用loads进行解析。
如何获得lat**/**lon geom 字段的?
发布于 2015-11-02 16:44:57
通过lat和是获取lon可能不是最优雅的方法,但它有效:
from sqlalchemy import func
items = session.query(
Item,
func.st_y(Item.geom),
func.st_x(Item.geom)
).filter(Item.id == 3)
for item in items:
print(item.geom)给予:
(<Item 3>, 3.0, 2.0)发布于 2019-07-09 07:34:30
geoalchemy2 形状函数将一个:class:geoalchemy2.types.SpatialElement转换为一个几何图形。
在项目课上:
from geoalchemy2.shape import to_shape
point = to_shape(self.geo)
return {
'latitude': point.y,
'longitude': point.x
}发布于 2022-05-16 09:38:01
点类型语法是
Point ( Lat, Long) 从mosi_kha的答案看,返回应该是
from geoalchemy2.shape import to_shape
point = to_shape(self.geo)
return {
'latitude': point.x,
'longitude': point.y
}https://stackoverflow.com/questions/33482653
复制相似问题