Learn R Programming

prioritizr (version 8.0.6)

fast_extract: Fast extract

Description

Extract data from a terra::rast() object.

Usage

fast_extract(x, y, ...)

# S4 method for Raster,Spatial fast_extract(x, y, fun = "mean", ...)

# S4 method for Raster,sfc fast_extract(x, y, fun = "mean", ...)

# S4 method for SpatRaster,sfc fast_extract(x, y, fun = "mean", ...)

# S4 method for Raster,sf fast_extract(x, y, fun = "mean", ...)

# S4 method for SpatRaster,sf fast_extract(x, y, fun = "mean", ...)

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.

Arguments

x

terra::rast() object.

y

sf::sf() object.

...

not used.

fun

character name of statistic to summarize data. Defaults to "mean". Available options include "sum" or "mean". Defaults to "mean".

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.

See Also

terra::extract(), exactextractr::exact_extract().

Examples

Run this code
# 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))

Run the code above in your browser using DataLab