使用经纬度直接计算距离与方位角

距离

import math
def cal_dis(lat1, lon1,lat2, lon2):
    latitude1 = (math.pi/180)*lat1
    latitude2 = (math.pi/180)*lat2
    longitude1 = (math.pi/180)*lon1
    longitude2= (math.pi/180)*lon2
    #因此AB两点的球面距离为:{arccos[sinb*siny+cosb*cosy*cos(a-x)]}*R
    #地球半径
    R = 6378.137
    d = math.acos(math.sin(latitude1)*math.sin(latitude2)+ math.cos(latitude1)*math.cos(latitude2)*math.cos(longitude2-longitude1))*R
    return d


if __name__ == '__main__':
    print cal_dis(23.0,101.1,23.06,113.34)

或者使用

from geopy.distance import geodesic

geodesic((30.28708,120.12802999999997), (28.7427,115.86572000000001)).m

经纬度是角度,而三角函数的输入是弧度。

方位角

def calc_azimuth(lat1, lon1, lat2, lon2):
    lat1_rad = lat1 * math.pi / 180
    lon1_rad = lon1 * math.pi / 180
    lat2_rad = lat2 * math.pi / 180
    lon2_rad = lon2 * math.pi / 180

    y = math.sin(lon2_rad - lon1_rad) * math.cos(lat2_rad)
    x = math.cos(lat1_rad) * math.sin(lat2_rad) - \
        math.sin(lat1_rad) * math.cos(lat2_rad) * math.cos(lon2_rad - lon1_rad)

    brng = math.atan2(y, x) * 180 / math.pi

    return float((brng + 360.0) % 360.0)

 

上一篇:Windows Embedded CE 6.0开发初体验(三)设置Boot-loader


下一篇:Matlab legend换行 多个legend 阵列排布