r.mask.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <h2>DESCRIPTION</h2>
  2. <em><b>r.mask</b></em> - Facilitates creation of a raster "MASK" map to
  3. control raster operations.
  4. <p>
  5. The MASK is applied when <em>reading</em> an existing GRASS raster map,
  6. for example when used as an input map in a module. The MASK will block out
  7. certain areas of a raster map from analysis and/or display, by "hiding" them
  8. from sight of other GRASS modules. Data falling within the boundaries of the
  9. MASK can be modified and operated upon by other GRASS raster modules; data
  10. falling outside the MASK is treated as if it were NULL.
  11. <p>
  12. By default, <em>r.mask</em> converts any non-NULL value in the input map,
  13. including zero, to 1. All these areas will be part of the MASK (see the notes
  14. for more details). To only convert specific values (or range of values) to 1
  15. and the rest to NULL, use the <em>maskcats</em> parameter.
  16. <p>
  17. Because the MASK created with <em>r.mask</em> is actually only a reclass map
  18. named "MASK", it can be copied, renamed, removed, and used in analyses, just
  19. like other GRASS raster map layers.
  20. <p>
  21. The user should be aware that a MASK remains in place until a user renames it
  22. to something other than "MASK", or removes it. To remove a mask and restore
  23. raster operations to normal (i.e., all cells of the current region), remove the
  24. MASK by setting the <b>-r</b> remove MASK flag (<tt>r.mask -r</tt>).
  25. Alternatively, a mask can be removed using <em>g.remove</em> or by renaming it
  26. to any other name with <em>g.rename</em>.
  27. <h2>NOTES</h2>
  28. The above method for specifying a "mask" may seem counterintuitive. Areas
  29. inside the MASK are not hidden; areas outside the MASK will be ignored until
  30. the MASK file is removed.
  31. <p>
  32. <em>r.mask</em> uses <em>r.reclass</em> to create a reclassification of an
  33. existing raster map and name it <tt>MASK</tt>. A reclass map takes up less
  34. space, but is affected by any changes to the underlying map from which it was
  35. created. The user can select category values from the input raster to use in the
  36. MASK with the <em>maskcats</em> parameter; if <em>r.mask</em> is run from the
  37. command line, the category values listed in <em>maskcats</em> must be quoted
  38. (see example below). Note that the <em>maskcats</em> can only be used if the
  39. input map is an integer map.
  40. <h3>Different ways to create a MASK</h3>
  41. The <em>r.mask</em> function creates a MASK with values 1 and NULL. But note
  42. that a MASK can also be created using other functions that have a raster as
  43. output, by naming the output raster 'MASK'. Such layers could have other
  44. values than 1 and NULL. The user should therefore be aware that grid cells
  45. in the MASK map containing <tt>NULL</tt> or <tt>0</tt> will replace data with
  46. NULL, while cells containing other values will allow data to pass through
  47. unaltered. This means that:
  48. <p>
  49. If a binary map with [0,1] values is used as input in <em>r.mask</em>, all
  50. raster cells with 0 and 1 will be part of the MASK. This is because
  51. <em>r.mask</em> converts all non-NULL cells to 1.
  52. <div class="code"><pre>
  53. r.mapcalc -s "map1 = round(rand(0,1))"
  54. r.mask raster=map1
  55. </pre></div>
  56. On the other hand, if a binary map is used as an input in <em>g.copy</em> to create a MASK,
  57. only the raster cells with value 1 will be part of the MASK.
  58. <div class="code"><pre>
  59. r.mapcalc -s "map2 = round(rand(0,1))"
  60. g.copy raster=map2,MASK
  61. </pre></div>
  62. <h3>Handling of floating-point maps</h3>
  63. <em>r.mask</em> treats floating-point maps the same as integer maps (except that
  64. floating maps are not allowed in combination with the <em>maskcats</em>
  65. parameter); all non-NULL values of the input raster map are converted to 1 and
  66. are thus part of the MASK. In the example below, all raster cells are part of
  67. the MASK, i.e., nothing is blocked out from analysis and/or display.
  68. <div class="code"><pre>
  69. r.mapcalc -s "map3 = rand(0.0,1.0)"
  70. r.mask raster=map3
  71. </pre></div>
  72. However, when using another method than <em>r.mask</em> to create a mask,
  73. the user should be aware that the MASK is read as an integer map. If MASK is
  74. a floating-point map, the values will be converted to integers using
  75. the map's quantisation rules (this defaults to round-to-nearest, but can be
  76. changed with r.quant).
  77. <div class="code"><pre>
  78. r.mapcalc -s "map4 = rand(0.0,1.0)"
  79. g.copy raster=map4,MASK
  80. </pre></div>
  81. In the example above, raster cells with a rounded value of 1 are part of
  82. the MASK, while raster cells with a rounded value of 0 are converted to NULL
  83. and consequently blocked out from analysis and/or display.
  84. <h2>EXAMPLES</h2>
  85. The examples are based on the North Carolina sample dataset.
  86. <p>
  87. Create a raster mask, for contraining the calculation of
  88. univariate statistics of the elevation values for "lakes":
  89. <div class="code"><pre>
  90. # set computation region to lakes raster map
  91. g.region raster=lakes -p
  92. # use lakes as MASK
  93. r.mask raster=lakes
  94. # get statistics for elevation pixels of lakes:
  95. r.univar elevation
  96. </pre></div>
  97. Remove the raster mask ("MASK" map) with the -r flag:
  98. <div class="code"><pre>
  99. r.mask -r
  100. </pre></div>
  101. Creating a mask from selected categories in the North Carolina
  102. 'geology_30m' raster map:
  103. <div class="code"><pre>
  104. g.region raster=geology_30m -p
  105. r.category geology_30m
  106. d.mon wx0
  107. d.rast geology_30m
  108. r.mask raster=geology_30m maskcats="217 thru 720"
  109. d.mon wx0
  110. d.rast geology_30m
  111. </pre></div>
  112. <h2>SEE ALSO</h2>
  113. <em>
  114. <a href="g.region.html">g.region</a>,
  115. <a href="r.mapcalc.html">r.mapcalc</a>,
  116. <a href="r.reclass.html">r.reclass</a>,
  117. <a href="g.remove.html">g.remove</a>,
  118. <a href="g.rename.html">g.rename</a>
  119. <a href="r.quant.html">r.quant</a>
  120. </em>
  121. <h2>AUTHOR</h2>
  122. Michael Barton, Arizona State University
  123. <!--
  124. <p>
  125. <i>Last changed: $Date$</i>
  126. -->