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

作者:bboyzqh 时间:2022-03-15 02:41:27 

最近做有关GPS轨迹上有关的东西,花费心思较多,对两个常用的函数总结一下,求距离和求方位角,比较精确,欢迎交流!

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

来源:https://blog.csdn.net/zhuqiuhui/article/details/53180395

标签:python,经纬度,距离,方位角
0
投稿

猜你喜欢

  • Python常用库大全及简要说明

    2023-06-10 00:35:49
  • python selenium操作cookie的实现

    2021-12-18 22:54:02
  • Python算法中的时间复杂度问题

    2021-03-20 04:52:50
  • python语言基本语句用法总结

    2023-07-03 01:26:34
  • pycharm使用技巧之自动调整代码格式总结

    2021-08-28 08:13:18
  • Python实现视频目标检测与轨迹跟踪流程详解

    2021-12-27 06:48:37
  • SQLServer 游标简介与使用说明

    2009-07-02 13:53:00
  • 解决golang编译提示dial tcp 172.217.160.113:443: connectex: A connection attempt failed(推荐)

    2023-07-16 04:24:49
  • 解决pandas展示数据输出时列名不能对齐的问题

    2021-02-12 03:00:23
  • tensorflow 保存模型和取出中间权重例子

    2021-05-11 07:30:11
  • python选择排序算法实例总结

    2023-08-29 06:58:28
  • python中使用%与.format格式化文本方法解析

    2023-09-21 18:02:11
  • python异步任务队列示例

    2021-05-04 03:09:07
  • 在Django中预防CSRF攻击的操作

    2023-11-11 15:55:13
  • 教你快速上手Selenium爬虫,万物皆可爬

    2022-01-02 18:44:31
  • Python 正则 re.compile 真的必需吗

    2021-12-27 17:12:24
  • 深入浅出SQL嵌套SELECT语句

    2009-02-06 14:25:00
  • Pandas标记删除重复记录的方法

    2022-04-26 13:53:31
  • 详解用python实现爬取CSDN热门评论URL并存入redis

    2022-08-30 00:11:35
  • YOLOv5改进之添加CBAM注意力机制的方法

    2023-07-22 20:48:52
  • asp之家 网络编程 m.aspxhome.com