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中文件遍历的两种方法
Jun 16 Python
Python中使用tarfile压缩、解压tar归档文件示例
Apr 05 Python
Python3写入文件常用方法实例分析
May 22 Python
Python实现图像几何变换
Jul 06 Python
一个基于flask的web应用诞生(1)
Apr 11 Python
基于DataFrame筛选数据与loc的用法详解
May 18 Python
Django实战之用户认证(用户登录与注销)
Jul 16 Python
Python数据抓取爬虫代理防封IP方法
Dec 23 Python
详解Python做一个名片管理系统
Mar 14 Python
Python3.5基础之变量、数据结构、条件和循环语句、break与continue语句实例详解
Apr 26 Python
解决在keras中使用model.save()函数保存模型失败的问题
May 21 Python
python的setattr函数实例用法
Dec 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
5个数组Array方法: indexOf、filter、forEach、map、reduce使用实例
2015/01/29 Javascript
Java  Spring 事务回滚详解
2016/10/17 Javascript
jQuery鼠标悬停内容动画切换效果
2017/04/27 jQuery
Vue实现百度下拉提示搜索功能
2017/06/21 Javascript
vue的传参方式汇总和router使用技巧
2018/05/22 Javascript
AngularJS使用$http配置对象方式与服务端交互方法
2018/08/13 Javascript
微信小程序实现swiper切换卡内嵌滚动条不显示的方法示例
2018/12/20 Javascript
微信小程序自定义弹窗滚动与页面滚动冲突的解决方法
2019/07/16 Javascript
深入理解 TypeScript Reflect Metadata
2019/12/12 Javascript
Vue 防止短时间内连续点击后多次触发请求的操作
2020/11/11 Javascript
[02:11]DOTA2上海特级锦标赛主赛事第二日RECAP
2016/03/04 DOTA
简单介绍使用Python解析并修改XML文档的方法
2015/10/15 Python
python 实现红包随机生成算法的简单实例
2017/01/04 Python
Python实现注册登录系统
2017/08/08 Python
python实现用户管理系统
2018/01/10 Python
利用Opencv中Houghline方法实现直线检测
2018/02/11 Python
python实现人工智能Ai抠图功能
2019/09/05 Python
Python 3.8正式发布重要新功能一览
2019/10/17 Python
jenkins配置python脚本定时任务过程图解
2019/10/29 Python
浅谈图像处理中掩膜(mask)的意义
2020/02/19 Python
基于Django OneToOneField和ForeignKey的区别详解
2020/03/30 Python
详解Python中的路径问题
2020/09/02 Python
PyCharm设置注释字体颜色以及是否倾斜的操作
2020/09/16 Python
实习老师离校感言
2014/02/03 职场文书
教师简历自我评价
2014/02/03 职场文书
安全教育实施方案
2014/03/02 职场文书
申论倡议书范文
2014/05/13 职场文书
食堂标语大全
2014/06/11 职场文书
班级学雷锋活动总结
2014/06/26 职场文书
受伤赔偿协议书
2014/09/24 职场文书
常务副县长“四风”个人对照检查材料思想汇报
2014/10/02 职场文书
社区三八妇女节活动总结
2015/02/06 职场文书
困难补助申请报告
2015/05/19 职场文书
2015年社区工会工作总结
2015/05/26 职场文书
党员反邪教心得体会
2016/01/15 职场文书
导游词创作书写原则以及开场白技巧怎么学?
2019/09/25 职场文书