本文介绍了GeoAlchemy2:获取点的纬度和经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑以下 SQLAalchemy / GeoAlchemy2 具有几何字段的ORM:
Consider the following SQLAalchemy / GeoAlchemy2 ORM with a geometry field:
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 shell中的项目时:
When I update an item in the PostgreSQL shell:
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-至少,它不使用 Shapely的loads .
This isn't a proper WKB - at least, it does not parse with Shapely's loads.
如何获取geom字段的lat/lon?
How do I get the lat/lon of the geom field?
推荐答案通过 ST_X 和 ST_Y 可能不是最优雅的方法,但它可以:
Fetching the lat, lon via ST_X and ST_Y might not be the most elegant approach, but it works:
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)更多推荐
GeoAlchemy2:获取点的纬度和经度
发布评论