0
我有两个点A和B以及它们各自的经度和纬度。我也有一段时间需要从A点到B点。假设它需要1小时,并且从A假定驾驶员直奔B点并在旅行期间保持相同的速度。 0.6小时后,我想知道驾驶员的当前位置(按经度和纬度)。包geosphere
或任何其他允许我这样做的软件包中是否有任何功能?谢谢R - 计算一段时间后的地理位置
我有两个点A和B以及它们各自的经度和纬度。我也有一段时间需要从A点到B点。假设它需要1小时,并且从A假定驾驶员直奔B点并在旅行期间保持相同的速度。 0.6小时后,我想知道驾驶员的当前位置(按经度和纬度)。包geosphere
或任何其他允许我这样做的软件包中是否有任何功能?谢谢R - 计算一段时间后的地理位置
我认为你的问题更好,更简洁地表述为“我如何找到两个位置之间的大圆路径(定义为纬度/经度坐标),然后找到点的坐标为任意百分比那条路上的路呢?“。
首先让我们做一个任意一对的位置,称为A和B:
df <- data.frame(locations = c("a","b"),
lon =runif(2,min = -180, max = 180),
lat = runif(2,min = -90, max = 90))
现在,我们来看看他们之间的大圆航线。我们不需要路线本身,只需要整个路线的距离和初始方向。
require(geosphere)
# get the distance of a great circle route between these points
track.dist = distHaversine(p1 = df[1,c("lon","lat")],
p2 = df[2,c("lon","lat")])
然后获得初始轴承,我们将在一个位使用:
track.init.bearing = bearing(p1 = df[1,c("lon","lat")],
p2 = df[2,c("lon","lat")])
下一步是要弄清楚我们在哪里,在逝去路线的任意部分:
# figure out where we are at an arbitrary time
current.location.fraction = runif(1,min = 0, max = 1)
# get the distance
current.location.dist = current.location.fraction * track.dist
current.location = as.data.frame(destPoint(p = df[1,c("lon","lat")],
b = track.init.bearing,
d = current.location.dist))
而最后一步就是检查我们是沿着路线的距离右侧部分:
check.dist = distHaversine(p1 = df[1,c("lon","lat")],
p2 = c(current.location$lon,
current.location$lat))
print(current.location.fraction)
print(check.dist/track.dist)
在我的测试中,最后两个数字通常在1%以内,表明这并不算太坏。
因此,您可以从current.location
数据框中提取结果。
TDo:请参阅我在答案中使用的解释,它让您重新回到编程问题的领域。但我同意这个问题被搁置,因为你没有提供任何证据表明自己已经尝试过。 –