计算R中具有纬度,长度和高度的两个点之间的距离

Lik*_*iky 11 r geo

是否有一个包允许计算两点之间的空间距离考虑到高程.因此,对于每个点,我们将拥有纬度,经度和海拔.到目前为止,我必须编写以下函数:

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)
    }
Run Code Online (Sandbox Code Playgroud)

我只是想知道其中一个R包中是否存在一个功能.

小智 0

半正矢大圆距离可能就是您正在寻找的。

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 
Run Code Online (Sandbox Code Playgroud)