[英]Terra equivalent for raster::stack()?
Basically the title.基本上是标题。 I know you can read in a folder of rasters with rast() but I just want to stack two rasters that are read in separately.
我知道您可以使用 rast() 读取光栅文件夹,但我只想堆叠两个单独读取的光栅。 Thanks
谢谢
Note that with raster::stack
, you were able to use it either on multiple arguments ( stack(x1,x2,x3)
) or on a list ( stack(list(x1,x2, x3))
).请注意,对于
raster::stack
,您可以在多个 arguments ( stack(x1,x2,x3)
) 或列表 ( stack(list(x1,x2, x3))
) 上使用它。
This is no longer true with terra's c
.这不再适用于 terra 的
c
。 You need to differentiate:你需要区分:
c(x1, x2, x3)
when providing separate argumentsc(x1, x2, x3)
rast(list(x1,x2,x3))
when providing the arguments as a list.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
For future users with this question note that terra::c()
returns对于有此问题的未来用户,请注意
terra::c()
返回
Error: 'c' is not an exported object from 'namespace:terra'
错误:'c' 不是从 'namespace:terra' 导出的 object
To stack rasters in terra
you can simply use base c()
.要在
terra
中堆叠栅格,您可以简单地使用 base c()
。
I think you want terra::c()
.我想你想要
terra::c()
。 It combines SpatRaster
objects, as long as they have the same extent and resolution.它组合
SpatRaster
对象,只要它们具有相同的范围和分辨率。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.