[GRASS-user] Re: Strange r.mapcalc results

Hermann Peifer peifer at gmx.eu
Thu Sep 24 11:52:21 EDT 2009


Glynn,

Thanks indeed for the enlightening. I am new to the mapcalc business and 
my obviously wrong (AWK-based) thinking was that mapcalc would do a lazy 
evaluation of the conditions, i.e.  "1 && 1 || something" would always 
be 1, whatever "something" was. Now I know better.

Thanks again, Hermann


Glynn Clements wrote:
> 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).
> 



More information about the grass-user mailing list