0

我需要计算作为克里金插值输出的网格与我需要插值的一些点之间的距离。

geodDist问题是网格非常大,并且从包中计算网格点与我的兴趣点之间的距离的循环计算平庸的双倍oce需要永远。

有没有更好的方法来计算网格中的哪个点更接近某些兴趣点?

这是我的平庸周期

#find the closest points from the grid to the old samples
#kriging model and so on y_ok now contains the grid

y_ok <- krige(rssi~1, samples, predgrid, model = vfit_ok, nmax=5)

yok.fr<-as.data.frame(y_ok)
#samples_all.fr contains the points where I want to interpolate
require(oce)
dist.mtx<-matrix(data=NA,nrow=dim(samples_all.fr)[1],ncol=2)

for (i in 1:2){#dim(samples_all.fr[1])){
  for(j in 1:dim(yok.fr)[1]){
    a=geodDist(samples_all.fr[i,2], samples_all.fr[i,1], yok.fr[j,2], yok.fr[j,1])
    if(!(is.finite(dist.mtx[i,1]))|(a<dist.mtx[i,1])){
      dist.mtx[i,1]=a
      dist.mtx[i,2]=j
    } 
  }
}

由于这只是一个最佳实践问题,我不包含任何数据,希望没问题。

4

1 回答 1

0

正如 Carl 建议的那样,使用 apply 系列函数可能会加快计算速度

 ??apply

您可能还想查看并行处理

于 2014-04-19T13:16:21.747 回答