重复相同的栅格层以创建栅格堆栈 [英] repeat same raster layer to create a raster stack

查看:38
本文介绍了重复相同的栅格层以创建栅格堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从光栅层创建光栅堆栈,其中光栅堆栈只是重复一定次数的同一个光栅层.

I am trying to create a raster stack from a rasterlayer, where the raster stack is just the same raster layer repeated a certain number of times.

我可以这样做:

library(raster)
rasterstack <- addLayer(rasterlayer, rasterLayer, rasterLayer) 

这是有效的.但是,我希望堆栈大约为 1000 层.我想我可以循环遍历,但我想知道是否有更复杂的方法来做到这一点.

and this works. However, i want the stack to be about a 1000 layers. I guess i could just loop through, but i was wondering if there was a more sophisticated way to doing this.

我尝试这样做的原因是计算具有数据的栅格堆栈的加权平均值,其中每个图层处于不同的时间段,并且权重位于不同的栅格图层对象中.我希望如果我从权重栅格层创建一个与数据层数相同的 rasterstack,我将能够执行以下操作:

The reason I am trying to do this is to calculate the weighted mean of a raster stack with data where each layer is a different time period, and where the weights are in a different raster layer object. I am hoping that if I create a rasterstack from the weights raster layer with the same number of layers as the data, I'll be able to do something like:

  weightedmean <- weighted.mean( data.RasterStack, weights.RasterStack )

推荐答案

示例数据

library(raster)
r <- raster(ncol=10, nrow=10, vals=1:100)

解决方案

n <- 10  # number of copies
s <- stack(lapply(1:n, function(i) r)) 

或者

s <- stack(replicate(n, r))

这篇关于重复相同的栅格层以创建栅格堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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