是否有一个包可以在考虑海拔的情况下计算两点之间的空间距离。因此,对于每个点,我们都有纬度、经度和海拔。到目前为止,我必须编写以下函数:
library(geosphere)
distance3D <- function (point1, point2) {
planiDist <- distm(point1[1:2], point2[1:2])
altiDist <- point2[3] - point1[3]
dist3D <- sqrt(planiDist^2+altiDist^2)
return(dist3D)
}
我只是想知道 R 包中是否存在一个函数。
最佳答案
半正矢大圆距离可能就是您正在寻找的。p>
library(geosphere)
distHaversine(p1, p2, r=6378137)
#p1, p2-longitude/latitude of point(s). Can be a vector of two numbers,
a matrix of 2 columns (first one is longitude, second is latitude)
or a SpatialPoints* object
#r-radius of the earth; default = 6378137 m
关于r - 计算 R 中具有纬度、经度和高程的两点之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51091092/