一、两个经纬度点之间的距离
$phi_1$,$phi_2$是纬度,$lambda_1$,$lambda_2$是经度。均是弧度制数值
ArcGIS Python 实现
2 * 6372 * math.asin(math.sqrt(math.sin((math.radians( !CENTROID_Y! )-math.radians( !Avg_co_lat! ))/2 )**2 + math.cos(math.radians( !CENTROID_Y! ) ) * math.cos(math.radians( !Avg_co_lat! ) ) * math.sin((math.radians( !CENTROID_X! )-math.radians( !Avg_co_lon! ))/2 )**2 ) )
python 实现:
from math import radians, cos, sin, asin, sqrt def distance(lon1, lat1, lon2, lat2): lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2]) # haversine function dlon = lon2 - lon1 dlat = lat2 - lat1 a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2 c = 2 * asin(sqrt(a)) r = 6372 # ratio of earch, km return c * r # km
二、经纬度网格的面积计算
$phi_1$,$phi_2$是纬度,$lambda_1$,$lambda_2$是经度。 均是弧度制数值
python 实现
from math import radians, sin def area(lon1, lat1, lon2, lat2): lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2]) r = 6372 return abs(r**2 * (lon2 - lon1) * (sin(lat2) - sin(lat1)))
参考:经纬网格面积计算