相关疑难解决方法(0)

R - 查找最近的相邻点和给定半径内的邻居数,坐标为lat-long

我试图弄清楚我的数据集中有多少孤立的某些点.我使用两种方法来确定隔离,最近邻居的距离和给定半径内的相邻站点的数量.我所有的坐标都是纬度和经度

这就是我的数据:

    pond            lat         long        area    canopy  avg.depth   neighbor    n.lat   n.long  n.distance  n.area  n.canopy    n.depth n.avg.depth radius1500
    A10             41.95928    -72.14605   1500    66      60.61538462                                 
    AA006           41.96431    -72.121     250     0       57.77777778                                 
    Blacksmith      41.95508    -72.123803  361     77      71.3125                                 
    Borrow.Pit.1    41.95601    -72.15419   0       0       41.44444444                                 
    Borrow.Pit.2    41.95571    -72.15413   0       0       37.7                                    
    Borrow.Pit.3    41.95546    -72.15375   0       0       29.22222222                                 
    Boulder         41.918223   -72.14978   1392    98      43.53333333                                 
Run Code Online (Sandbox Code Playgroud)

我想把最近的邻近池塘的名称放在列邻居,它的纬度和长度在n.lat和n.long,两个池塘之间的距离n.distance,以及区域,冠层和avg.depth in每个适当的列.

其次,我想把目标池塘1500米范围内的池塘数量调到半径1500.

有谁知道一个功能或包,可以帮助我计算我想要的距离/数字?如果这是一个问题,输入我需要的其他数据并不困难,但最近邻居的名字和距离加上1500米以内的池塘数量是我真正需要帮助的.

谢谢.

r distance latitude-longitude

25
推荐指数
2
解决办法
3万
查看次数

找到r中某个纬度/经度距离内的位置

我有一个网格化数据集,可在以下位置获得数据:

lon <- seq(-179.75,179.75, by = 0.5)
lat <- seq(-89.75,89.75, by = 0.5)
Run Code Online (Sandbox Code Playgroud)

我想找到位于该位置500公里范围内的所有数据点:

mylat <- 47.9625
mylon <- -87.0431
Run Code Online (Sandbox Code Playgroud)

我的目标是在R中使用geosphere包,但我目前编写的方法效率似乎不高:

require(geosphere)
dd2 <- array(dim = c(length(lon),length(lat)))
for(i in 1:length(lon)){
  for(ii in 1:length(lat)){
    clon <- lon[i]
    clat <- lat[ii]
    dd <- as.numeric(distm(c(mylon, mylat), c(clon, clat), fun = distHaversine))
    dd2[i,ii] <- dd <= 500000
  }
}
Run Code Online (Sandbox Code Playgroud)

在这里,我循环遍历数据中的每个网格,并查找距离是否小于500 km.然后我存储一个TRUE或FALSE变量,然后我可以使用它来平均数据(其他变量).从这个方法,我想要一个TRUE或FALSE的矩阵,用于距离lat和lon 500公里范围内的位置.有没有更有效的方法来做到这一点?

r geosphere

19
推荐指数
2
解决办法
1675
查看次数

标签 统计

r ×2

distance ×1

geosphere ×1

latitude-longitude ×1