具有多个栅格堆栈的ClusterR [英] ClusterR with multiple raster stacks

查看:129
本文介绍了具有多个栅格堆栈的ClusterR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是栅格库提供的一个使用clusterR和overlay函数的示例:

Here is an example that raster library provides for using clusterR and overlay functions:

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')

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

I want to know how to run that function if I have multiple raster stacks:

s <- stack(r, r*2, r*3)
s2 <- stack(r*2, r*3, r*4)
s3 <- stack(r*3, r*4, r*5)

我想要这样的东西(函数f2中的d,e,fs, s2s3中的每一层):

I want something like this (d,e,f in function f2 are each layer in s, s2 and s3):

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

推荐答案

首先,我将在您的堆栈中创建一个保存param值的虚拟栅格图层.因此,可以对操作进行矢量化:

First I would create a dummy raster layer in your stack holding the paramvalue. Thus, the operations can be vectorized:

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

然后您按以下方式更改功能:

Then you change your function like this:

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

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

Thus, the layers of the individual stack x are referred to correctly. The 4th layer is the param value (here p)

然后创建一个图层堆栈列表:

Then you create a list of layer stacks:

stackList <- list(s, s2, s3)

然后您lapply clusterR函数.

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

然后

ov将是您覆盖的图层的列表.

ov will then be a list of your overlaid layers.

这篇关于具有多个栅格堆栈的ClusterR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆