[GRASS-user] Tip on using r.mapcalcl
Glynn Clements
glynn at gclements.plus.com
Fri Jul 8 22:35:37 EDT 2011
Helena Herrera wrote:
> I have 4 bands (B1;B2,B3;B4) all with values >0 except in a few pixels where
> I have nulls.
> I want to create a layer where I have 1 if at least I have 1 number and
> nulls where I don't have a single value
> I have tried this
> if (B1>=0 || B2>=0 || B3>=0 || B4>=0, 1,null()) but I got null in pixels
> where I have information for at least 2 bands.
"x>=0" will evaluate to null if x is null. "x||y" will evaluate to
null if either x or y is null. In general, most operators and
functions return null if any of their arguments are null. The main
exceptions are if(), eval(), isnull(), ||| and &&&, as described in
the "NULL support" section of the r.mapcalc manual page.
> any tip on how can I do this?
Either:
1. Use isnull() to determine whether a cell is null, e.g.:
if (isnull(B1) && isnull(B2) && isnull(B3) && isnull(B4), null(), 1)
2. Modify your original expression to use ||| instead of ||, i.e.:
if (B1>=0 ||| B2>=0 ||| B3>=0 ||| B4>=0, 1, null())
The ||| operator satisfies the boolean axioms:
x ||| true == true
and:
true ||| x == true
even when x is null. The || operator propagates nulls like other
operators. Similarly for &&& and &&.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list