[英]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
.我计算从起点到两点
a
和b
的距离。 On Google Maps, I can see that the distance from start
to a
is greater than the distance from start
to b
.在谷歌地图上,我可以看到从
start
到a
的距离大于从start
到b
的距离。 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.