[R-sig-Geo] rasterize in parrallel
Jérome Mathieu
jerome.mathieu at upmc.fr
Tue Jul 14 00:03:04 CEST 2015
Dear all,
I need to rasterize the same shapefile according to different fields stored
in the @data of the shapefile. So I need to loop trough the fields (named
sc1 to sc27) to rasterize upon each field. With a regular sequential loop
it takes a very long time (much longer than in ArcMap), so I would like to
parallelize it, but I didn't succeed so far.
I tried :
# read shapefile
library(maptools)
polyg<-readShapePoly("D:\\polyg.shp")
polyg at proj4string <- CRS("+init=epsg:2154")
library(doParallel)
cl <- makeCluster(4)
registerDoParallel(cl)
grain<-50
nsc<-4
foreach(idxsc = 1 : nsc , .packages="raster", polyg=polyg) %dopar% {
eval(parse(text=paste("RRpolyg_",idxsc,"<-raster(polyg,res=c(grain,grain))",sep="")))
# create raster template
eval(parse(text=paste("projection(RRpolyg_",idxsc,") <-
proj4string(polyg)",sep=""))) # projection
eval(parse(text=paste("RRpolyg_",idxsc,"<-rasterize(polyg,RRpolyg_",idxsc,",field=polyg at data$sc",idxsc,")",sep="")))
# rasterization
}
stopCluster(cl)
and I get the following error :
Error in { :
task 1 failed - "unable to find an inherited method for function 'raster'
for signature '"numeric"'"
the data are here
http://we.tl/7qqegfLoBA
Any help would be greatly appreciated !
Jerome
> sessionInfo()
R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252
LC_MONETARY=French_France.1252 LC_NUMERIC=C
LC_TIME=French_France.1252
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods
base
other attached packages:
[1] rgeos_0.3-11 rgdal_0.9-2 maptools_0.8-36 lattice_0.20-31
foreign_0.8-63 raster_2.3-40 sp_1.1-0 doParallel_1.0.8
iterators_1.0.7 foreach_1.4.2
loaded via a namespace (and not attached):
[1] codetools_0.2-11 compiler_3.1.3 grid_3.1.3 tools_3.1.3
--
Jérôme Mathieu
Université Pierre & Marie Curie
Institute of Ecology and Environmental Science (Paris)
Bât. A - 7ème Etage, porte 715
7 quai St.-Bernard
F-75252 Paris Cedex 05
tel: 01 44 27 34 22
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list