#' @title Reclassify a raster object
#' @description Divide values of a raster object into bins of a given width.
#' @param x A raster object.
#' @param binwidth The width of the bins.
#' @param right Should bin intervals be closed on the right? See [`terra::classify()`] for details.
#' @param col_name Name of the classified variable.
#' @param ... Other arguments passed to [`terra::classify()`].
#' @export
rs_reclass <- function(x, binwidth = 100, right = FALSE, col_name = "zone", ...) {
min <- round_nearest(terra::minmax(x)[1], -binwidth)
max <- round_nearest(terra::minmax(x)[2], -binwidth)
s <- seq(min, max, binwidth)
new_values <- tibble(lower = s, upper = s + binwidth, new = s)
x <- terra::classify(x, new_values, right = right, ...)
setNames(x, col_name)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.