[R-sig-Geo] Fwd: ifelse with multiple rasters
Jonathan Greenberg
jgrn at illinois.edu
Mon Feb 24 15:50:06 CET 2014
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:
> 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 at 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 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
More information about the R-sig-Geo
mailing list