class_map | R Documentation |
Classify a raster image based on table of identified colour thresholds.
class_map(in.raster, colour.table = NULL, errors = 0, exceptions = NULL, plot.raster = FALSE, raster.summary = FALSE, return.raster=FALSE, save.raster = FALSE, out.file = NULL)
in.raster |
The smoothed SpatRaster to be classified. |
colour.table |
Dataframe containing colour thresholds for different categories. Should either be an output from |
errors |
Integer. Expand the range by n x the standard error within a sample. Higher numbers mean a larger range, but also increase the likelihood and magnitude of overlap between categories. |
exceptions |
Assign those (non-NA) pixels not falling within any colours in the colour table as a specific category string. Defaults to NULL, which can be useful for inspection, but will usually be assigned to a category in the end. |
plot.raster |
Logical. Plots the resulting classification, showing first the input raster, then each category separately, finishing with pixels not assigned to any class. |
raster.summary |
Logical. Print summary statistics describing the number of pixels and area (according to the attributes of the in raster)for each category in the classified raster. |
return.raster |
Logical. Do you want to return the raster as an object into your workspace? If so, you will also need to assign the function to an object, otherwise R will just print the raster information in the console. |
save.raster |
Logical. Do you want to save the resulting raster using |
out.file |
Character. Filepath and name to pass to writeRaster. Include extenstion ".tif" (one f) |
Saves, returns and/or plots the classified raster. Values of raster cells in the output correspond to row numbers in the colour table input, i.e. the category represented by the first row will be 1, the second row 2 etc. Pixels that don't fit into any category (unless specified with 'exceptions') are given 0.
Alistair Auffret and Adam Kimberley
Auffret, A.G., Kimberley, A., et al., 2017, HistMapR: Rapid digitization of historical maps in R, Methods in Ecology and Evolution, doi: 10.1111/2041-210X.12788., Link. GitHub repository.
Hijmans, R.J. (2023) terra: Spatial Data Analysis. R package version 1.7-29, https://CRAN.R-project.org/package=terra.
data.loc <- system.file("data", package="HistMapR")
ras.smoothed <- rast(paste0(data.loc,"/ras.smoothed.tiff"))
col.table <- read.csv(paste0(data.loc,"/col.table.csv"))
class_map(in.raster=ras.smoothed, colour.table = col.table, errors = 5, exceptions = "Forest", plot.raster = TRUE, raster.summary = TRUE, return.raster = FALSE, save.raster = FALSE, out.file = NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.