Python从2个GPS坐标计算速度、距离和方向

2024-05-15 09:37:05 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在Python中从2个GPS坐标计算速度、距离和方向(度)?每个点都有纬度,经度,时间。

我在这篇文章中找到了哈弗森距离的计算方法:

Calculate distance between 2 GPS coordinates

它也有一个Java版本的速度和方向,但它们是公制的,我需要英里每小时,并在Python。


Tags: 版本距离时间javabetween方向gpsdistance
2条回答
  1. 用哈弗辛找出A和B之间的距离。Haversine Formula in Python (Bearing and Distance between two GPS points)
  2. 找到从A到B的方向(方位):Determine compass direction from one lat/lon to the other
  3. 假设你知道从A到B的时间。速度=距离/时间

尝试使用pyproj。我必须为一个处理lob的项目确定距离(除其他外),我发现pyproj是无价的。(注:我的分数采用MGRS格式,必须先转换为lat/lon)

_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

相关问题 更多 >