as.SpatRaster: as.SpatRaster

View source: R/as.SpatRaster.R

as.SpatRasterR Documentation

as.SpatRaster

Description

Convert magclass object to a SpatRaster object. Requires the terra package.

Usage

as.SpatRaster(x, res = NULL)

Arguments

x

MAgPIE object

res

spatial data resolution. If not provided it will be guessed.

Value

A SpatRaster object

Author(s)

Jan Philipp Dietrich

See Also

getCoords

Examples


if (requireNamespace("terra", quietly = TRUE)) {
   r <- terra::rast(ncols = 360, nrows = 180, nl = 4)
   r[85:89, 176:179] <- (1:20 %*% t(1:4))
   r[15:19, 76:79] <-   (10 + 1:20 %*% t(1:4))
   names(r) <- c("y2000..bla", "y2001..bla", "y2000..blub", "y2001..blub")
   m <- as.magpie(r)
   r2 <- as.SpatRaster(m)
}

magclass documentation built on May 29, 2024, 6:20 a.m.