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最基本的操作字典的方法
Apr 24 Python
django实现分页的方法
May 26 Python
python编程线性回归代码示例
Dec 07 Python
Python实现一个Git日志统计分析的小工具
Dec 14 Python
快速解决PyCharm无法引用matplotlib的问题
May 24 Python
Python 给某个文件名添加时间戳的方法
Oct 16 Python
对Python的交互模式和直接运行.py文件的区别详解
Jun 29 Python
pywinauto自动化操作记事本
Aug 26 Python
python分布式计算dispy的使用详解
Dec 22 Python
Django用数据库表反向生成models类知识点详解
Mar 25 Python
Tensorflow中批量读取数据的案列分析及TFRecord文件的打包与读取
Jun 30 Python
python 爬取英雄联盟皮肤并下载的示例
Dec 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 insert语法详解
2008/06/07 PHP
PHP使用mkdir创建多级目录的方法
2015/12/22 PHP
php轻松实现文件上传功能
2016/03/03 PHP
ThinkPHP like模糊查询,like多匹配查询,between查询,in查询,一般查询书写方法
2018/09/26 PHP
jQuery版仿Path菜单效果
2011/12/15 Javascript
js钢琴按钮波浪式图片排列效果代码分享
2015/08/26 Javascript
jQuery实现为控件添加水印文字效果(附源码)
2015/12/02 Javascript
JavaScript设计模式经典之工厂模式
2016/02/24 Javascript
JavaScript中误用/g导致的正则test()无法正确重复执行的解决方案
2016/07/27 Javascript
jquery validate表单验证插件
2016/09/06 Javascript
Javascript获取图片原始宽度和高度的方法详解
2016/09/20 Javascript
微信小程序网络请求的封装与填坑之路
2017/04/01 Javascript
浅谈angularjs依赖服务注入写法的注意点
2017/04/24 Javascript
AngularJS实现表单元素值绑定操作示例
2017/10/11 Javascript
vue watch关于对象内的属性监听
2019/04/22 Javascript
详解微信小程序实现跑马灯效果(附完整代码)
2019/04/29 Javascript
vue-cli —— 如何局部修改Element样式
2020/10/22 Javascript
[01:59]深扒TI7聊天轮盘语音出处 1
2017/05/11 DOTA
Python3如何解决字符编码问题详解
2017/04/23 Python
Pycharm设置界面全黑的方法
2018/05/23 Python
Python3中的bytes和str类型详解
2019/05/02 Python
python实现微信打飞机游戏
2020/03/24 Python
pandas分组聚合详解
2020/04/10 Python
Python configparser模块常用方法解析
2020/05/22 Python
python实现爱奇艺登陆密码RSA加密的方法示例详解
2020/05/27 Python
美国在线眼镜店:GlassesShop
2018/11/15 全球购物
日本AOKI官方商城:AOKI西装
2020/06/11 全球购物
电工工作职责范本
2014/02/22 职场文书
竞聘书格式及范文
2014/03/31 职场文书
2015大学生实训报告
2014/11/05 职场文书
2015年城管执法工作总结
2015/07/23 职场文书
关于实现中国梦的心得体会
2016/01/05 职场文书
iPhone13 Pro外观确定,升级4800万镜头,4月20日发新品
2021/04/15 数码科技
深入浅析Redis 集群伸缩原理
2021/05/15 Redis
教你如何让spark sql写mysql的时候支持update操作
2022/02/15 MySQL
MySQL详解进行JDBC编程与增删改查方法
2022/06/16 MySQL