postgresql 如何从 PostGIS 获取地球上两点之间的距离?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31213790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 01:57:44  来源:igfitidea点击:

How can I get distance between two points on Earth from PostGIS?

postgresqlpostgis

提问by Nathan Long

I'm getting an unexpected value from a PostGIS distance query, and I'm not sure why. I'm trying to find the distance between two points on Earth.

我从 PostGIS 距离查询中得到了一个意外的值,但我不知道为什么。我试图找到地球上两点之间的距离。

SELECT ST_Distance(
  ST_Point(50.7678,6.091499)::geography,
  ST_Point(52.525592,13.369545)::geography
) as distance;

... returns 827757.672533206, or about 827.7km.

...返回827757.672533206,或约 827.7 公里。

However, if I calculate this distance with an open source library I'm using, or using any one of several online calculators, I get 538.6km. Something is obviously amiss.

但是,如果我使用我正在使用的开源库或使用几个在线计算器中的任何一个来计算这个距离,我会得到 538.6km。显然有些不对劲。

What am I doing wrong?

我究竟做错了什么?

回答by Jakub Kania

The result is correct, the input is not. ST_Pointaccepts input as (lon,lat)while you're verifying it as (lat,lon).

结果正确,输入错误。ST_Point(lon,lat)在您将其验证为时接受输入(lat,lon)