fast_extract: Fast extract

View source: R/fast_extract.R

fast_extractR Documentation

Fast extract

Description

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

Usage

fast_extract(x, y, fun = "mean")

Arguments

x

terra::rast() object.

y

sf::sf() or sf::st_sfc() object.

fun

character name of statistic to summarize data. 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.

Value

A matrix containing the summary amount of each feature within each planning unit. Rows correspond to different spatial features in y and columns correspond to different raster layers in x.

See Also

The terra::extract() and exactextractr::exact_extract() functions are alternatives for extracting raster data.

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))


prioritizr documentation built on Sept. 24, 2026, 5:07 p.m.