View source: R/helperFunctions.R
cv.2.rast | R Documentation |
Transform a class vector or a generic vector into a raster.
cv.2.rast( r, classVector, index = NULL, plot = FALSE, type = "classes", writeRaster = NULL, overWrite = FALSE )
r |
raster object. |
classVector |
numeric vector, the values to be assigned to the cell
numbers indicated by |
index |
numeric vector, the cell numbers of the argument |
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. |
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
.
A class vector or a generic vector transformed into a raster.
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.