R/internal.R

Defines functions is_binary_raster

#' Is a binary raster?
#'
#' Check if [terra::rast()] raster object contains binary values.
#'
#' @param x [terra::rast()] Raster object.
#'
#' @return `logical` value indicating if raster contains binary values.
#'
#' @noRd
is_binary_raster <- function(x) {
  assertthat::assert_that(inherits(x, "SpatRaster"))
  terra::global(x, function(x) {
    x <- x[is.finite(x)]
    all(x == 0 | x == 1)
  })[[1]]
}

Try the restoptr package in your browser

Any scripts or data that you put into this service are public.

restoptr documentation built on Aug. 12, 2025, 1:08 a.m.