Extract data from a Raster object.

fast_extract(x, y, ...)

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

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

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

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

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

Arguments

x

Raster object.

y

Spatial or 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".

Value

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.

Details

This function is simply a wrapper that uses raster::extract() to extract data for SpatialPoints and SpatialLines and non-polygonal sf::sf() data, and exactextractr::exact_extract() for SpatialPolygons and polygonal sf::sf() data.

See also

Examples

# load data
data(sim_pu_sf, sim_features)

# extract data
result <- fast_extract(sim_features, sim_pu_sf)

# show result
print(head(result))
#>           [,1]      [,2]      [,3]      [,4]      [,5]
#> [1,] 0.7150548 0.2900901 0.8178213 0.2199663 0.4533809
#> [2,] 0.6990429 0.3052216 0.8064534 0.2713800 0.4413639
#> [3,] 0.6859317 0.3266036 0.7852441 0.3296247 0.4343547
#> [4,] 0.6783193 0.3510977 0.7541320 0.3900085 0.4355628
#> [5,] 0.6782107 0.3750470 0.7131559 0.4468281 0.4474871
#> [6,] 0.6863252 0.3950113 0.6628435 0.4946333 0.4714105