经纬度坐标与距离的相互转换及其实现
經緯度坐標與距離的相互轉換
- 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 radiansradLatA = 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) ** 2c2 = (math.sin(x) + x) * (math.sin(pA) - math.sin(pB)) ** 2 / math.sin(x / 2) ** 2dr = 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 - radLonAy = 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:return f'北偏西{brng - 270}'else:pass驗證:
選取深圳野生動物園(22.599578, 113.973129)為起點,深圳坪山站(22.6986848, 114.3311032)為終點,結合百度地圖、谷歌地圖等進行效果驗證。
即,百度測距為38.3km
Google地圖手動測距為39.31km
參考:
https://blog.csdn.net/qq_23392639/article/details/89446703
http://blog.itblood.com/952.html
http://wenda.tianya.cn/question/151ddd808627a78b
總結
以上是生活随笔為你收集整理的经纬度坐标与距离的相互转换及其实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: CUDA编程
- 下一篇: GPU 编程入门到精通(二)之 运行第一