没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
试读
3页
最近项目上有这样的需求,需要依据设备的经纬度坐标计算距离及角度。经验证后效果较好,并分享。 1 经纬度转换距离代码 #!/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'Seven' import math # 计算距离 def getDistance(latA, lonA, latB, lonB): ra = 6378140 # 赤道半径 rb = 6356755 # 极半径 flatten = (ra - rb) / ra # Partial rate of the earth # change angle
资源推荐
资源详情
资源评论
Python经纬度坐标转换为距离及角度的实现经纬度坐标转换为距离及角度的实现
最近项目上有这样的需求,需要依据设备的经纬度坐标计算距离及角度。经验证后效果较好,并分享。
1 经纬度转换距离代码经纬度转换距离代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Seven'
import math
# 计算距离
def getDistance(latA, lonA, latB, lonB):
ra = 6378140 # 赤道半径
rb = 6356755 # 极半径
flatten = (ra - rb) / ra # Partial rate of the earth
# change angle to radians
radLatA = math.radians(latA)
radLonA = math.radians(lonA)
radLatB = math.radians(latB)
radLonB = math.radians(lonB)
pA = math.atan(rb / ra * math.tan(radLatA))
pB = math.atan(rb / ra * math.tan(radLatB))
x = math.acos(math.sin(pA) * math.sin(pB) + math.cos(pA) * math.cos(pB) * math.cos(radLonA - radLonB))
c1 = (math.sin(x) - x) * (math.sin(pA) + math.sin(pB)) ** 2 / math.cos(x / 2) ** 2
c2 = (math.sin(x) + x) * (math.sin(pA) - math.sin(pB)) ** 2 / math.sin(x / 2) ** 2
dr = flatten / 8 * (c1 - c2)
distance = ra * (x + dr)
distance = round(distance / 1000, 4)
return f'{distance}km'
2 经纬度转化角度代码经纬度转化角度代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'Seven'
import math
# 计算角度
def getDegree(latA, lonA, latB, lonB):
radLatA = math.radians(latA)
radLonA = math.radians(lonA)
radLatB = math.radians(latB)
radLonB = math.radians(lonB)
dLon = radLonB - radLonA
y = math.sin(dLon) * math.cos(radLatB)
x = math.cos(radLatA) * math.sin(radLatB) - math.sin(radLatA) * math.cos(radLatB) * math.cos(dLon)
brng = math.degrees(math.atan2(y, x))
brng = round((brng + 360) % 360, 4)
brng = int(brng)
if (brng == 0.0) or ((brng == 360.0)):
return '正北方向'
elif brng == 90.0:
return '正东方向'
elif brng == 180.0:
return '正南方向'
elif brng == 270.0:
return '正西方向'
elif 0 < brng < 90:
return f'北偏东{brng}'
elif 90 < brng < 180:
return f'东偏南{brng - 90}'
elif 180 < brng < 270:
return f'西偏南{270 - brng}'
elif 270 < brng < 360:
资源评论
weixin_38637878
- 粉丝: 3
- 资源: 926
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 论文(最终)_20240430235101.pdf
- 基于python编写的Keras深度学习框架开发,利用卷积神经网络CNN,快速识别图片并进行分类
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功