本文介绍了如何遍历光栅砖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含部分积雪的 SCA(nrow=108,ncol=132,nlayers=365) 光栅砖.我想从这个 8 层中每层制作 46 个堆栈,并从这 46 个堆栈中计算最大部分积雪.我该怎么做?
I have a raster brick of SCA(nrow=108,ncol=132,nlayers=365) which contains fractional snow cover. I want to make 46 stacks each of 8 layers from this and calculate maximum fractional snow cover from these 46 stacks.How can i do this?
推荐答案
我想你可能想这样做:
library(raster)
# example data
sca <- brick(nrow=108,ncol=132,nl=365)
values(sca) <- runif(ncell(sca)*nlayers(sca))
# indices grouping sets of 8
i <- rep(1:ceiling(365/8), each=8)
# the last period is not a complete set of 8 days
i <- i[1:nlayers(sca)]
x <- stackApply(sca, i, max)
如果你想要一个循环(但这是R
,尽量避免循环)你可以做
If you wanted a loop (but this is R
, try to avoid loops) you could do
for (i in 1:nlayers(sca)) {
x <- sca[[i]]
# etc.
}
这篇关于如何遍历光栅砖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!