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获取指定路径下所有指定后缀文件的方法
May 26 Python
python计算文本文件行数的方法
Jul 06 Python
使用python加密自己的密码
Aug 04 Python
Django中的Signal代码详解
Feb 05 Python
django使用xlwt导出excel文件实例代码
Feb 06 Python
pandas重新生成索引的方法
Nov 06 Python
Numpy 中的矩阵求逆实例
Aug 26 Python
python deque模块简单使用代码实例
Mar 12 Python
怎么快速自学python
Jun 22 Python
安装pytorch时报sslerror错误的解决方案
May 17 Python
python 爬取京东指定商品评论并进行情感分析
May 27 Python
Python自动操作神器PyAutoGUI的使用教程
Jun 16 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
配置支持SSI
2006/11/25 PHP
PHP基础学习小结
2011/04/17 PHP
PHP使用Alexa API获取网站的Alexa排名例子
2014/06/12 PHP
搭建PhpStorm+PhpStudy开发环境的超详细教程
2020/09/17 PHP
js一组验证函数
2008/12/20 Javascript
利用JQuery的load函数动态加载其它页面的内容的实现代码
2010/12/14 Javascript
JS实现的驼峰式和连字符式转换功能分析
2016/12/21 Javascript
Node.js命令行/批处理中如何更改Linux用户密码浅析
2018/07/22 Javascript
js实现简单的打印表格
2020/01/15 Javascript
[45:16]完美世界DOTA2联赛PWL S3 Magma vs Phoenix 第一场 12.12
2020/12/16 DOTA
OpenCV实现人脸识别
2017/04/07 Python
python3实现UDP协议的服务器和客户端
2017/06/14 Python
Python网络爬虫与信息提取(实例讲解)
2017/08/29 Python
使用python编写udp协议的ping程序方法
2018/04/22 Python
基于scrapy的redis安装和配置方法
2018/06/13 Python
在Python中获取两数相除的商和余数方法
2018/11/10 Python
Python面向对象思想与应用入门教程【类与对象】
2019/04/12 Python
python 操作mysql数据中fetchone()和fetchall()方式
2020/05/15 Python
如何将json数据转换为python数据
2020/09/04 Python
Python+OpenCV图像处理——打印图片属性、设置存储路径、调用摄像头
2020/10/22 Python
基于 HTML5 Canvas实现 的交互式地铁线路图
2018/03/05 HTML / CSS
html5使用canvas画三角形
2014/12/15 HTML / CSS
全球最大的在线橄榄球商店:Lovell Rugby
2018/05/20 全球购物
Abbacino官网:包、钱包和女士配饰
2019/04/15 全球购物
LN-CC中国:高端男装和女装的奢侈时尚目的地
2019/09/14 全球购物
体育教师工作总结的自我评价
2013/10/10 职场文书
动物学专业毕业生求职信
2013/10/11 职场文书
自考毕业自我鉴定范文
2013/10/27 职场文书
体育专业个人求职信范文
2013/12/27 职场文书
医院院务公开实施方案
2014/05/03 职场文书
员工薪酬激励方案
2014/06/13 职场文书
机关作风建设自查报告
2014/10/22 职场文书
六一儿童节致辞稿(3篇)
2019/07/11 职场文书
教师学期述职自我鉴定
2019/08/16 职场文书
关于Python OS模块常用文件/目录函数详解
2021/07/01 Python
SSM VUE Axios详解
2021/10/05 Vue.js