为什么地球会给出错误的距离?

时间:2017-05-01 12:08:38

标签: r distance latitude-longitude

请查看以下示例:

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状态:

,但结果却很糟糕
  

与椭球相同单位的距离值(默认为米)

修改:就像来自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

1 个答案:

答案 0 :(得分:3)

您正在向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

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

如果你这样做:

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

你会得到:

[1] 75.34357