经纬度坐标与距离的相互转换及其实现

您所在的位置:网站首页 blagoveshchensk经纬度 经纬度坐标与距离的相互转换及其实现

经纬度坐标与距离的相互转换及其实现

2023-08-09 17:16| 来源: 网络整理| 查看: 265

经纬度坐标与距离的相互转换 1.经纬度与距离角度的换算关系:2 Python代码实现

1.经纬度与距离角度的换算关系:

a)在纬度相等的情况下:

经度每隔0.00001度,距离相差约1米;

每隔0.0001度,距离相差约10米;

每隔0.001度,距离相差约100米;

每隔0.01度,距离相差约1000米;

每隔0.1度,距离相差约10000米。

b)在经度相等的情况下:

纬度每隔0.00001度,距离相差约1.1米;

每隔0.0001度,距离相差约11米;

每隔0.001度,距离相差约111米;

每隔0.01度,距离相差约1113米;

每隔0.1度,距离相差约11132米。

c)换算 地球赤道上环绕地球一周走一圈共 40075.04公里 而一圈分成360° 而每1°(度)有60’ 每一度一秒在赤道上的长度计算如下: 40075.04km/360°=111.31955km 111.31955km/60’=1.8553258km=1855.3m 而每一分又有60秒 每一秒就代表 1855.3m/60=30.92m 任意两点距离计算公式为 d=111.12cos{1/[sinΦAsinΦB十 cosΦAcosΦBcos

2 Python代码实现

1.经纬度转换为距离

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.经纬度转换角度代码

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


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3