【发布时间】:2017-09-19 14:21:06
【问题描述】:
我正在处理时间序列的栅格,我需要分析 17 个日期的 ts。对于每个日期,我导入了带 5 和带 7。我制作了 17 个带 5 的列表和 17 个带 7 的列表,分别称为 list_B5 和 list_B7。 我想将同一日期的波段堆叠在一起,所以:list_B5 的第一个栅格与 list_B7 的第一个栅格; list_B5 的第二个栅格与 list_B7 的第二个栅格;等等。
我是循环新手,但我试着写一个:
for (i in seq_along(length(list_B5)) [1]) {
for (j in seq_along(length(list_B7)) [2]) {
B5 <- raster(list_B5[[i]]) #extract the raster of interest
B7 <- raster(list_B7[[j]]) #extract the raster of interest
test[i,j] <- brick(B5, B7) #stack them together
}
}
“测试”是:
test <- brick(nrows=5490, ncol=5490, nl=17)
不幸的是,我收到以下错误:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘raster’ for signature ‘"NULL"’
我不明白为什么它不接受我尝试提取感兴趣的栅格的行,因为通常仅此行就可以:
> raster(list_B5[[3]])
class : RasterLayer
dimensions : 5490, 5490, 30140100 (nrow, ncol, ncell)
resolution : 20, 20 (x, y)
extent : 6e+05, 709800, 5590200, 5700000 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=utm +zone=31 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0
有人可以向我解释为什么会出现上述错误吗?
【问题讨论】:
-
如果你想从同一天开始堆叠 B5 和 B7,为什么要使用
i和j?另外,你为什么使用i和[1]和j和[2]?我建议您删除j循环并仅使用i。如果test是一个列表,请使用test[[i]] <- brick(B5, B7)
标签: r loops for-loop stack raster