extract_at {chopin} | R Documentation |
Extract raster values with point buffers or polygons
Description
Extract raster values with point buffers or polygons
Usage
extract_at(x, y, ...)
## S4 method for signature 'SpatRaster,sf'
extract_at(
x = NULL,
y = NULL,
id = NULL,
func = "mean",
extent = NULL,
radius = NULL,
out_class = "sf",
kernel = NULL,
kernel_func = stats::weighted.mean,
bandwidth = NULL,
max_cells = 3e+07,
.standalone = TRUE,
...
)
## S4 method for signature 'character,character'
extract_at(
x = NULL,
y = NULL,
id = NULL,
func = "mean",
extent = NULL,
radius = NULL,
out_class = "sf",
kernel = NULL,
kernel_func = stats::weighted.mean,
bandwidth = NULL,
max_cells = 3e+07,
.standalone = TRUE,
...
)
## S4 method for signature 'SpatRaster,character'
extract_at(
x = NULL,
y = NULL,
id = NULL,
func = "mean",
extent = NULL,
radius = NULL,
out_class = "sf",
kernel = NULL,
kernel_func = stats::weighted.mean,
bandwidth = NULL,
max_cells = 3e+07,
.standalone = TRUE,
...
)
## S4 method for signature 'SpatRaster,SpatVector'
extract_at(
x = NULL,
y = NULL,
id = NULL,
func = "mean",
extent = NULL,
radius = NULL,
out_class = "sf",
kernel = NULL,
kernel_func = stats::weighted.mean,
bandwidth = NULL,
max_cells = 3e+07,
.standalone = TRUE,
...
)
## S4 method for signature 'character,sf'
extract_at(
x = NULL,
y = NULL,
id = NULL,
func = "mean",
extent = NULL,
radius = NULL,
out_class = "sf",
kernel = NULL,
kernel_func = stats::weighted.mean,
bandwidth = NULL,
max_cells = 3e+07,
.standalone = TRUE,
...
)
## S4 method for signature 'character,SpatVector'
extract_at(
x = NULL,
y = NULL,
id = NULL,
func = "mean",
extent = NULL,
radius = NULL,
out_class = "sf",
kernel = NULL,
kernel_func = stats::weighted.mean,
bandwidth = NULL,
max_cells = 3e+07,
.standalone = TRUE,
...
)
Arguments
x |
|
y |
|
... |
Placeholder. |
id |
character(1). Unique identifier of each point. |
func |
function taking one numeric vector argument.
Default is |
extent |
numeric(4) or SpatExtent. Extent of clipping vector.
It only works with |
radius |
numeric(1). Buffer radius. |
out_class |
character(1). Output class. One of |
kernel |
character(1). Name of a kernel function
One of |
kernel_func |
function.
Kernel function to apply to the extracted values.
Default is |
bandwidth |
numeric(1). Kernel bandwidth. |
max_cells |
integer(1). Maximum number of cells in memory. |
.standalone |
logical(1). Default is |
Details
Inputs are preprocessed in different ways depending on the class.
Vector inputs in
y
:sf
is preferred, thus character andSpatVector
inputs will be converted tosf
object. Ifradius
is not NULL,sf::st_buffer
is used to generate circular buffers as subsequent raster-vector overlay is done withexactextractr::exact_extract
.Raster input in
x
:SpatRaster
is preferred. If the input is notSpatRaster
, it will be converted toSpatRaster
object.
Value
A data.frame object with summarized raster values with respect to the mode (polygon or buffer) and the function.
Author(s)
Insang Song geoissong@gmail.com
See Also
Other Macros for calculation:
kernelfunction()
,
summarize_aw()
,
summarize_sedc()
Examples
ncpath <- system.file("gpkg/nc.gpkg", package = "sf")
rastpath <- file.path(tempdir(), "test.tif")
nc <- terra::vect(ncpath)
nc <- terra::project(nc, "EPSG:5070")
rrast <- terra::rast(nc, nrow = 300, ncol = 660)
terra::values(rrast) <- rgamma(1.98e5, 4, 2)
rpnt <- terra::spatSample(rrast, 16L, as.points = TRUE)
rpnt$pid <- sprintf("ID-%02d", seq(1, 16))
extract_at(rrast, rpnt, "pid", "mean", radius = 1000)
extract_at(rrast, nc, "NAME", "mean")
extract_at(rrast, ncpath, "NAME", "mean")
# Using SpatRaster object
suppressWarnings(
extract_at(
rrast, ncpath, "NAME", "mean",
kernel = "epanechnikov",
bandwidth = 1e5
)
)
# Using raster path
terra::writeRaster(rrast, rastpath, overwrite = TRUE)
suppressWarnings(
extract_at(
rastpath, ncpath, "NAME", "mean",
kernel = "epanechnikov",
bandwidth = 1e5
)
)