Learn R Programming

terra (version 0.2-8)

reclassify: Reclassify

Description

Reclassify values of a SpatRaster. The function (re)classifies groups of values to other values.

Reclassification can be based on ranges (from-to-becomes) or on specific values (is-becomes).

Reclassification is done with matrix rcl, in the row order of the reclassify table. Thus, if there are overlapping ranges or values, the first time a number is within a range determines the reclassification value.

Usage

# S4 method for SpatRaster
reclassify(x, rcl, include.lowest=FALSE, right=TRUE, othersNA=FALSE, filename="", overwrite=FALSE, wopt=list(), ...)

Arguments

x

Raster* object

rcl

matrix for reclassification. This matrix must have 2 or 3 columns. If there are three columns, the first two columns are "from" "to" of the input values, and the third column "becomes" has the new value for that range. You can also supply a vector that is then coverted into a 3 column matrix with byrow=TRUE. The two column matrix ("is", "becomes") can be useful for reclassifying integer values. In that case, the right argument is automatically set to NA

include.lowest

logical, indicating if a value equal to the lowest value in rcl (or highest value in the second column, for right=FALSE) should be included.

right

logical, indicating if the intervals should be closed on the right (and open on the left) or vice versa. The default is TRUE. A special case is to use right=NA. In this case both the left and right intervals are open

othersNA

logical. If TRUE, values that are not matched become NA. If FALSE, they retain their original value.

filename

character. Output filename. Optional

overwrite

logical. If TRUE, filename is overwritten

wopt

list. Options for writing files as in writeRaster

...

additional arguments. None implemented

Value

SpatRaster

Examples

Run this code
# NOT RUN {
r <- rast(ncols=10, nrows=10)
values(r) <- runif(ncell(r)) 
# reclassify the values into three groups 
# all values >= 0 and <= 0.25 become 1, etc.
m <- c(0, 0.25, 1,  0.25, 0.5, 2,  0.5, 1, 3)
rclmat <- matrix(m, ncol=3, byrow=TRUE)
rc <- reclassify(r, rclmat)

# equivalent to
rc <- reclassify(r, c(-Inf,0.25,1, 0.25,0.5,2, 0.5,Inf,3))

# is becomes 
x <- round(r*5)
unique(x)
m <- rbind(c(1,100), c(2,200))
m
rcx1 <- reclassify(x, m)
unique(rcx1)
rcx2 <- reclassify(x, m, othersNA=TRUE)
unique(rcx2)

# }

Run the code above in your browser using DataLab