[GRASS-user] Re: raster MASKs; was [GRASS-dev] interferring ovewrite flags

Glynn Clements glynn at gclements.plus.com
Mon Oct 2 13:50:31 EDT 2006


Michael Barton wrote:

> > A module scan specifically ask to ignore the MASK, but the vast vast
> > majority of raster modules process data by row (to save memory), and use
> > G_get_raster_row() to do that.
> > 
> > G_get_raster_row_nomask() is the non-masking version. Things that use it:
> >   display/d.rast.edit/mk_tmp_file.c
> >   imagery/i.rectify/perform.c
> >   imagery/i.ortho.photo/photo.rectify/perform.c
> >   raster/r.compress/main.c
> >   raster/r.le/r.le.patch/driver.c
> >   raster/r.le/r.le.patch/trace.c
> >   raster/r.le/r.le.pixel/cellclip.c
> >   raster/r.le/r.le.pixel/driver.c
> > * raster/r.null/null.c
> 
> These commands do NOT respect a MASK ???

It depends.

E.g. r.compress and r.null simply ignore the mask (i.e. they read the
map using G_get_raster_row_nomask()). This makes sense, as these are
low-level utilities which operate directly upon the map, rather than a
"view" of it. Similarly, both of those modules set the region to the
map's region, ignoring the current region.

OTOH, r.le.patch/driver.c seems to handle the mask itself. The actual
map is read with G_get_raster_row(), but it also reads the MASK map
directly (using G_get_raster_row_nomask(); reading MASK with
G_get_raster_row() wouldn't make much sense).

i.ifft does something similar. i.ifft doesn't read any maps, it reads
the "raw" copy which i.fft creates. Not being a map, the mask doesn't
apply, so i.ifft applies the mask itself.

> > r.mapcalc MASK='if(isnull(roads))'
> > r.mapcalc MASK=fields
> > d.rast elevation.dem   # displays with holes
> > r.mapcalc one=1        # full coverage once MASK is removed
> > r.mapcalc two=elevation.dem  # holes once MASK is removed
> > g.remove MASK
> > d.rast one
> > d.rast two
> 
> r.mapcalc will respect a MASK ONLY if the formula to create a new map
> includes an existing map (i.e., read from disk).

That's true of all modules. The mask is applied automatically to input
maps by libgis (unless the map is read using the _nomask versions of
the intput functions). It won't affect anything else unless the module
handles it explicitly (which very few do).

> A new map created from a formula that does NOT include an existing map will
> NOT respect a MASK, even though it may APPEAR to do so when you display it
> using d.rast with a MASK in place--because d.rast DOES respect a MASK.

Yes. Anything which doesn't actually read a map will be unaffected by
the mask.

Also, note that if you use the neighbourhood modifier, e.g.:

	r.mapcalc 'out = in[10,10]'

the mask will be applied upon input, before the shift is applied.

Similarly, modules which switch regions between input and output (e.g. 
r.resamp.interp, r.resamp.stats) will apply the mask at the input
resolution, not the output resolution. One consequence of this is that
r.resamp.stats may produce non-null cells where most other modules
would produce null cells due to the mask.

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




More information about the grass-user mailing list