R: Active category

activeCat {terra} | R Documentation

## Active category

### Description

Get or set the active category of a multi-categorical SpatRaster layer

### Usage

    ## S4 method for signature 'SpatRaster'
    activeCat(x, layer=1)
    ## S4 replacement method for signature 'SpatRaster'
    activeCat(x, layer=1)<-value

### Arguments

`x` | SpatRaster
`layer` | positive integer, the layer number or name
`value` | a data.frame (ID, category) or vector with category names

### Value

integer

### See Also

`catalyze`, `cats`

### Examples

    set.seed(0)
    r <- rast(nrows=10, ncols=10)
    values(r) <- sample(3, ncell(r), replace=TRUE) + 10
    d <- data.frame(id=11:13, cover=c("forest", "water", "urban"), letters=letters[1:3], value=10:12)
    levels(r) <- d

    activeCat(r)
    activeCat(r) <- 3
    activeCat(r)

[Package terra version 1.3-22 Index]