[GRASS5] very confused over NULL in rasters

Markus Neteler neteler at geog.uni-hannover.de
Thu Jan 18 16:01:32 EST 2001


Hi back on this thread,

just checked in a demonstration module from Huidae Cho 
into
unused/raster/r.show

which demonstrated below FP programming with UNIONs
as described below.

Maybe useful to someone,

thanks, Huidae!

 Markus


On Sat, Dec 16, 2000 at 02:40:20PM -0800, Eric G . Miller wrote:
> On Sat, Dec 16, 2000 at 02:36:02PM -0700, William L. Baker wrote:
> > Hello,
> > 
> > Still another question while revising r.le, which is especially
> > messy because of null values and true zeroes.
> > 
> > I am confused about what the possible cases are for null values
> > in a raster map and the corresponding null file.
> > 
> > 1. Will NULL values be in the raster map itself?
> [snip]
> 
> If you're using the library functions, you don't need to care whether
> the NULL's are embedded or not.  In memory they are embedded, on disk
> they are separated.  By using the library routines for testing for NULL
> values or writing NULL values (by RASTER_MAP_TYPE), you shouldn't worry
> about how they are actually dealt with.  Huidae Cho suggested an nice
> method for handling the abstraction for the differing kinds of rasters
> that goes something like:
> 
> union RASTER_PTR {
> 	void  *v;
> 	CELL  *c;
> 	FCELL *f;
> 	DCELL *d;
> };
> 
> struct RASTER_MAP_PTR {
> 	RASTER_MAP_TYPE  type;
> 	union RASTER_PTR buf;
> };
> 
> The you can use something like:
> 
> ..
>   struct RASTER_MAP_PTR rast;
>   struct Cell_head window;
> 
>   rast.type = G_raster_map_type (name, mapset);
>   rast.buf.v = G_allocate_raster_buf (rast.type);
> 
>   G_get_window (&window);
> 
>   ...
>   
>   for (i = 0; i < window.cols ; i++)
>     switch (rast.type) {
>       case CELL_TYPE:
>       	rast.buf.c[i] = /* something */
>       ...
> 
>     }
>   
>   /* or */
> 
>   if (G_is_null_value (rast.buf.v, rast.type))
>   	/* Do something */
> 
>   /* or */
> 
>   G_set_null_value (rast.buf.v, window.cols, rast.type);
>   
> 
>   G_free (rast.buf.v);
> ..
> 		
> 
> > 2. The NULL in the null value file (cell_misc/<map>/null) in the
> > programming manual is "one indicating that the corresponding
> > cell contains valid data, and zeros indicating that the corresponding
> > cell contains a NULL value.  I may have done something wrong
> > when I looked at the results from using r.null, but I'm pretty sure
> > that program does just the opposite--a one indicates a null and
> > a zero indicates valid data.  Is this wrong in the programming
> > manual or does r.null have it backwards?  What are programmers
> > assuming is correct?
> 
> I haven't done alot of raster programming, but I've generally avoided
> worrying about using NULL flags for G_insert_null_values() or whatever,
> by simply setting an entire buffer to NULL and then writing non-NULL
> values where applicable.  For reading, I've used the G_is_null_value
> to deal with whether a cell is NULL or not.  I suppose using the flags
> method could be more practical in some scenarios, and I believe you're
> correct that 0 == not-NULL and 0 != NULL.  At least, it says that for
> G_insert_null_values();
> 
> -- 
> 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'
> 

-- 
Markus Neteler *  University of Hannover
Institute of Physical Geography and Landscape Ecology
Schneiderberg 50 * D-30167 Hannover * Germany
Tel: ++49-(0)511-762-4494  Fax: -3984

---------------------------------------- 
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