Description Usage Arguments Details Value See Also Examples
Extract data from a Raster-class
object from a
Spatial-class
object using performance enhancing tricks.
1 2 3 4 5 6 7 8 9 | ## S4 method for signature 'Raster,SpatialPolygons'
fast_extract(x, y, fun = mean,
velox = requireNamespace("velox", quietly = TRUE), ...)
## S4 method for signature 'Raster,SpatialLines'
fast_extract(x, y, fun = mean, ...)
## S4 method for signature 'Raster,SpatialPoints'
fast_extract(x, y, fun = mean, ...)
|
x |
|
y |
|
fun |
|
velox |
|
... |
additional arguments passed to |
Spatial analyses will be conducted using the
velox
package if it is installed. Additionally,
multiple threads can be used to speed up computation using the
set_number_of_threads
function.
data.frame
, matrix
, or list
object
depending on the arguments.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # load data
data(sim_pu_polygons, sim_features)
# we will investigate severals ways for extracting values from a raster
# using polygons. Specifically, for each band in the raster,
# for each polygon in the vector layer, calculate the average
# of the cells that are inside the polygon.
# perform the extraction using the standard raster::extract function
system.time({result <- fast_extract(sim_features, sim_pu_polygons)})
# perform extract using the fast_extract function augmented using the
# "velox" package
system.time({result <- fast_extract(sim_features, sim_pu_polygons,
velox = TRUE)})
# perform extract using the fast_extract function with "velox" package
# and using two threads for processing. Note that this might be slower
# due to overheads but should yield faster processing times on larger
# spatial data sets
set_number_of_threads(2)
system.time({result <- fast_extract(sim_features, sim_pu_polygons,
velox = TRUE)})
set_number_of_threads(1)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.