用科学测量地理距离 [英] Measuring geographic distance with scipy

查看:133
本文介绍了用科学测量地理距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使用scipypdist函数的结果.我对真实的地理距离(首选单位:公里)感兴趣.取以下坐标:

I fail to use the outcome of scipy's pdist function. I am interested in the real geographic distance (preferred unit: km). Take the following coordinates:

from scipy.spatial.distance import pdist

coordinates = [ (42.057, -71.08), (39.132, -84.5155) ]
distance = pdist(coordinates)
print distance
# [ 13.75021037]

但是什么是单位?谷歌表示,这两点之间的距离是1179公里.我如何从13.75021037到达那里?

But what's the unit? Google says the distance between these two points is 1179 km. How do I get there from 13.75021037?

推荐答案

现在使用最新的Python 3,这将发出弃用警告.我实际上是通过

Using the latest Python 3, this now gives a deprecation warning. I actually found this answer by @cffk much easier to understand:

(为方便起见,粘贴在这里)

(pasting here for convenience)

>>> from geopy.distance import great_circle
>>> from geopy.distance import geodesic
>>> p1 = (31.8300167,35.0662833) # (lat, lon) - https://goo.gl/maps/TQwDd
>>> p2 = (31.8300000,35.0708167) # (lat, lon) - https://goo.gl/maps/lHrrg
>>> geodesic(p1, p2).meters
429.1676644986777
>>> great_circle(p1, p2).meters
428.28877358686776

这篇关于用科学测量地理距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆