如何在栅格之间进行插值? [英] How to interpolate between rasters?
本文介绍了如何在栅格之间进行插值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果有三个栅格(作为矩阵):
If have three rasters(as matrix):
r1 <- raster(nrows=10, ncols=10); r1 <- setValues(r1, 1:ncell(r1))
r16 <- raster(nrows=10, ncols=10);r16 <- setValues(r16, 1:ncell(r16))
r30 <- raster(nrows=10, ncols=10);r30 <- setValues(r30, 1:ncell(r30))
我想对r1,c16,c30
进行线性插值以找到介于两者之间的值,即r2,r3,r4,......r15 then r17,r18,r19,..........r29
.
I would like to linearly interpolate r1,c16,c30
to find the values in between i.e. r2,r3,r4,......r15 then r17,r18,r19,..........r29
.
使用R可以吗?
推荐答案
这是一种实现方法
library(raster)
r <- raster(nrows=10, ncols=10);
values(r) <- NA
x <- sapply(1:30, function(...) r)
x[[1]] <- setValues(r, runif(ncell(r)))
x[[16]] <- setValues(r, runif(ncell(r))) + 10
x[[30]] <- setValues(r, runif(ncell(r))) + 20
s <- stack(x)
z <- approxNA(s)
plot(z)
plot(1:30, z[1])
这是另一种方法
library(raster)
r <- raster(nrows=10, ncols=10);
x1 <- setValues(r, runif(ncell(r)))
x16 <- setValues(r, runif(ncell(r))) + 10
x30 <- setValues(r, runif(ncell(r))) + 20
s <- stack(x1, x16, x30)
x <- calc(s, fun=function(y) approx(c(1,16,30), y, 1:30)$y)
但是,如果三层中都存在NA值,则此操作将失败.您需要调整功能fun
来解决此问题(这是
But this will fail if there are NA values in the three layers. You would need to adjust the function fun
to deal with that (here is an example).
这篇关于如何在栅格之间进行插值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文