请查看以下示例:
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
答案 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