ifel {raster}R Documentation

ifelse for Raster* objects

Description

This functions like ifelse but this one works for Raster* objects. This is "syntactic sugar", that is, it can be easier to express what is desired; but there is no real need for it, as you can achieve the same things with combinations of calc, reclassify, mask, and cover.

In ArcMap (arcpy), ifel is called Con.

Usage

## S4 method for signature 'Raster'
ifel(test, yes, no, filename, ...)

Arguments

test

Raster* object

yes

Raster* object or numeric

no

Raster* object or numeric

filename

character. Output filename (optional)

...

if x is a Raster* object, additional arguments as for writeRaster

Details

This is a new method that has not been tested much yet. User beware.

Value

Raster* object

Examples

r <- raster(nrows=5, ncols=5, vals=-10:14)

x <- ifel(r > 1, 1, r)
# same as 
a <- reclassify(r, cbind(1, Inf, 1))
b <- calc(r, function(i) {i[i > 1] <- 1; i})
d <- clamp(r, -Inf, 1)

y <- ifel(r > 1, 1, ifel(r < -1, -1, r))

z <- ifel(r > -2 & r < 2, 100, 0)

k <- ifel(r > 0, r+10, ifel(r < 0, r-10, 3))
plot(k)
text(k)

[Package raster version 2.9-7 Index]