具有多个栅格堆栈的ClusterR

时间:2016-02-12 17:52:16

标签: r parallel-processing raster

以下是栅格库为使用clusterR和overlay函数提供的示例:

ary

如果我有多个光栅堆栈,我想知道如何运行该函数:

library(raster)
beginCluster()
r <- raster()
r[] <- 1:ncell(r)
s <- stack(r, r*2, r*3)
f2 <- function(d,e,f) (d + e) / (f * param)
param <- 122
ov <- clusterR(s, overlay, args=list(fun=f2), export='param')

我想要这样的内容(s <- stack(r, r*2, r*3) s2 <- stack(r*2, r*3, r*4) s3 <- stack(r*3, r*4, r*5) d,e,f f2 s, s2s3中的每一层都是{/ 1}}:

ov <- clusterR(s,s2,s3, overlay, args=list(fun=f2), export='param')

1 个答案:

答案 0 :(得分:2)

首先,我会在堆栈中创建一个包含param值的虚拟栅格图层。因此,操作可以进行矢量化:

p <- 122
rp <- r
rp[] <- p
s <- stack(s, rp)
s2 <- stack(s2, rp)
s3 <- stack(s3, rp)

然后你改变你的功能:

f2 <- function(x) (x[[1]] + x[[2]]) / (x[[3]] * x[[4]])

因此,正确引用了单个堆栈x的层。第四层是param值(此处为p

然后创建图层堆栈列表:

stackList <- list(s, s2, s3)

然后你lapply clusterR函数。

ov <- lapply(stackList, function(x){clusterR(x, fun = f2, progress = "text")})

ov将是您的重叠图层列表。

相关问题