Dear Jonathan,
thank you very much. I will have a closer look to overlay, but I think that
your example with Spatial.tools is the most straightforward for the way I
think... and it can be used with multiple processors.

Thanks

Laura


On 24 February 2014 14:50, Jonathan Greenberg <jgrn@illinois.edu> wrote:

> 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@gmail.com>
> wrote:
> > Dear list,
> > I am struggling to find a way to do a simple if statement with multiple
> > rasters in raster.
> >
> > For example:
> > ifelse(rst_a==0 & rst_B=1,2,0)
> >
> > Which is the simplest and most efficient way to implement it? especially
> > when considering large (>10,000,000 cells) rasters?
> >
> > Thank you in advance
> >
> > Laura
> >
> >         [[alternative HTML version deleted]]
> >
> > _______________________________________________
> > R-sig-Geo mailing list
> > R-sig-Geo@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
>
> --
> Jonathan A. Greenberg, PhD
> Assistant Professor
> Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
> Department of Geography and Geographic Information Science
> University of Illinois at Urbana-Champaign
> 259 Computing Applications Building, MC-150
> 605 East Springfield Avenue
> Champaign, IL  61820-6371
> Phone: 217-300-1924
> http://www.geog.illinois.edu/~jgrn/
> AIM: jgrn307, MSN: jgrn307@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
>

	[[alternative HTML version deleted]]

