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


Posted in Python onJuly 05, 2019

最近做有关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

以上这篇python实现两个经纬度点之间的距离和方位角的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
wxpython 学习笔记 第一天
Mar 16 Python
Python Sleep休眠函数使用简单实例
Feb 02 Python
Python获取暗黑破坏神3战网前1000命位玩家的英雄技能统计
Jul 04 Python
python分割列表(list)的方法示例
May 07 Python
python实现图像识别功能
Jan 29 Python
解决matplotlib库show()方法不显示图片的问题
May 24 Python
用Python实现读写锁的示例代码
Nov 05 Python
对pandas中iloc,loc取数据差别及按条件取值的方法详解
Nov 06 Python
python修改FTP服务器上的文件名
Sep 11 Python
线程安全及Python中的GIL原理分析
Oct 29 Python
python不到50行代码完成了多张excel合并的实现示例
May 28 Python
python 如何用urllib与服务端交互(发送和接收数据)
Mar 04 Python
Python3+Appium实现多台移动设备操作的方法
Jul 05 #Python
Python PIL读取的图像发生自动旋转的实现方法
Jul 05 #Python
python读出当前时间精度到秒的代码
Jul 05 #Python
python读写csv文件方法详细总结
Jul 05 #Python
Python考拉兹猜想输出序列代码实践
Jul 05 #Python
python读写csv文件实例代码
Jul 05 #Python
python暴力解压rar加密文件过程详解
Jul 05 #Python
You might like
Smarty+QUICKFORM小小演示
2007/02/25 PHP
用Zend Studio+PHPnow+Zend Debugger搭建PHP服务器调试环境步骤
2014/01/19 PHP
PHP错误和异长常处理总结
2014/03/06 PHP
php的4种常见运行方式
2015/03/20 PHP
漂亮的thinkphp 跳转页封装示例
2019/10/16 PHP
DOM下的节点属性和操作小结
2009/05/14 Javascript
jQuery学习基础知识小结
2010/11/25 Javascript
简单的前端js+ajax 购物车框架(入门篇)
2011/10/29 Javascript
JS面向对象基础讲解(工厂模式、构造函数模式、原型模式、混合模式、动态原型模式)
2014/08/16 Javascript
javascript 动态修改css样式方法汇总(四种方法)
2015/08/27 Javascript
完美实现八种js焦点轮播图(下篇)
2020/04/20 Javascript
你知道setTimeout是如何运行的吗?
2016/08/16 Javascript
JS实现的随机排序功能算法示例
2017/06/09 Javascript
javascript checkbox/radio onchange不能兼容ie8处理办法
2017/06/13 Javascript
详解使用VueJS开发项目中的兼容问题
2018/08/02 Javascript
node.js文件操作系统实例详解
2019/11/05 Javascript
openlayers 3实现车辆轨迹回放
2020/09/24 Javascript
Python 可爱的大小写
2008/09/06 Python
python 合并文件的具体实例
2013/08/08 Python
在Django的模板中使用认证数据的方法
2015/07/23 Python
一张图带我们入门Python基础教程
2017/02/05 Python
Python探索之修改Python搜索路径
2017/10/25 Python
Python中列表与元组的乘法操作示例
2018/02/10 Python
Python列表切片操作实例总结
2019/02/19 Python
python matplotlib画图库学习绘制常用的图
2019/03/19 Python
Django外键(ForeignKey)操作以及related_name的作用详解
2019/07/29 Python
python rsa实现数据加密和解密、签名加密和验签功能
2019/09/18 Python
Python @property装饰器原理解析
2020/01/22 Python
python实现梯度下降和逻辑回归
2020/03/24 Python
Ubuntu中配置TensorFlow使用环境的方法
2020/04/21 Python
Python使用sys.exc_info()方法获取异常信息
2020/07/23 Python
音乐教师求职信范文
2015/03/20 职场文书
2015年“七七卢沟桥事变”纪念活动总结
2015/03/24 职场文书
企业财务经理岗位职责
2015/04/08 职场文书
导游词之上海东方明珠塔
2019/09/25 职场文书
Vue全局事件总线你了解吗
2022/02/24 Vue.js