简体   繁体   English

带有 distHaversine 的 distm() 是否会在短距离内给出不准确的结果?

[英]Is distm() with distHaversine giving inaccurate results for short distances?

I'm confused by this result I'm getting from geosphere::distm() .我对从geosphere::distm()得到的这个结果感到困惑。 I compute the distance from a starting point to two points a and b .我计算从起点到两点ab的距离。 On Google Maps, I can see that the distance from start to a is greater than the distance from start to b .在谷歌地图上,我可以看到从starta的距离大于从startb的距离。 But the distm() function makes it appear that the reverse is true.但是distm()函数使它看起来相反。

library(geosphere)
start <- c(42.23025, -83.71448)
a <- c(42.30022, -83.71255)
b <- c(42.24302, -83.75135)

# distm() says start is closer to a:

distm(start, a, fun = distHaversine)
#>         [,1]
#> [1,] 879.541
distm(start, b, fun = distHaversine)
#>          [,1]
#> [1,] 4107.282

But NOAA's distance calculator says the distance to a is about 4 miles, compared to about 2 miles for b .但是 NOAA 的距离计算器表示到a的距离约为 4 英里,而b距离约为 2 英里。 And I get a similar ratio of a being nearly twice as a far when I do a simple application of the Pythagorean theorem:而我得到的相似比a是近两倍,当我做勾股定理的一个简单的应用远:

sqrt((start[1] - a[1])^2 + (start[2] - a[2])^2)
#> [1] 0.06999661
sqrt((start[1] - b[1])^2 + (start[2] - b[2])^2)
#> [1] 0.03901884

What explains the result from distm() ?什么解释了distm()的结果? My points are close together, less than five miles, could that be contributing?我的积分相距很近,不到五英里,这会有所贡献吗?

This looks like a situation of swapping latitude and longitude.这看起来像是交换了经纬度的情况。 (I do this every time.) While the traditional way to communicate a coordinate is Lat,Long, distm is looking for Long,Lat (ie relating to XY). (我每次都这样做。)虽然传递坐标的传统方式是 Lat,Long,但distm正在寻找 Long,Lat(即与 XY 相关)。 We can swap the order using rev to reverse the order of the coordinate vector.我们可以使用rev交换顺序来反转坐标向量的顺序。

distHaversine(rev(start), rev(a))
[1] 7790.647 # 4.8 miles

distHaversine(rev(start), rev(b))
[1] 3354.825 # 2 miles

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM