[R-sig-Geo] Raster in parallel computing?

Camilo Mora cmora at dal.ca
Wed Jan 8 22:32:28 CET 2014


Thank you very much all for your help on this.

A functional code to "resample" many rasters is below. It takes about  
three seconds to resample 1000 rasters. This functionality in R is  
pretty amazing, really.


library (raster)
library(doParallel)
library(foreach)

#creates 3 test rasters
r <- raster(nrow=3, ncol=3)
v <- sapply(1:1000, function(i) setValues(r, runif(ncell(r))))
s <- raster(nrow=10, ncol=10)

#cluster
cl <- makeCluster(detectCores()-2)    #create a cluster
registerDoParallel(cl)                #register the cluster

#code to be clustered
x <- foreach(i = 1:length(v), .packages = "raster") %dopar% {
resamp <- resample(v[[i]], s, method='bilinear')
}

ss <- brick(x)

#stop the cluster
stopCluster(cl)



More information about the R-sig-Geo mailing list