Learn R Programming

terra (version 0.2-9)

values: Get cell values

Description

values returns all cell values of a SpatRaster.

Usage

# S4 method for SpatRaster
values(x, mat=TRUE, ...)
# S4 method for SpatRaster
values(x,...)<-value

Arguments

x

SpatRaster

mat

logical. If TRUE, values are returned as a matrix instead of as a vector

value

matrix or numeric, the length must match the total number of cells (ncell(x) * nlyr(x)), or be a single value

...

additional arguments. none implemented

Value

matrix or vector

Details

If matrix=TRUE, a matrix is returned in which the values of each layer are represented by a column (with ncell(x) rows). The values per layer are in cell-order, that is, from top-left, to top-right and then down by row. Use as.matrix for an alternative matrix representation where the number of rows and columns matches that of x, if x has a single layer. If matrix=FALSE, the values are returned as a vector. In cell-order by layer.

Examples

Run this code
# NOT RUN {
r <- rast(system.file("exdata/test.tif", package="terra"))
r
v <- values(r)
values(r) <- v * 10
r
# }

Run the code above in your browser using DataLab