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的Tornado框架的异步任务与AsyncHTTPClient
Jun 27 Python
分享给Python新手们的几道简单练习题
Sep 21 Python
Python实现找出数组中第2大数字的方法示例
Mar 26 Python
基于python 二维数组及画图的实例详解
Apr 03 Python
在Python中字典根据多项规则排序的方法
Jan 21 Python
python3+pyqt5+itchat微信定时发送消息的方法
Feb 20 Python
Python实现的读取文件内容并写入其他文件操作示例
Apr 09 Python
keras做CNN的训练误差loss的下降操作
Jun 22 Python
python logging模块的使用
Sep 07 Python
安装pytorch时报sslerror错误的解决方案
May 17 Python
Python IO文件管理的具体使用
Mar 20 Python
python实现对doc、txt、xls等文档的读写操作
Apr 02 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
德生H-501的评价与改造
2021/03/02 无线电
PHP安装攻略:常见问题解答(二)
2006/10/09 PHP
php实现统计邮件大小的方法
2013/08/06 PHP
php 如何获取数组第一个值
2013/08/06 PHP
PHP实现的下载远程图片自定义函数分享
2015/01/28 PHP
golang 调用 php7详解及实例
2017/01/04 PHP
php ajax数据传输和响应方法
2018/08/21 PHP
php 根据URL下载远程图片、压缩包、pdf等文件到本地
2019/07/26 PHP
完整显示当前日期和时间的JS代码
2007/09/17 Javascript
JavaScript Event学习第二章 Event浏览器兼容性
2010/02/07 Javascript
confirm的用法示例用于按钮操作时确定是否执行
2014/06/19 Javascript
jQuery中:not选择器用法实例
2014/12/30 Javascript
Jquery 实现grid绑定模板
2015/01/28 Javascript
node.js连接mongoDB数据库 快速搭建自己的web服务
2016/04/17 Javascript
js实现碰撞检测特效代码分享
2016/10/16 Javascript
vue 权限认证token的实现方法
2018/07/17 Javascript
详解超简单的react服务器渲染(ssr)入坑指南
2019/02/28 Javascript
重学 JS:为啥 await 不能用在 forEach 中详解
2019/04/15 Javascript
mpvue微信小程序的接口请求fly全局拦截代码实例
2019/11/13 Javascript
Nodejs实现WebSocket代码实例
2020/05/19 NodeJs
vue如何搭建多页面多系统应用
2020/06/17 Javascript
JavaScript多种图形实现代码实例
2020/06/28 Javascript
python线程池(threadpool)模块使用笔记详解
2017/11/17 Python
python 判断参数为Nonetype类型或空的实例
2018/10/30 Python
PyQt5笔记之弹出窗口大全
2019/06/20 Python
python爬虫实现中英翻译词典
2019/06/25 Python
flask框架jinja2模板与模板继承实例分析
2019/08/01 Python
用Python 爬取猫眼电影数据分析《无名之辈》
2020/07/24 Python
COS美国官网:知名服装品牌
2019/04/08 全球购物
酒店管理专业毕业生推荐信
2013/11/10 职场文书
婚礼新郎父母答谢词
2014/01/16 职场文书
物流专业求职信
2014/06/30 职场文书
人大代表选举标语
2014/10/07 职场文书
五星级酒店前台接待岗位职责
2015/04/02 职场文书
css3实现背景图片半透明内容不透明的方法示例
2021/04/13 HTML / CSS
在Django中使用MQTT的方法
2021/05/10 Python