[GRASS5] r.mapcalc bug/64bit?

Glynn Clements glynn at gclements.plus.com
Tue May 2 13:24:09 EDT 2006


Markus Neteler wrote:

> > What does the following say:
> > 
> > r.mapcalc 'test = isnull(modis_t_a_lst1km20040102.daily_min) + isnull(startday_previous) + isnull(condition_previous)'
> > r.info -r test
> > 
> 
> This test:
> 
> GRASS 6.1.cvs (pat):~ > r.mapcalc 'test = isnull(modis_t_a_lst1km20040102.daily_min) + isnull(startday_previous) + isnull(condition_previous)'
>  100%
> GRASS 6.1.cvs (pat):~ > r.info -r test
> min=1
> max=3

The "min=1" means that the value of every cell in the region is null
in at least one of the three input maps. Consequently, the output map
will be all nulls.

Note that the && and || operators follow the same null-propagation
rules as other operators, i.e. if either argument is null the result
will be null.

In particular, the following all evaluate to null, which may be
counterintuitive:

	true  || null
	null  || true
	false && null
	null  && false

Currently, the behaviour of those operators is:

	&&|0 1 N	|||0 1 N
	--+-----	--+-----
	0 |0 0 N	0 |0 1 N
	1 |0 1 N	1 |1 1 N
	N |N N N	N |N N N

Preserving the boolean axioms would give:

	&&|0 1 N	|||0 1 N
	--+-----	--+-----
	0 |0 0 0	0 |0 1 N
	1 |0 1 N	1 |1 1 1
	N |0 N N	N |N 1 N

If you want the normal boolean axioms:

	true  || x == true
	false && x == false

to hold even when x is null, you can replace && and || with:

	x || y -> eval(nx=if(isnull(x),0,x), ny=if(isnull(y),0,y),if(nx||ny,1,x||y))
	x && y -> eval(nx=if(isnull(x),1,x), ny=if(isnull(y),1,y),if(!nx||!ny,0,x&&y))

That's rather messy. If desired, I can re-write the && and ||
operators accordingly (or add an alternative set of and/or operators).

-- 
Glynn Clements <glynn at gclements.plus.com>




More information about the grass-dev mailing list