-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffer_and_crop.Rd
48 lines (44 loc) · 1.58 KB
/
buffer_and_crop.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/spatial_tools.R
\name{buffer_and_crop}
\alias{buffer_and_crop}
\title{Buffer and crop a spatial object}
\usage{
buffer_and_crop(to_buffer, to_crop, buffer = NULL, ...)
}
\arguments{
\item{to_buffer}{A spatial object to be buffered (see \code{\link[rgeos]{gBuffer}}).}
\item{to_crop}{A spatial object to be cropped by the buffered object (see \code{\link[raster]{crop}}).}
\item{buffer}{A named list of arguments, passed to \code{\link[rgeos]{gBuffer}} to buffer the \code{to_buffer} object (e.g., \code{buffer = list(width = 10)}).}
\item{...}{Additional arguments passed to \code{\link[raster]{crop}}.}
}
\value{
The function returns the \code{to_crop} object, cropped to the \code{\link[raster]{extent}} of the buffered \code{to_buffer} 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.
}
\details{
This is a simple wrapper for \code{\link[rgeos]{gBuffer}} and \code{\link[raster]{crop}}. If \code{buffer = NULL}, the function simply implements \code{\link[raster]{crop}}.
}
\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)
}
\author{
Edward Lavender
}