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变量作用范围实例分析
Jul 07 Python
Python的Django中将文件上传至七牛云存储的代码分享
Jun 03 Python
Python第三方库的安装方法总结
Jun 06 Python
解决pycharm安装后代码区不能编辑的问题
Oct 28 Python
python绘图模块matplotlib示例详解
Jul 26 Python
基于Python的微信机器人开发 微信登录和获取好友列表实现解析
Aug 21 Python
python如何实现不用装饰器实现登陆器小程序
Dec 14 Python
python脚本实现mp4中的音频提取并保存在原目录
Feb 27 Python
Django添加bootstrap框架时无法加载静态文件的解决方式
Mar 27 Python
python 多进程和协程配合使用写入数据
Oct 30 Python
使用Django实现商城验证码模块的方法
Jun 01 Python
Python采集股票数据并制作可视化柱状图
Apr 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
PHP之COOKIE支持详解
2010/09/20 PHP
php 中英文语言转换类代码
2011/08/11 PHP
php数组函数序列之array_key_exists() - 查找数组键名是否存在
2011/10/29 PHP
php addslashes及其他清除空格的方法是不安全的
2012/01/25 PHP
php curl模拟post请求和提交多维数组的示例代码
2015/11/19 PHP
Javascript 页面模板化很多人没有使用过的方法
2012/06/05 Javascript
javascript获得当前的信息的一些常用命令
2015/02/25 Javascript
window.onload与$(document).ready()的区别分析
2015/05/30 Javascript
bootstrap3 兼容IE8浏览器!
2016/05/02 Javascript
浅谈bootstrap使用中的一些问题以及解决过程
2016/10/18 Javascript
轻松理解JavaScript闭包
2017/03/14 Javascript
从零开始学习Node.js系列教程三:图片上传和显示方法示例
2017/04/13 Javascript
详解vue2父组件传递props异步数据到子组件的问题
2017/06/29 Javascript
基于Vue 2.0的模块化前端 UI 组件库小结
2017/12/21 Javascript
在vue项目中使用element-ui的Upload上传组件的示例
2018/02/08 Javascript
JavaScript定时器设置、使用与倒计时案例详解
2019/07/08 Javascript
vue v-for 使用问题整理小结
2019/08/04 Javascript
微信小程序实现滚动加载更多的代码
2019/12/06 Javascript
JS实现网站楼层导航效果代码实例
2020/06/16 Javascript
[01:08:17]2018DOTA2亚洲邀请赛3月29日 小组赛B组 EG VS VGJ.T
2018/03/30 DOTA
Python实现从百度API获取天气的方法
2015/03/11 Python
python数据结构之图深度优先和广度优先实例详解
2015/07/08 Python
python中redis的安装和使用
2016/12/04 Python
python3应用windows api对后台程序窗口及桌面截图并保存的方法
2019/08/27 Python
python 正则表达式贪婪模式与非贪婪模式原理、用法实例分析
2019/10/14 Python
pytorch 修改预训练model实例
2020/01/18 Python
python 对一幅灰度图像进行直方图均衡化
2020/10/27 Python
日本面向世界,国际级的免税在线购物商城:DOKODEMO
2017/02/01 全球购物
体育专业个人的求职信范文
2013/09/21 职场文书
铁路安全事故反思
2014/04/26 职场文书
还款承诺书范文
2014/05/20 职场文书
秋季校运会广播稿100字
2014/09/18 职场文书
党员群众路线个人整改措施思想汇报
2014/10/12 职场文书
先进个人事迹材料范文
2014/12/30 职场文书
2016年入党心得体会范文
2016/01/23 职场文书
卖车协议书范文
2016/03/23 职场文书