最近遇到一個(gè)需求,使用pyhon 獲取雷達(dá)設(shè)備中的數(shù)據(jù)并解析,將返回?cái)?shù)據(jù)中包含方位角、速度、距離等,需要使用獲得的數(shù)據(jù)來(lái)計(jì)算目標(biāo)經(jīng)緯度!
import math
lon = 23.1090329023218
lat = 113.64838778972626
l_azimuth = 23
l_distance = 0.5 # km
# 已知起點(diǎn)經(jīng)緯度,使用距離與方位角求終點(diǎn)經(jīng)緯度
def get_destination(lat1: float, lon1: float, azimuth: float, distance: float) -> list:
"""
已知起點(diǎn)經(jīng)緯度,使用距離與方位角求終點(diǎn)經(jīng)緯度
:param lat1: 已知緯度
:param lon1: 已知經(jīng)度
:param azimuth: 已知方位角 °
:param distance: 已知距離 km
:return: 終點(diǎn)經(jīng)緯度
"""
lat1 = math.radians(lat1)
lon1 = math.radians(lon1)
azimuth = math.radians(azimuth)
distance = distance / 6378.1
lat2 = math.asin(math.sin(lat1) * math.cos(distance) + math.cos(lat1) * math.sin(distance) * math.cos(azimuth))
lon2 = lon1 + math.atan2(math.sin(azimuth) * math.sin(distance) * math.cos(lat1),
math.cos(distance) - math.sin(lat1) * math.sin(lat2))
lat2 = math.degrees(lat2)
lon2 = math.degrees(lon2)
return [lat2, lon2]
print(get_destination(lon, lat, 2.1, l_distance))
# 生成經(jīng)緯度坐標(biāo)并輸出JS語(yǔ)句應(yīng)用到地圖上
for i in range(0, 8):
z = get_destination(lon, lat, (i + 1) * 45, l_distance)
print('L.marker([%s, %s]).addTo(map).bindPopup("角度:%d°<br />距離:%f米");' % (z[0], z[1], (i + 1) * 45, l_distance * 1000))
Nginx使用寶典 (tboai.com)