Null data in raster - A proposal (was Re: [GRASS5] Opinion wanted - null data)

Michel Wurtz mw at
Wed Jul 4 06:29:20 EDT 2001

Well, after reading a lot of mail and a little thinking, I propose
the following rules and implementation.  Any remarks are welcome.

Add a field in raster's header files, "null:"
The values can be

null: No          There is no null value in the raster file (faster)
null: NaN         Null value is ISO Not_a_Number (for FCELL or DCELL)
null: <integer>   Null value is represented by <integer> in the raster
                  (for 1, 2, 3 or 4 bytes integer raster files)
null: file=xxx    where xxx is another raster file where 0 means null
                  (acts like Grass MASK) - should be an exception.

For old files (no "null:" field), use a Grass environment variable,
like GRASSNULLVALUE, which contains 0 or No (I think there is no
other alternative for pré-5.0 rasters)

Add the command r.null for creating/modifying null values :
the usage should be

    r.null raster=xxx value=No (or value=NaN, or value=<integer>)
or (exclusive use of value and mask)
    r.null raster=xxx mask=yyy
where xxx and yyy are raster files.

This should cover all cases.  Using a "classic" raster file for null
means that this file can be compressed, unlike the actual "null file".
It means also that you can easely create or modify it, because every
raster functions work with it.

The only problem I see is when a command uses two (or more) files as
input file (like r.mapcalc).  If the output is a CELL file, there is
no mean to find a correct "null value", so we must create a mask (a
raster file) and give him a name.  I propose to use the generator for
uniques file names and use .nul as extension (like "12345678.nul")

A further enhancement may be a command to automatically replace the
file generated by a value not in the range of the raster values (a
first approach may use r.hist to find it...)

Michel WURTZ - DIG - Maison de la télédétection
               500, rue J.F. Breton
               34093 MONTPELLIER Cedex 5

More information about the grass-dev mailing list