Learn R Programming

terra (version 0.2-9)

rast: Create a SpatRaster

Description

Methods to create a SpatRaster. These objects can be created from scratch or from a file.

A SpatRaster represents a spatially referenced surface divided into three dimensional cells (rows, columns, and layers).

When a SpatRaster is created from a file, it does (initially) not contain any cell (pixel) values in memory (RAM), it only has the parameters that describe the SpatRaster. You can access cell-values with values.

Usage

# S4 method for character
rast(x, ...)

# S4 method for missing rast(x, nrows=180, ncols=360, nlyrs=1, xmin=-180, xmax=180, ymin=-90, ymax=90, crs, extent, resolution, ...)

# S4 method for SpatRaster rast(x, nlyrs=nlyr(x), ...)

# S4 method for SpatVector rast(x, nrows=10, ncols=10, nlyrs=1, ...) # S4 method for SpatExtent rast(x, nrows=10, ncols=10, nlyrs=1, crs="", ...)

# S4 method for Raster rast(x, ...)

Arguments

x

filename (character), Extent, SpatRaster, matrix, array, or Raster* object (from the "raster" package). Can also be missing

nrows

positive integer. Number of rows

ncols

positive integer. Number of columns

nlyrs

positive integer. Number of layers

xmin

minimum x coordinate (left border)

xmax

maximum x coordinate (right border)

ymin

minimum y coordinate (bottom border)

ymax

maximum y coordinate (top border)

extent

object of class SpatExtent. If present, the arguments xmin, xmax, ymin and ymax are ignored

crs

character. PROJ.4 type description of a Coordinate Reference System (map projection). If this argument is missing, and the x coordinates are within -360 .. 360 and the y coordinates are within -90 .. 90, "+proj=longlat +datum=WGS84" is used

resolution

numeric vector of length 1 or 2 to set the resolution (see res). If this argument is used, arguments ncol and nrow are ignored

...

Additional arguments. None implemented

Value

SpatRaster

Examples

Run this code
# NOT RUN {
# Create a SpatRaster from scratch
x <- rast(nrow=108, ncol=21, xmin=0, xmax=10)

# Create a SpatRaster from a file
f <- system.file("exdata/test.tif", package="terra")
r <- rast(f)

s <- rast(system.file("exdata/logo.grd", package="terra"))   

# Create a skeleton with no associated cell values
rast(s)
# }

Run the code above in your browser using DataLab