【问题标题】:In R create maximum raster from mulitple raster files在 R 中,从多个栅格文件创建最大栅格
【发布时间】:2015-09-13 04:56:39
【问题描述】:

我是新的 R,所以也许这是一个愚蠢的问题,但我自己无法弄清楚。

这是我的问题。 我有多个具有相同网格大小并覆盖相同区域的 asc 文件。我想从所有 asc 文件中获取每个网格的最大值。 我尝试了多种方法:

   for (i in 1:144){
    asc0<-rasterToPoints(raster(asc0))
        asc1<-rasterToPoints(raster(asc[i]))
        asc0[,3] <-pmax(asc0[,3], asc1[,3])
    }

当我循环抛出文件时,这个失败,因为它遗漏了 NA,所以我的 asc0(我的基本文件)的大小与我的下一个文件 asc1[2] 的大小不同。

有没有人知道这个方法?我已经准备好循环遍历所有文件,有 13x144 个文件。 但我想不出一种方法来获取最大值、存储它并与下一个文件进行比较。

非常感谢您的帮助!!!

【问题讨论】:

    标签: r ascii r-raster


    【解决方案1】:

    使用stackmax

    r1 <- r2 <- r3 <- raster(nrows=10, ncols=10, xmn=0, xmx=10, ymn=0, ymx=10)
    r1[] <- 1   # raster with 1
    r2[] <- 2   # raster with 2
    r3[] <- 3   # raster with 3
    s1 <- stack(r1, r2, r3)
    s1
    #class       : RasterStack 
    #dimensions  : 10, 10, 100, 3  (nrow, ncol, ncell, nlayers)
    #resolution  : 1, 1  (x, y)
    #extent      : 0, 10, 0, 10  (xmin, xmax, ymin, ymax)
    #coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
    #names       : layer.1, layer.2, layer.3 
    #min values  :       1,       2,       3    <- values between 1 and 3
    #max values  :       1,       2,       3    <- values between 1 and 3
    
    max(s1)
    #class       : RasterLayer 
    #dimensions  : 10, 10, 100  (nrow, ncol, ncell)
    #resolution  : 1, 1  (x, y)
    #extent      : 0, 10, 0, 10  (xmin, xmax, ymin, ymax)
    #coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
    #data source : in memory
    #names       : layer 
    #values      : 3, 3  (min, max)   <- 3 only
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-20
      • 2019-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-13
      • 1970-01-01
      相关资源
      最近更新 更多