我需要计算作为克里金插值输出的网格与我需要插值的某些点之间的距离。
问题是网格非常大,并且使用平均值来计算网格点之间的距离,并且geodDist
包中的oce
的感兴趣点需要永久。< / p>
有没有更好的方法来计算网格中的哪个点更接近某些兴趣点?
这是我的平庸周期
#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
}
}
}
由于这只是一个最佳实践问题,我不包含任何数据,希望它没问题。
答案 0 :(得分:0)
正如Carl建议的那样,使用apply系列函数可以加快计算速度
??apply
您可能还想查看并行处理