0

I'm trying to create an intersection between two layers but, because of their size, st_intersection can't be done in one ony execution. I'm trying to do so spliting the process in parallel so this is what I do (this works):

library(sf)
library(mapview)
library(doParallel)

GP <- st_make_valid(st_read('./capas/GP/GP.shp'))
UP <- st_make_valid(st_read('./capas/UP/UP.shp'))

# CONFIG PARALLEL
cl <- parallel::makeCluster(detectCores(), type="FORK")
doParallel::registerDoParallel(cl)
ls <- foreach(i=1:nrow(GP)) %dopar% {
        st_intersection(GP[i,], UP) %>% 
                mutate(Name = paste0(GranArea,'; ',LABEL)) %>% 
                group_by(Name) %>% 
                summarise()
}
stopCluster(cl)

# MERGE 
GPUP <- do.call(rbind,ls)

My question is: how can I write the same process using parlapply?

Here are the layers.

1
  • 1
    You could also try future.apply package functions. I find them easy to use, basically the same as the various apply functions, and quite efficient. – Jeffrey Evans Feb 8 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.