小编Jos*_*cha的帖子

Geosphere/dplyr:创建坐标之间的距离矩阵

我想创建多个坐标之间距离的“矩阵”。最好使用 dplyr/geosphere。我已经看到 geosphere 包提供了这个。我设法创建了两个向量之间的距离,但我很难创建完整的矩阵。

这是具有多个坐标的示例表。

df <- data.frame(latitude = c(49.48609,-8.14671,11.28625),
                 longitude = c(8.463678,143.05793,-11.18285))

  latitude  longitude
1 49.48609   8.463678
2 -8.14671 143.057930
3 11.28625 -11.182850
Run Code Online (Sandbox Code Playgroud)

这是我正在寻找的输出:

  latitude    longitude    distance-latlon1    distance-latlon2   distance-latlon3                 
1 49.48609     8.463678    NA                  *latlon2><latlon1  *latlon3><latlon1
2 -8.14671   143.057930    *latlon1><latlon2   NA                 *latlon3><latlon2
3 11.28625   -11.182850    *latlon1><latlon3   *latlon2><latlon3  NA
Run Code Online (Sandbox Code Playgroud)

我尝试使用 geosphere,但我只找到了一种计算两列之间距离的方法(在此代码段中结果为 0)。

library(geosphere) 
df$distance <- distVincentyEllipsoid(df[,c('longitude','latitude')],
                                     df[,c('longitude','latitude')])
Run Code Online (Sandbox Code Playgroud)

r geospatial latitude-longitude dplyr geosphere

5
推荐指数
1
解决办法
2511
查看次数

标签 统计

dplyr ×1

geospatial ×1

geosphere ×1

latitude-longitude ×1

r ×1