Terra 相当于 raster::stack()?

Nat*_*iel 9 gis r raster terra

基本上就是标题。我知道您可以使用 rast() 读取栅格文件夹,但我只想堆叠两个单独读取的栅格。谢谢

Mat*_*fou 13

请注意,对于raster::stack,您可以在多个参数 ( stack(x1,x2,x3)) 或列表 ( stack(list(x1,x2, x3))) 上使用它。

对于 terra 来说,情况不再如此c。您需要区分:

  • c(x1, x2, x3)提供单独的参数时使用
  • rast(list(x1,x2,x3))以列表形式提供参数时使用。
library(terra)
#> terra 1.5.21

x <- rast(xmin=-110, xmax=-80, ymin=40, ymax=70, ncols=30, nrows=30)
values(x) <- 1:ncell(x)

many_rasters <- list(x,x)

## this works
rast( many_rasters)
#> class       : SpatRaster 
#> dimensions  : 30, 30, 2  (nrow, ncol, nlyr)
#> resolution  : 1, 1  (x, y)
#> extent      : -110, -80, 40, 70  (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 
#> sources     : memory  
#>               memory  
#> names       : lyr.1, lyr.1 
#> min values  :     1,     1 
#> max values  :   900,   900

## just using c creates a list
c(many_rasters)
#> [[1]]
#> class       : SpatRaster 
#> dimensions  : 30, 30, 1  (nrow, ncol, nlyr)
#> resolution  : 1, 1  (x, y)
#> extent      : -110, -80, 40, 70  (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 
#> source      : memory 
#> name        : lyr.1 
#> min value   :     1 
#> max value   :   900 
#> 
#> [[2]]
#> class       : SpatRaster 
#> dimensions  : 30, 30, 1  (nrow, ncol, nlyr)
#> resolution  : 1, 1  (x, y)
#> extent      : -110, -80, 40, 70  (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 
#> source      : memory 
#> name        : lyr.1 
#> min value   :     1 
#> max value   :   900
Run Code Online (Sandbox Code Playgroud)


小智 6

对于有此问题的未来用户,请注意terra::c()返回

错误:“c”不是从“namespace:terra”导出的对象

要堆叠栅格,terra您可以简单地使用 base c()


小智 1

我想你想要terra::c()。它组合SpatRaster对象,只要它们具有相同的范围和分辨率。