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实现面向对像的ASP程序实例
Nov 10 Python
Python字符串替换实例分析
May 11 Python
一键搞定python连接mysql驱动有关问题(windows版本)
Apr 23 Python
Python定时器实例代码
Nov 01 Python
通过python+selenium3实现浏览器刷简书文章阅读量
Dec 26 Python
python中的for循环
Sep 28 Python
Python3 关于pycharm自动导入包快捷设置的方法
Jan 16 Python
Python入门Anaconda和Pycharm的安装和配置详解
Jul 16 Python
python UDP(udp)协议发送和接收的实例
Jul 22 Python
python绘制BA无标度网络示例代码
Nov 21 Python
python3通过qq邮箱发送邮件以及附件
May 20 Python
用Python提取PDF表格的方法
Apr 11 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
APMServ使用说明
2006/10/23 PHP
fleaphp crud操作之findByField函数的使用方法
2011/04/23 PHP
php导出excel格式数据问题
2014/03/11 PHP
php实现的数字验证码及数字运算验证码
2015/07/30 PHP
Symfony2联合查询实现方法
2016/03/18 PHP
微信小程序 消息推送php服务器验证实例详解
2017/03/30 PHP
CodeIgniter框架实现的整合Smarty引擎DEMO示例
2019/03/28 PHP
jquery中使用$(#form).submit()重写提交表单无效原因分析及解决
2013/03/25 Javascript
如何正确使用javascript 来进行我们的程序开发
2014/06/23 Javascript
用Node.js通过sitemap.xml批量抓取美女图片
2015/05/28 Javascript
Bootstrap实现登录校验表单(带验证码)
2016/06/23 Javascript
layer弹窗插件操作方法详解
2017/05/19 Javascript
使用jQuery实现动态添加小广告
2017/07/11 jQuery
原生JS+Canvas实现五子棋游戏
2020/05/28 Javascript
vue实现自定义多选与单选的答题功能
2018/07/05 Javascript
vue实现菜单切换功能
2019/05/08 Javascript
基于纯JS实现多张图片的懒加载Lazy过程解析
2019/10/14 Javascript
微信小程序如何实现五星评价功能
2019/10/15 Javascript
es6函数中的作用域实例分析
2020/04/18 Javascript
python类继承与子类实例初始化用法分析
2015/04/17 Python
Python实现使用卷积提取图片轮廓功能示例
2018/05/12 Python
运行django项目指定IP和端口的方法
2018/05/14 Python
pycharm远程开发项目的实现步骤
2019/01/20 Python
Pytorch实现的手写数字mnist识别功能完整示例
2019/12/13 Python
CSS3实现红包抖动效果
2020/12/23 HTML / CSS
移动web模拟客户端实现多方框输入密码效果【附代码】
2016/03/25 HTML / CSS
美国受信赖的教育产品供应商:Nest Learning
2018/06/14 全球购物
DataList 能否分页,请问如何实现?
2015/05/03 面试题
小区门卫工作职责
2013/12/14 职场文书
给同学的道歉信
2014/01/16 职场文书
旅游项目开发策划书
2014/01/18 职场文书
关于奉献的演讲稿
2014/05/21 职场文书
学校师德师风整改方案
2014/10/28 职场文书
端午节活动总结报告
2015/02/11 职场文书
中国合伙人观后感
2015/06/02 职场文书
市场营销计划书
2019/04/24 职场文书