I am trying to do a point-in-poly analysis using R. I have 4.5 million points and 5k polygons. This is computationally intensive. I was pointed to parallel processing through another post and tried to run point.in.poly through parallel processing.
Without parallel
table1 = point.in.poly(spdf, all_polygons)
With parallel
library(foreach)
library(doParallel)
nrow = nrow(spdf)
registerDoParallel(makeCluster(no_cores - 1))
ptm <- proc.time()
foreach(i=1:nrow, .combine = rbind) %dopar% {
table1 = point.in.poly(spdf, all_polygons)
getValues(table1)
}
proc.time() - ptm
endCluster()
Without parallel results in about 7 minute processing time for a 100k subset. With parallel takes longer, then freezes and crashed my computer. Note that I am on a four core computer.
How might I speed up this function? Without parallel processing, my rough estimation is that this process could take 6 hours.