python 距离地理纬度经度

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 距离地理纬度经度相关的知识,希望对你有一定的参考价值。

## calculate distances between two points into km
def distances(lat1,lon1,lat2,lon2):
    from math import sin, cos, sqrt, atan2, radians

    # approximate radius of earth in km
    R = 6373.0
    # conversion
    lat1 = radians(lat1)
    lon1 = radians(lon1)
    lat2 = radians(lat2)
    lon2 = radians(lon2)
    # differences
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    # calculate distances
    a = sin(dlat / 2)**2 + cos(lat1) * cos(lat2) * sin(dlon / 2)**2
    c = 2 * atan2(sqrt(a), sqrt(1 - a))
    return R * c
## Calculate the distance between Lyon and Paris
from haversine import haversine

lyon = (45.7597, 4.8422) # (lat, lon)
paris = (48.8567, 2.3508)

haversine(lyon, paris)
# >> 392.2172595594006  # in kilometers

haversine(lyon, paris, unit='mi')
# >> 243.71201856934454  # in miles

haversine(lyon, paris, unit='nmi')
# >> 211.78037755311516  # in nautical miles

以上是关于python 距离地理纬度经度的主要内容,如果未能解决你的问题,请参考以下文章

2个纬度/经度点(坐标)列表之间的地理/地理空间距离

通过转换为 utm 计算纬度/经度距离与使用近似方法给出不同的结果

地理空间坐标和以千米为单位的距离

查找两个经度纬度之间的距离-Mysql

计算两个纬度和经度坐标之间的距离

计算两个地理位置之间的距离