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)