Skip to content
Prev 20454 / 29559 Next

ifelse with multiple rasters

Laura:

If this is a straight masking procedure, you can do some
multiplication tricks in raster like:

output = rst_a*rst_B*2

or look at
?overlay

or take a look at
?mask

I suspect mask and overlay are faster than the raster algebra
statement (Robert, is this correct?)

If you want to use rasterEngine for parallel processing, you can do
something like this:

library(spatial.tools)

# Set X to the number of CPUs you want top use and uncomment this for
parallel processing:
# sfQuickInit(cpus=X)

rst_test <- function(rst_a,rst_B)
{
return(ifelse(rst_a==0 & rst_B==1,2,0))
}

# Fill in the rasters you intend to use here:
raster_check <-
rasterEngine(rst_a=someraster,rst_B=someotherraster,fun=rst_test)

# Uncomment to stop the parallel engine if need be:
# sfQuickStop()

--j
On Mon, Feb 24, 2014 at 8:16 AM, Laura Poggio <laura.poggio at gmail.com> wrote: