r - 计算 R 中具有纬度、经度和高程的两点之间的距离

标签 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)
    }

我只是想知道 R 包中是否存在一个函数。

最佳答案

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

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/

相关文章:

r - ggplot 中标题行的不等水平调整

python - 解码 SEGD 文件并绘制其中的任何轨迹

javascript - 使用 D3 更改 shapefile 投影以进行可视化

ruby - 计算 ruby 中多边形的面积

python - 在python中的地理数据中查找圆圈内的所有坐标

d3.js - d3.geo.path 矩形包裹错误的方式

r - 如何按所有列对矩阵进行排序

r - 在 GGplot 中显示位于同一点的点的密度

r - 将 R Markdown 渲染为 MS Word 时页面上 flextable 的对齐方式

r - R中runif和sample的区别?