【问题标题】:Geographic coordinates in PostgreSQL queryPostgreSQL 查询中的地理坐标
【发布时间】:2016-02-23 19:37:35
【问题描述】:

数据库表中有两个字段,latitudelongitude。 (其他领域也一样,但现在不重要了。)

我有一个函数,其中有三个参数:latitudelongitudema​​x_distance(公里)。

有没有什么方法可以构建原始 PostgreSQL 查询,只返回代表位置的行,该位置在从给定纬度和经度测量的 ma​​x_distance (km) 内?

示例参数 latitude=59.9138699, longitude=10.7522451, max_distance=10

【问题讨论】:

标签: sql postgresql gis


【解决方案1】:

为此,请使用 postgis。

Postgis有ST_DistanceST_PointFromText等功能:

select * from tbl
where ST_Distance(
    ST_PointFromText('POINT(' || longitude || ' ' || latitude || ')', 4326), 
    ST_PointFromText('POINT(10.7522451 59.9138699)', 4326)
) < 10000;

要快速完成此操作,您应该使用几何字段并对其进行索引。


您还应该了解一些有关空间参考系统和 SRID 的知识。 SRID 4326 表示 WGS84 坐标系,通常在网络上使用。

【讨论】:

    猜你喜欢
    • 2013-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 2016-07-19
    • 2020-08-24
    • 2013-09-09
    相关资源
    最近更新 更多