2014-07-26 480 views
1

如何計算Python中2個GPS座標的速度,距離和方向(度)?每個點都有經緯度。Python從2個GPS座標計算速度,距離,方向

我發現這個職位的半正矢距離計算:

Calculate distance between 2 GPS coordinates

它也有一個速度和方向的Java版本,但它們是公制的,我需要MPH和Python。

+0

速度您需要花費從A到B旅行的時間。Haversine可以找到距離。所以速度是微不足道的發現。在這裏找到方向:http://stackoverflow.com/questions/3209899/determine-compass-direction-from-one-lat-lon-to-the-other – zengr

+0

你一定錯過了這個: http://stackoverflow.com /問題/ 15736995 /何燦I-很快,估計-的距離之間,二,經緯度點 – dappiu

回答

2

嘗試使用pyproj的時間。我必須確定一個處理LOB的項目的距離(等等),我發現pyproj是非常寶貴的。 (注意:我的積分是MGRS格式,必須首先轉換爲經緯度)

_GEOD = pyproj.Geod(ellps='WGS84') 
_MGRS = mgrs.MGRS() 
def dist(sp,ep): 
    try: 
     # convert start point and end point 
     (sLat,sLon) = _MGRS.toLatLon(sp) 
     (eLat,eLon) = _MGRS.toLatLon(ep) 

     # inv returns azimuth, back azimuth and distance 
     a,a2,d = _GEOD.inv(sLon,sLat,eLon,eLat) 
    except: 
     raise ValueError, "Invalid MGRS point" 
    else: 
     return d,a