计算球面两点距离 python

代码如下

@requires_authorization
#!/usr/bin/env python
#-*-encoding:utf-8 -*-
import math

def cal_dis_meters(radius,latitude1, longitude1,latitude2, longitude2):  
    radLat1 = (math.pi/180)*latitude1  
    radLat2 = (math.pi/180)*latitude2  
    radLng1 = (math.pi/180)*longitude1  
    radLng2= (math.pi/180)*longitude2  
    #ref: http://www.alivenode.com/index.php/archives/300
    d=2.0*math.asin(math.sqrt(math.pow(math.sin((radLat1-radLat2)/2.0),2)+math.cos(radLat1)*math.cos(radLat2)*math.pow(math.sin((radLng1-radLng2)/2.0),2)))*radius
    return d

你可能感兴趣的:(GIS)