Convert a SpatRaster object into a worldMatrix object or a worldArray object depending on the number of layers of the SpatRaster object.

spatRast2world(raster)

# S4 method for SpatRaster
spatRast2world(raster)

Arguments

raster

SpatRaster object.

Value

WorldMatrix or worldArray object depending on the number of layers of the input raster. Patches value are retained from the raster.

Details

See help("worldMatrix-class") or help("worldArray-class") for more details on the classes.

     If the `SpatRaster` object has only one layer, a `worldMatrix` object

     will be returned. If the `SpatRaster` object has more than one layer,

     layers must have unique names and a `worldArray` object will be returned.



     The number of rows and columns, as well as the cell values of the `raster`

     are kept the same. However, to match the coordinates system and resolution of a

     `worldMatrix` or `worldArray`, the grid is shifted by a 1/2 cell to have

     round coordinate values at the center of the patches and patch size is equal to (1,1).

     The bottom left corner cell coordinates of the `worldMatrix` or `worldArray`

     will be (pxcor = 0, pycor = 0).

Author

Sarah Bauduin

Examples

library(terra)
#> terra 1.7.46
#> 
#> Attaching package: 'terra'
#> The following objects are masked from 'package:NetLogoR':
#> 
#>     patches, wrap
r1 <- rast(xmin = 0, xmax = 10, ymin = 0, ymax = 10, nrows = 10, ncols = 10)
r1[] <- runif(100)
w1 <- spatRast2world(r1)
terra::plot(r1)

plot(w1)


r2 <- rast(xmin = 0, xmax = 10, ymin = 0, ymax = 10, nrows = 10, ncols = 10)
r2[] <- 0
r3 <- c(r1, r2)
names(r3) <- c("layer1", "layer2")
w3 <- spatRast2world(r3)
terra::plot(r3)

plot(w3)