帮酷LOGO
0 0 评论
文章标签:AWK  poi  Coordinates    long  经纬度  CAL  ECHO  

计算两个地理坐标点之间的距离(纬度经度)

h(){ echo $@|awk '{d($1,$2,$3,$4);} function d(x,y,x2,y2,a,c,dx,dy){dx=r(x2-x);dy=r(y2-y);x=r(x);x2=r(x2);a=(sin(dx/2))^2+cos(x)*cos(x2)*(sin(dy/2))^2;c=2*atan2(sqrt(a),sqrt(1-a)); printf("%.4f",6372.8*c);} function r(g){return g*(3.1415926/180.);}';}
哈弗斯线公式(Haversine formula)根据一个球体上两点的经度和纬度确定了它们之间的距离,
示例输出
# input (format: latitude1 longitude1 latitude2 longitude2) :
h -22.9077611 -43.1259322 -22.9121089 -43.2301558
# output:
10.6889
# So, the distance between -22.9077611 (latitude),-43.1259322 (longitude) and -22.9121089,-43.2301558 (latitude,longitude) is 10,688.9 meters (10.6889 kilometers)


文章标签:CAL  GEO  poi    long  ECHO  Distance  Coordinates  

Copyright © 2011 HelpLib All rights reserved.    知识分享协议 京ICP备05059198号-3  |  如果智培  |  酷兔英语