cv.2.rast: Class vector to raster

View source: R/helperFunctions.R

cv.2.rastR Documentation

Class vector to raster

Description

Transform a class vector or a generic vector into a raster.

Usage

cv.2.rast(
  r,
  classVector,
  index = NULL,
  plot = FALSE,
  type = "classes",
  writeRaster = NULL,
  overWrite = FALSE
)

Arguments

r

raster object.

classVector

numeric vector, the values to be assigned to the cell numbers indicated by index.

index

numeric vector, the cell numbers of the argument r to which assign the values of the argument classVector. If NULL, the column Cell of the attribute table attTbl(r) is used (see attTbl).

plot

logic, plot the raster.

type

character, type of map/legend. One of "continuous", "classes", or "interval".

writeRaster

filename, if a raster name is provided save the raster to a file.

overWrite

logic, if the raster names already exist, the existing file is overwritten.

Details

The arguments index and vector need to have the same length. The function assign the values of vector at the positions of index to an empty raster having the same spatial properties of the raster r.

Value

A class vector or a generic vector transformed into a raster.

Examples

library(scapesClassification)
library(terra)

# LOAD THE DUMMY RASTER
r <- list.files(system.file("extdata", package = "scapesClassification"),
                pattern = "dummy_raster\\.tif", full.names = TRUE)
r <- terra::rast(r)

# COMPUTE THE ATTRIBUTE TABLE
at <- attTbl(r, "dummy_var")

# COMPUTE THE LIST OF NEIGBORHOODS
nbs <- ngbList(r)

# Compute an example class vector
cv <- cond.4.all(attTbl = at, cond = "dummy_var > 1", class = 1)

# Class vector to raster
cv.2.rast(r, cv, plot = TRUE)
text(r) # add raster values

scapesClassification documentation built on March 18, 2022, 6:32 p.m.