buffer_and_crop: Buffer and crop a spatial object

View source: R/spatial_tools.R

buffer_and_cropR Documentation

Buffer and crop a spatial object

Description

This function creates a buffer around a spatial object and then crops another spatial object to lie within the extent of the buffered object.

Usage

buffer_and_crop(to_buffer, to_crop, buffer = NULL, ...)

Arguments

to_buffer

A spatial object to be buffered (see gBuffer).

to_crop

A spatial object to be cropped by the buffered object (see crop).

buffer

A named list of arguments, passed to gBuffer to buffer the to_buffer object (e.g., buffer = list(width = 10)).

...

Additional arguments passed to crop.

Details

This is a simple wrapper for gBuffer and crop. If buffer = NULL, the function simply implements crop.

Value

The function returns the to_crop object, cropped to the extent of the buffered to_buffer object.

Author(s)

Edward Lavender

Examples

# Define an example raster
nrw <- ncl <- 50
r <- raster::raster(nrow = nrw, ncol = ncl)
r[] <- stats::runif(nrw * ncl, 0, 1)
# Buffer and crop the raster around an example location
xy <- sp::SpatialPoints(matrix(c(0, 0), ncol = 2))
r2 <- buffer_and_crop(
  to_buffer = xy,
  to_crop = r,
  buffer = list(width = 10)
)
# Visualise outputs
pp <- par(mfrow = c(1, 2))
raster::plot(r)
raster::plot(r2)
par(pp)


edwardlavender/flapper documentation built on Jan. 22, 2025, 2:44 p.m.