# Create a SpatRaster from scratch
x <- rast(nrows=108, ncols=21, xmin=0, xmax=10)
# Create a SpatRaster from a file
f <- system.file("ex/elev.tif", package="terra")
r <- rast(f)
# A file with multiple layers. This one is special as the layers are RGB color channels
s <- rast(system.file("ex/logo.tif", package="terra"))
# remove the color channels
#plot(s)
#RGB(s) <- NULL
#plot(s)
# Create a skeleton with no associated cell values
rast(s)
# from a matrix
m <- matrix(1:25, nrow=5, ncol=5)
rm <- rast(m)
# from a "xyz" data.frame
d <- as.data.frame(rm, xy=TRUE)
head(d)
rast(d, type="xyz")
Run the code above in your browser using DataLab