GeoAlchemy2:获取点的纬度和经度

编程入门 行业动态 更新时间:2024-10-20 18:58:28
本文介绍了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:获取点的纬度和经度

本文发布于:2023-10-13 10:14:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1487666.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:经度   纬度

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!