#' Paralellized extraction
#'
#' @param instack Raster stack
#' @param samples samples
#' @param ncores Number of cores used for paralellization
#'
#' @return Table with extracted values
#' @export
extract_parallel <- function(x, samples, n_cores){
x_unstack <- raster::unstack(x)
cl <- parallel::makeCluster(n_cores)
doParallel::registerDoParallel(cl)
ext_list <- foreach::foreach(i = x_unstack,
.packages = "raster") %dopar% {
raster::extract(i, samples)
}
out <- do.call(cbind, ext_list)
colnames(out) <- names(x)
return(out)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.