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 相关文章推荐
python自动化工具日志查询分析脚本代码实现
Nov 26 Python
python执行等待程序直到第二天零点的方法
Apr 23 Python
Python中的ConfigParser模块使用详解
May 04 Python
Python中二维列表如何获取子区域元素的组成
Jan 19 Python
pyqt5的QWebEngineView 使用模板的方法
Aug 18 Python
详解python分布式进程
Oct 08 Python
Python中几种属性访问的区别与用法详解
Oct 10 Python
Python DataFrame一列拆成多列以及一行拆成多行
Aug 06 Python
详解Django CAS 解决方案
Oct 30 Python
python Plotly绘图工具的简单使用
Mar 03 Python
Python-jenkins 获取job构建信息方式
May 12 Python
Python答题卡识别并给出分数的实现代码
Jun 22 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
phpinfo 系统查看参数函数代码
2009/06/05 PHP
php排序算法(冒泡排序,快速排序)
2012/10/09 PHP
PHP直接修改表内容DataGrid功能实现代码
2015/09/24 PHP
PHP Laravel 上传图片、文件等类封装
2017/08/16 PHP
PHP实现的策略模式示例
2019/03/20 PHP
用tip解决Ext列宽度不够的问题
2008/12/13 Javascript
JavaScript中创建字典对象(dictionary)实例
2015/03/31 Javascript
jQuery Validate初步体验(二)
2015/12/12 Javascript
AngularJs学习第八篇 过滤器filter创建
2016/06/08 Javascript
JavaScript中的子窗口与父窗口的互相调用问题
2017/02/08 Javascript
浅谈键盘上回车按钮的js触发事件
2017/02/13 Javascript
js获取当前周、上一周、下一周日期
2017/03/19 Javascript
angular4模块中给标签添加背景图的实现方法
2017/09/15 Javascript
基于BootStrap的文本编辑器组件Summernote
2017/10/27 Javascript
详解js加减乘除精确计算
2019/03/19 Javascript
在VUE中实现文件下载并判断状态的方法
2019/11/08 Javascript
Python的内存泄漏及gc模块的使用分析
2014/07/16 Python
python中二维阵列的变换实例
2014/10/09 Python
基于python编写的微博应用
2014/10/17 Python
python Crypto模块的安装与使用方法
2017/12/21 Python
Python 创建新文件时避免覆盖已有的同名文件的解决方法
2018/11/16 Python
Pyqt5 基本界面组件之inputDialog的使用
2019/06/25 Python
python中多个装饰器的调用顺序详解
2019/07/16 Python
python_mask_array的用法
2020/02/18 Python
Python+OpenCV实现图像的全景拼接
2020/03/05 Python
Python文件时间操作步骤代码详解
2020/04/13 Python
Python之字典添加元素的几种方法
2020/09/30 Python
Python求区间正整数内所有素数之和的方法实例
2020/10/13 Python
关于Python 解决Python3.9 pandas.read_excel(‘xxx.xlsx‘)报错的问题
2020/11/28 Python
基于zepto的插件之移动端无缝向上滚动并上下触摸滑动实例代码
2016/12/20 HTML / CSS
自荐信怎么写好
2013/11/11 职场文书
中学生评语大全
2014/04/18 职场文书
公司内部升职自荐信
2015/03/27 职场文书
礼仪培训心得体会
2016/01/22 职场文书
2019年警察入党转正申请书最新范文
2019/09/03 职场文书
Nginx代理Redis哨兵主从配置的实现
2022/07/15 Servers