【问题标题】:How to loop through raster brick?如何循环穿过光栅砖?
【发布时间】:2021-06-05 00:57:45
【问题描述】:

我有一块 SCA(nrow=108,ncol=132,nlayers=365) 的栅格砖,其中包含部分积雪。我想从中制作 8 层中的每层 46 层,并从这 46 层中计算最大部分积雪。我该怎么做?

【问题讨论】:

    标签: raster


    【解决方案1】:

    我想你可能想这样做:

    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,尽量避免循环)你可以这样做

    for (i in 1:nlayers(sca)) {
        x <- sca[[i]]
        # etc.
    }
    

    【讨论】:

      猜你喜欢
      • 2017-07-20
      • 2023-03-17
      • 1970-01-01
      • 2016-12-25
      • 2022-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多