MASK
by default.
The mask is applied when reading an existing GRASS raster map, for example when used as an input map in a module. The mask will block out certain areas of a raster map from analysis and/or display, by "hiding" them from sight of other GRASS modules. Data falling within the boundaries of the mask can be modified and operated upon by other GRASS raster modules; data falling outside the mask is treated as if it were NULL.
By default, r.mask converts any non-NULL value in the input map, including zero, to 1. All these areas will be part of the mask (see the notes for more details). To only convert specific values (or range of values) to 1 and the rest to NULL, use the maskcats parameter.
Because the mask raster map created with r.mask is actually only
a reclass map named MASK
by default, it can be copied, renamed,
removed, and used in analyses, just like other GRASS raster maps.
The user should be aware that a mask remains in place until it is removed
or renamed. To remove a mask and restore
raster operations to normal (i.e., all cells of the current region), remove the
mask by setting the -r flag (r.mask -r
).
Alternatively, a mask can be removed using g.remove or by renaming it
to any other name with g.rename.
The GRASS_MASK
environment variable can be used to specify
the raster map which will be used as a mask. If the environment variable is
not defined, the name MASK
is used instead.
r.mask uses r.reclass to create a reclassification of an
existing raster map and names it MASK
by default.
A reclass map takes up less
space, but is affected by any changes to the underlying map from which it was
created. The user can select category values from the input raster to use in the
mask with the maskcats parameter; if r.mask is run from the
command line, the category values listed in maskcats must be quoted
(see example below). Note that the maskcats can only be used if the
input map is an integer map.
The r.mask tool creates a mask with values 1 and NULL. By default, r.mask converts all non-NULL cells to 1. If a raster with ones (1) and NULLs values is used with r.mask, all raster cells with value 1 will be included in the computation, while those with NULL will be masked out.
r.mapcalc -s "map1 = if(row() < col(), 1, null())" r.mask raster=map1
r.mapcalc -s "map2 = if(row() < col(), 1, 0)" r.mask raster=map2 maskcats="0"
Mask can also be created directly using any tools that have a raster as
output, by naming the output raster MASK
(or whatever the
GRASS_MASK
environment variable is set to).
Both NULLs and zeros will be masked out in the raster mask.
This allows for creation of a simple binary raster with only ones and zeros
where cells with zeros in the mask raster are excluded from the computation
(behaving as if they were NULL).
A raster with zeros and ones can be created and used directly as a mask
by naming the output raster MASK
, e.g., using raster algebra:
r.mapcalc -s "MASK = if(row() < col(), 1, 0)"
r.mapcalc -s "map3 = rand(0.0,1.0)" r.mask raster=map3
r.mapcalc -s "map4 = rand(0.0,1.0)" g.copy raster=map4,MASK
Create a raster mask, for constraining the calculation of univariate statistics of the elevation values for "lakes":
# set computation region to lakes raster map g.region raster=lakes -p # use lakes as mask r.mask raster=lakes # get statistics for elevation pixels of lakes: r.univar elevation
r.mask -r
g.region raster=geology_30m -p r.category geology_30m d.mon wx0 d.rast geology_30m r.mask raster=geology_30m maskcats="217 thru 720" d.mon wx0 d.rast geology_30m
Available at: r.mask source code (history)
Latest change: Wednesday Feb 26 10:14:03 2025 in commit: 512bd6d3ba7892514fa95c183deea3bf8b718fa5
Main index | Raster index | Topics index | Keywords index | Graphical index | Full index
© 2003-2025 GRASS Development Team, GRASS GIS 8.5.0dev Reference Manual