[R-sig-Geo] Using "rasterize" with parallel...
Guillermo E. Ponce-Campos
geponce at gmail.com
Thu Sep 18 21:41:36 CEST 2014
GetXYfromRaster <- function (vraster.template, vshp.file, vext) {
if (nchar(vshp.file) < 1) {
vshp.file <- tk_choose.files(caption="Select shapefile...")
vshp.file <- readShapeSpatial(vshp.file)
} else {
vshp.file <- readShapeSpatial(vshp.file)
}
## Cluster for parallelization
cl <- makeCluster(detectCores()-2)
registerDoParallel(cl)
if (nchar(vraster.template) < 1) {
vraster.template <- tk_choose.files(caption="Select raster template...")
mc <- foreach (i = 1:1, .packages = "raster") %dopar% {
vraster.template <- raster(vraster.template)
vraster.template <- crop (vraster.template, vext)
}
} else {
mc <- foreach (i = 1:1, .packages = "raster") %dopar% {
vraster.template <- raster(vraster.template)
vraster.template <- crop (vraster.template, vext)
}
}
mc <- foreach (i = 1:1, .packages = "raster") %dopar% {
vshp.crop <- crop(vshp.file, vraster.template)
vrasterized <- rasterize(vshp.crop, vraster.template, field="OBJECTID")
}
vxy.coords <- coordinates(vrasterized)
stopCluster(cl)
return (as.data.frame(vxy.coords))
}
I'm getting the following error when I call that function...
Error in { :
task 1 failed - "unable to find an inherited method for function extent
for signature "character""
Doing the traceback, the error comes from the call to "rasterize". Is it
possible to use rasterize in this way?
Any hint?
Guillermo
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list