为什么 geoshere 给出了错误的距离?

Why does geoshere give the wrong distance?

只需检查以下示例:

lat <- c(47.5, 47.5, 47.501)
lng <- c(9.3, 9.301, 9.3)
geosphere::distVincentyEllipsoid(lng[c(1,2)], lat[c(1,2)])
# [1] 5551424 Should be about 5000 m?
geosphere::distVincentyEllipsoid(lng[c(1,3)], lat[c(1,3)])
#[1] 5551583 Should be about 5000 m?

m <- leaflet() %>%
  addTiles(group = "OSM") %>%
  addProviderTiles("Stamen.TonerLite") %>%
  addLayersControl(
    baseGroups = c("OSM", "Stamen.TonerLite")) %>% 
  addCircleMarkers(lat = lat,
                   lng = lng,
                   color = "blue",
                   stroke = FALSE,
                   radius = 3,
                   fillOpacity = 0.7)
print(m)

在我看来,尽管 ????distVincentyEllipsoid 状态:

,但结果很不理想

Distance value in the same units as the ellipsoid (default is meters)

编辑:就像来自here的简单交叉检查:

R = 6371  # radius of the earth in km
x = (lng[2] - lng[1]) * cos( 0.5*(lat[2]+lat[1]) )
y = lat[2] - lat[1]
d = R * sqrt( x*x + y*y ) # in km

您提供的 distVincentyEllipsoid 错误信息。它应该具有以下格式:distVincentyEllipsoid(p1, p2)。来自帮助文件:

p1  longitude/latitude of point(s), in degrees 1; can be a vector of two numbers, a matrix of 2 columns (first one is longitude, second is latitude) or a SpatialPoints* object
p2  as above

您正在做的是向 p1 提供两个 lng 值,向 p2 提供两个 lat 值,而这两个点都应该是 lng/lat组合。

如果你这样做:

distVincentyEllipsoid(c(lng[1], lat[1]), c(lng[2], lat[2]))

您将获得:

[1] 75.34357