View source: R/spatial_tools.R
buffer_and_crop | R Documentation |
This function creates a buffer around a spatial object and then crops another spatial object to lie within the extent of the buffered object.
buffer_and_crop(to_buffer, to_crop, buffer = NULL, ...)
to_buffer |
A spatial object to be buffered (see |
to_crop |
A spatial object to be cropped by the buffered object (see |
buffer |
A named list of arguments, passed to |
... |
Additional arguments passed to |
This is a simple wrapper for gBuffer
and crop
. If buffer = NULL
, the function simply implements crop
.
The function returns the to_crop
object, cropped to the extent
of the buffered to_buffer
object.
Edward Lavender
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.