簡體   English   中英

使用 Python 計算矩形的 4 個角的緯度/經度

[英]Calculate lat/lon of 4 corners of rectangle using Python

給定形狀的中心坐標、長度、寬度和方位角,我需要在 Python 腳本中找到矩形四個角的經緯度坐標。 長度和寬度以法定英里為單位,但老實說,將它們轉換為米可能是最簡單的部分之一。 我有一些關於如何使用 haversine 來計算兩點之間距離的例子,但我對此一無所知。 誰能至少指出我正確的方向?

長方形圖片

更新

這是我根據@Mbo 提供的鏈接為我的 Python 腳本想出的公式:

lat2 = asin(sin(lat1)*cos(length2/(_AVG_EARTH_RADIUS_KM)) + cos(lat1) * sin(length2/(_AVG_EARTH_RADIUS_KM)) * cos(bearing1))

lon2 = lon1 + atan2(sin(bearing1) * sin(length2/(_AVG_EARTH_RADIUS_KM)) * cos(lat1), cos(length2/(_AVG_EARTH_RADIUS_KM)) - sin(lat1) * sin(lat2))

不幸的是,結果沒有意義。 我使用了 32° N 77° W 的中心點,長度為 20 英里,寬度為 10 英里,方位角為 0 度,我得到的結果是0.586599511812, -77.0

當我在我的地圖應用程序中輸入 plot 時,它告訴我新點的坐標應該是32.14513° N, -77.0° W

編輯添加:在上面的公式中使用之前,我將length1width1轉換為千米,並將bearing1轉換為弧度。

地球球體上的矩形.. 這是值得懷疑的事情。

無論如何,看看這個頁面

使用Destination point given distance and bearing from start point部分的公式,計算距離width/2和 bearings bearing, bearing + 180處的兩個中點。

對於每個中間點,用height/2bearing + 90, bearing - 90做同樣的事情來計算角點。

(請注意,對於這種近似值,作為角角距離的寬度將是不精確的)

使用pyproj ,您擁有進行計算的工具。

fwd()支持計算終點,給出起點、方位和距離。

您仍然需要基本的幾何圖形來計算必要的距離/角度。

我最終找到了 2 個答案。

第一個,來自python - 在給定當前點、距離和方位的情況下獲取緯度/經度很簡單。 Destination point given distance and bearing from start point畢竟有效,我只是忘了將起點的緯度/經度轉換為弧度,然后在最后將答案轉換回度數。

生成的代碼如下所示:

import math

R = 6378.1 #Radius of the Earth
brng = 1.57 #Bearing is 90 degrees converted to radians.
d = 15 #Distance in km

#lat2  52.20444 - the lat result I'm hoping for
#lon2  0.36056 - the long result I'm hoping for.

lat1 = math.radians(52.20472) #Current lat point converted to radians
lon1 = math.radians(0.14056) #Current long point converted to radians

lat2 = math.asin( math.sin(lat1)*math.cos(d/R) +
     math.cos(lat1)*math.sin(d/R)*math.cos(brng))

lon2 = lon1 + math.atan2(math.sin(brng)*math.sin(d/R)*math.cos(lat1),
             math.cos(d/R)-math.sin(lat1)*math.sin(lat2))

lat2 = math.degrees(lat2)
lon2 = math.degrees(lon2)

print(lat2)
print(lon2)

我找到的第二個答案,來自python - 計算給定點、方位角和距離的 gps 坐標,使用 geopy 並且簡單得多,所以我最終將其作為我的首選解決方案:

from geopy import Point
from geopy.distance import distance, VincentyDistance

# given: lat1, lon1, bearing, distMiles
lat2, lon2 = VincentyDistance(miles=distMiles).destination(Point(lat1, lon1), bearing)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM