TransWikia.com

How to use parallel parlapply for features whithin an sf object

Geographic Information Systems Asked by César Arquero on February 12, 2021

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.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP