R/engine_crop.R

Defines functions engine_crop.default engine_crop.Spatial engine_crop.sfc engine_crop.sf engine_crop.SpatRaster engine_crop.stars engine_crop.Raster engine_crop.LAS engine_crop

Documented in engine_crop

#' @rdname engine
#' @export
#' @param x LAS, Raster, stars, SpatRaster,sf, sfc, Spatial
#' @param bbox bbox
engine_crop <- function(x, bbox)
{
  UseMethod("engine_crop", x)
}

#' @export
engine_crop.LAS <- function(x, bbox)
{
  buffer <- NULL
  x <- filter_poi(x, buffer == LIDRNOBUFFER)
  if (is.empty(x)) return(NULL)
  return(x)
}

#' @export
engine_crop.Raster <- function(x, bbox)
{
  return(raster_crop(x, bbox))
}

#' @export
engine_crop.stars <- function(x, bbox)
{
  return(raster_crop(x, bbox))
}

#' @export
engine_crop.SpatRaster <- function(x, bbox)
{
  return(raster_crop(x, bbox))
}

#' @export
engine_crop.sf <- function(x, bbox)
{
  return(sf::st_crop(x, bbox))
}

#' @export
engine_crop.sfc <- function(x, bbox)
{
  return(sf::st_crop(x, bbox))
}

#' @export
engine_crop.Spatial <- function(x, bbox)
{
  x <- sf::st_as_sf(x)
  x <- sf::st_crop(x, bbox)
  return(sf::as_Spatial(x))
}

#' @export
engine_crop.default <- function(x, bbox)
{
  stop(glue::glue("No method for cropping '{class(x)}'. Use catalog_apply instead of catalog_map."), call. = FALSE)
}

Try the lidR package in your browser

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

lidR documentation built on Sept. 11, 2024, 5:21 p.m.