温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

python怎么实现两个经纬度点之间的距离和方位角的方法

发布时间:2021-04-07 09:56:10 来源:亿速云 阅读:313 作者:小新 栏目:开发技术

这篇文章主要介绍python怎么实现两个经纬度点之间的距离和方位角的方法,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

1. 求两个经纬点的方位角,P0(latA, lonA), P1(latB, lonB)(很多博客写的不是很好,这里总结一下)

def getDegree(latA, lonA, latB, lonB):
  """
  Args:
    point p1(latA, lonA)
    point p2(latB, lonB)
  Returns:
    bearing between the two GPS points,
    default: the basis of heading direction is north
  """
  radLatA = radians(latA)
  radLonA = radians(lonA)
  radLatB = radians(latB)
  radLonB = radians(lonB)
  dLon = radLonB - radLonA
  y = sin(dLon) * cos(radLatB)
  x = cos(radLatA) * sin(radLatB) - sin(radLatA) * cos(radLatB) * cos(dLon)
  brng = degrees(atan2(y, x))
  brng = (brng + 360) % 360
  return brng

2. 求两个经纬点的距离函数:P0(latA, lonA), P1(latB, lonB)

def getDistance(latA, lonA, latB, lonB):
  ra = 6378140 # radius of equator: meter
  rb = 6356755 # radius of polar: meter
  flatten = (ra - rb) / ra # Partial rate of the earth
  # change angle to radians
  radLatA = radians(latA)
  radLonA = radians(lonA)
  radLatB = radians(latB)
  radLonB = radians(lonB)
 
  pA = atan(rb / ra * tan(radLatA))
  pB = atan(rb / ra * tan(radLatB))
  x = acos(sin(pA) * sin(pB) + cos(pA) * cos(pB) * cos(radLonA - radLonB))
  c1 = (sin(x) - x) * (sin(pA) + sin(pB))**2 / cos(x / 2)**2
  c2 = (sin(x) + x) * (sin(pA) - sin(pB))**2 / sin(x / 2)**2
  dr = flatten / 8 * (c1 - c2)
  distance = ra * (x + dr)
  return distance

以上是“python怎么实现两个经纬度点之间的距离和方位角的方法”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI