简体   繁体   English

我的 geopy 大圆距离计算有什么问题?

[英]What is wrong with my geopy great circle distance computation?

I want to compute the distance (in km) using geopy library between two points defined by their respective (lat, lon) coordinates.我想使用 geopy 库计算由各自的 (lat, lon) 坐标定义的两点之间的距离(以公里为单位)。

My code我的代码

from geopy.distance import great_circle

# lat, lon
p1 = (45.8864, -7.2305)
p2 = (46.2045, -7.2305)

# distance in km
great_circle(p1, p2).km
>>> 35.371156132664765

To check above results, I used the tool available here: https://www.movable-type.co.uk/scripts/latlong.html but the two outputs do not match.为了检查以上结果,我使用了此处提供的工具: https://www.movable-type.co.uk/scripts/latlong.html但两个输出不匹配。

在此处输入图像描述

The output of my code is 35.371156132664765 though the above tool returns a distance of 15.41 km.我的代码的 output 是35.371156132664765尽管上面的工具返回了 15.41 公里的距离。 How come the results are different?结果怎么不一样?

Your calculation for the points p1 and p2 is wrong, you need to convert the minutes and seconds into degree correctly.您对点p1p2的计算是错误的,您需要将分和秒正确转换为度数。 Otherwise the code works prefectly.否则代码可以完美运行。

Your arguments are flipped: geopy expects coordinates in (lon, lat) order.您的 arguments 被翻转: geopy需要(lon, lat)顺序的坐标。

p2 = (-7.2305, 46.2045)
p1 = (-7.2305, 45.8864)
great_circle(p1, p2).km
# => 35.08987842072082

(Additionally, as moreON says in comments, the web tool you have linked treats 46.2045 and 46 20 45N very differently.) (此外,正如 moreON 在评论中所说,您链接的 web 工具对46.204546 20 45N的处理方式非常不同。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM