[GRASS-user] Strange r.mapcalc results
Glynn Clements
glynn at gclements.plus.com
Thu Sep 24 11:34:45 EDT 2009
Hermann Peifer wrote:
> I am trying to find out if 2 raster layers are exactly identical. I am
> not an experienced mapcalc user, so I am wondering, where the 3200204
> NULL values come from, in Test1. The result in Test2 is what I expected.
>
> My obviously wrong understanding was that I wouldn't need the special
> operator ||| in Test1, as NULL values are already treated specially by
> isnull()
> Any hint from the experts?
> Test1
>
> $ r.mapcalc 'result = isnull(mapA) && isnull(mapT) || mapA == mapT ? 1 : 2'
> Test2
>
> $ r.mapcalc 'result = isnull(mapA) && isnull(mapT) ||| mapA == mapT ? 1 : 2'
If mapA and mapT are both null, then Test 1 reduces to:
result = isnull(mapA) && isnull(mapT) || mapA == mapT
-> result = isnull(null) && isnull(null) || null == null
-> result = 1 && 1 || null
-> result = 1 || null
-> result = null
while Test2 reduces to:
result = isnull(mapA) && isnull(mapT) ||| mapA == mapT
-> result = isnull(null) && isnull(null) ||| null == null
-> result = 1 && 1 ||| null
-> result = 1 ||| null
-> result = 1
The || and && operators always propagate nulls (i.e. they return null
if either operand is null), while ||| and &&& return a non-null result
where possible (i.e. ||| returns 1 if either operand is non-zero, &&&
returns 0 if either operand is zero).
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-user
mailing list