如何在 R 传单中使用 distanceTo 命令
How to use the distanceTo command in R leaflet
有没有办法在 R 中使用 distanceTo 命令?我只看到 javascript 文档?我已经有经纬度了
这是我正在谈论的命令:
http://leafletjs.com/reference.html#latlng-distanceto
您可以使用包 geosphere
中的 distHaversine()
函数来获得相同的结果。
例如:
library(geosphere)
# Longitude and Latitude, respectively:
coords1 <- c(-71, 42)
coords2 <- c(-70, 41)
distance <- distHaversine(coords1, coords2)
这给出了以米为单位的大圆距离:
R> distance
[1] 139077.2
同一包中的其他距离函数,例如 distVincentyEllipsoid()
可能更准确,但计算量更大。
有没有办法在 R 中使用 distanceTo 命令?我只看到 javascript 文档?我已经有经纬度了
这是我正在谈论的命令: http://leafletjs.com/reference.html#latlng-distanceto
您可以使用包 geosphere
中的 distHaversine()
函数来获得相同的结果。
例如:
library(geosphere)
# Longitude and Latitude, respectively:
coords1 <- c(-71, 42)
coords2 <- c(-70, 41)
distance <- distHaversine(coords1, coords2)
这给出了以米为单位的大圆距离:
R> distance
[1] 139077.2
同一包中的其他距离函数,例如 distVincentyEllipsoid()
可能更准确,但计算量更大。