[GRASS5] r.mapcalc and NULL question

Eric G . Miller egm2 at jps.net
Mon Jan 15 15:40:21 EST 2001


On Mon, Jan 15, 2001 at 12:41:58PM -0700, Roger S. Miller wrote:
> 
> On Mon, 15 Jan 2001, Markus Neteler wrote:
> 
> > Hi there,
> >
> > maybe a r.mapcalc/NULL FAQ, but I don't get it...
> >
> > Assume you have a streams map (streams contain values,
> > other cells=NULL).
> >
> > Now I want to add some values *everywhere* using r.mapcalc, but
> > it is only added in those cells not containing a NULL value.
> 
> Markus,
> 
> I guess you probably want the NULL-valued cells to be treated like zeros.
> To add maps A and B (where B contains NULLs) to get a map C you can use a
> construction like
> 
> C=A+if(isnull(B),0,B)
> 
> I found a need for this when I used Grass 5 to run the Leicestershire
> tutorial, which was written for Grass 4.x.
> 
> There's another NULL-related behavior that I find rather annoying.  I
> guess that the numerical value of NULL is actually -129.  I constructed a
> raster map of water-level changes from a ground water model and found a
> band of nulls scattered across the map, wherever the surface passed -129
> feet.

No, the NULL value depends on the CELL type.  Think this is/was a bug in
r.mapcalc specifically (If I recall, it has been corrected).  Generally
the embedded NULL values (when the file is read via G_* funcs) are

CELL  : MAX_INT
FCELL : NaN  (float version)
DCELL : Nan  (double version)

However, applications should always use the G_is_null_value() family of
functions.  The CELL Null value is problematic if used incorrectly
because you can silently get overflow/underflow errors.  NaN used in any
context should always produce NaN (NaN = NaN - NaN) -- at least, that's
how it's supposed to work ;)

-- 
Eric G. Miller <egm2 at jps.net>

---------------------------------------- 
If you want to unsubscribe from GRASS Development Team mailing list write to:
minordomo at geog.uni-hannover.de with
subject 'unsubscribe grass5'



More information about the grass-dev mailing list