fast_extract {prioritizr} | R Documentation |
Fast extract
Description
Extract data from a terra::rast()
object.
Usage
fast_extract(x, y, ...)
## S4 method for signature 'Raster,Spatial'
fast_extract(x, y, fun = "mean", ...)
## S4 method for signature 'Raster,sfc'
fast_extract(x, y, fun = "mean", ...)
## S4 method for signature 'SpatRaster,sfc'
fast_extract(x, y, fun = "mean", ...)
## S4 method for signature 'Raster,sf'
fast_extract(x, y, fun = "mean", ...)
## S4 method for signature 'SpatRaster,sf'
fast_extract(x, y, fun = "mean", ...)
Arguments
x |
|
y |
|
... |
not used. |
fun |
|
Details
The performance of this function for large terra::rast()
objects
can be improved by increasing the GDAL cache size.
The default cache size is 25 MB.
For example, the following code can be used to set the cache size to 4 GB.
terra::gdalCache(size = 4000)
This function is simply a wrapper that uses
exactextractr::exact_extract()
for polygon geometries, and
terra::extract()
for other geometry types.
Value
A matrix
containing the summary amount of each feature
within each planning unit. Rows correspond to different spatial features
in the argument to y
and columns correspond to different raster
layers in the argument to x
.
See Also
terra::extract()
, exactextractr::exact_extract()
.
Examples
# load data
sim_pu_polygons <- get_sim_pu_polygons()
sim_features <- get_sim_features()
# extract data
result <- fast_extract(sim_features, sim_pu_polygons)
# show result
print(head(result))