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调用C语言开发的共享库方法实例
Mar 18 Python
在Linux系统上部署Apache+Python+Django+MySQL环境
Dec 24 Python
JSON Web Tokens的实现原理
Apr 02 Python
Python 利用scrapy爬虫通过短短50行代码下载整站短视频
Oct 29 Python
python实现事件驱动
Nov 21 Python
Python生成rsa密钥对操作示例
Apr 26 Python
Django组件content-type使用方法详解
Jul 19 Python
Pytorch 保存模型生成图片方式
Jan 10 Python
PyCharm安装PyQt5及其工具(Qt Designer、PyUIC、PyRcc)的步骤详解
Nov 02 Python
Python 多进程原理及实现
Dec 21 Python
python Scrapy爬虫框架的使用
Jan 21 Python
OpenCV-Python实现人脸美白算法的实例
Jun 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
咖啡因含量是由谁决定的?低因咖啡怎么来?低因咖啡适合什么人喝
2021/03/06 新手入门
php&java(三)
2006/10/09 PHP
php与php MySQL 之间的关系
2009/07/17 PHP
php 归并排序 数组交集
2011/05/10 PHP
探讨Smarty中如何获取数组的长度以及smarty调用php函数的详解
2013/06/20 PHP
PHP判断表单复选框选中状态完整例子
2014/06/24 PHP
php的mssql数据库连接类实例
2014/11/28 PHP
php实现Mongodb自定义方式生成自增ID的方法
2015/03/23 PHP
PHP文件上传之多文件上传的实现思路
2016/01/27 PHP
Prototype Array对象 学习
2009/07/19 Javascript
点弹代码 点击页面任何位置都可以弹出页面效果代码
2012/09/17 Javascript
Extjs 3.3切换tab隐藏相应工具栏出现空白解决
2013/04/02 Javascript
jQuery打字效果实现方法(附demo源码下载)
2015/12/18 Javascript
jQuery插件制作的实例教程
2016/05/16 Javascript
基于jQuery实现表格内容的筛选功能
2016/08/21 Javascript
在localStorage中存储对象数组并读取的方法
2016/09/24 Javascript
js实现目录链接,内容跟着目录滚动显示的简单实例
2016/10/15 Javascript
Js利用console计算代码运行时间的方法示例
2017/09/24 Javascript
Vue修改mint-ui默认样式的方法
2018/02/03 Javascript
this在vue和小程序中的使用详解
2019/01/28 Javascript
浅析JavaScript中的事件委托机制跟深浅拷贝
2021/01/20 Javascript
[06:38]DOTA2怒掀电竞风暴 2013Chinajoy
2013/07/27 DOTA
[41:21]夜魇凡尔赛茶话会 第三期02:看图识人
2021/03/11 DOTA
Python实现股市信息下载的方法
2015/06/15 Python
对Python进行数据分析_关于Package的安装问题
2017/05/22 Python
Sanic框架应用部署方法详解
2018/07/18 Python
对IPython交互模式下的退出方法详解
2019/02/16 Python
浅谈PySpark SQL 相关知识介绍
2019/06/14 Python
html5各种页面切换效果和模态对话框用法总结
2014/12/15 HTML / CSS
《母亲的恩情》教学反思
2014/02/13 职场文书
采购意向书范本
2014/03/31 职场文书
学生自我评语大全
2014/04/18 职场文书
俞敏洪北大演讲稿
2014/05/22 职场文书
2014年学校党建工作总结
2014/11/11 职场文书
大学军训通讯稿(2016最新版)
2015/12/21 职场文书
实习员工转正的评语汇总,以备不时之需
2019/12/17 职场文书