2016-02-12 81 views
3

這裏是光柵庫提供了使用clusterR和覆蓋功能的示例:ClusterR多光柵棧

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在功能f2s, s2每層s3):

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

列出堆棧並循環羣集? – Sam

回答

1

首先,我將在您的堆棧中創建一個虛擬柵格圖層,並保存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) 

那麼你lapplyclusterR功能。

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

ov將會是您的重疊圖層列表。