r.patch.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <h2>DESCRIPTION</h2>
  2. The GRASS program <em>r.patch</em> allows the user to build a new
  3. raster map the size and resolution of the current region by assigning
  4. known data values from input raster maps to the cells in this region.
  5. <br>
  6. In case of overlapping input raster maps this is done by filling in
  7. "no data" cells, those that do not yet contain data, contain NULL data,
  8. or, optionally contain 0 data, with the data from the first input map.
  9. Once this is done the remaining holes are filled in by the next input map,
  10. and so on.
  11. <br>
  12. In case of adjacent input raster maps the output map contains the map
  13. mosaic.
  14. <p>
  15. Hence this command is useful for
  16. <ul>
  17. <li> making a composite raster map layer from two or more adjacent map layers,</li>
  18. <li> for filling in "holes" in a raster map layer's data (e.g., in digital
  19. elevation data), or
  20. <li> for updating an older map layer with more recent data.</li>
  21. </ul>
  22. The current geographic region definition and mask settings are respected.
  23. <center>
  24. <img src="r_patch.png">
  25. <p><em>Figure: Result of patching of two raster maps containing NULLs
  26. using the default settings.</em></p>
  27. </center>
  28. <h3>Stacking order</h3>
  29. <p>The first <em>name</em> listed in the string
  30. <b>input=</b><em>name</em>,<em>name</em>,<em>name</em>,... is the name
  31. of the first map whose data values will be used to fill in
  32. cells in the current region.
  33. Then, the second through the last input
  34. maps (..., <em>name</em>, <em>name</em>, ...) will be used,
  35. in order, to supply data values for the remaining
  36. "no data" cells (or cells with value 0 with <b>-z</b> flag).
  37. <p>
  38. In other words, the first raster map is used first and if it had some
  39. "no data" cells, then second raster map is used for these cells, then
  40. the third and so on.
  41. So the formal command line syntax can be also written as
  42. <b>input=</b><em>primary</em>,<em>secondary</em>,<em>tertiary</em>,...
  43. For two raster maps, the first one can be viewed as the primary one
  44. or the default one and the second one as the secondary one or a fallback.
  45. <center>
  46. <img src="r_patch_zeros_as_nulls.png">
  47. <p><em>Figure: Result of patching of two raster maps using the
  48. <b>-z</b> flag to treat zeros as NULLs. Note the value 1 being preserved
  49. from the first raster while the value 6 is taken from the second raster
  50. instead of the value 0 from the first raster because zeros are replaced
  51. with the <b>-z</b> flag active.</em></p>
  52. </center>
  53. <h3>Relation to SQL COALESCE() function</h3>
  54. The module is corresponds to the SQL COALESCE() function.
  55. This function takes two or more arguments and returns
  56. a copy of its first non-NULL argument. If all arguments are NULL,
  57. the function returns NULL.
  58. <p>
  59. The <em>r.patch</em> module iterates over all cells and for each cell
  60. of the output raster map uses the first corresponding non-NULL cell
  61. in the series of the input raster maps.
  62. <h3>Example of filling areas</h3>
  63. <!-- this example is also used in the tests -->
  64. Below, the raster map layer on the far left is <b>patched</b>
  65. with the middle (<em>patching</em>) raster map layer,
  66. to produce the <em>composite</em> raster map layer on the right.
  67. The example assumes zero values to be treated as NULLs (<b>-z</b> flag).
  68. <div class="code"><pre>
  69. 1 1 1 0 2 2 0 0 0 0 1 1 0 0 0 0 1 1 1 1 2 2 0 0
  70. 1 1 0 2 2 2 0 0 0 0 1 1 0 0 0 0 1 1 1 2 2 2 0 0
  71. 3 3 3 3 2 2 0 0 0 0 0 0 0 0 0 0 3 3 3 3 2 2 0 0
  72. 3 3 3 3 0 0 0 0 4 4 4 4 4 4 4 4 3 3 3 3 4 4 4 4
  73. 3 3 3 0 0 0 0 0 4 4 4 4 4 4 4 4 3 3 3 4 4 4 4 4
  74. 0 0 0 0 0 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
  75. </pre></div>
  76. Switching the <em>patched</em> and the <em>patching</em> raster map layers
  77. produces the following results:
  78. <div class="code"><pre>
  79. 0 0 1 1 0 0 0 0 1 1 1 0 2 2 0 0 1 1 1 1 2 2 0 0
  80. 0 0 1 1 0 0 0 0 1 1 0 2 2 2 0 0 1 1 1 1 2 2 0 0
  81. 0 0 0 0 0 0 0 0 3 3 3 3 2 2 0 0 3 3 3 3 2 2 0 0
  82. 4 4 4 4 4 4 4 4 3 3 3 3 0 0 0 0 4 4 4 4 4 4 4 4
  83. 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 4 4 4 4 4 4 4 4
  84. 4 4 4 4 4 4 4 4 0 0 0 0 0 0 0 0 4 4 4 4 4 4 4 4
  85. </pre></div>
  86. <h2>NOTES</h2>
  87. Frequently, this program is used to patch together adjacent map layers which
  88. have been digitized separately. The program
  89. <em><a href="v.mkgrid.html">v.mkgrid</a></em> can be used to make adjacent
  90. maps align neatly.
  91. <p>The user should check the current geographic region settings before running
  92. <em>r.patch</em>, to ensure that the region boundaries encompass all
  93. of the data desired to be included in the composite map and to ensure that the
  94. region resolution is the resolution of the desired data. To set the
  95. geographic region settings to one or several raster maps, the <em>g.region</em>
  96. program can be used:
  97. <div class="code"><pre>
  98. g.region raster=map1[,map2[,...]]
  99. </pre></div>
  100. <p>
  101. Use of <em>r.patch</em> is generally followed by use of the GRASS programs
  102. <em><a href="g.remove.html">g.remove</a></em> and
  103. <em><a href="g.rename.html">g.rename</a></em>;
  104. <em>g.remove</em> is used to remove the original (un-patched) raster map
  105. layers, while <em>g.rename</em> is used to then assign to the newly-created
  106. composite (patched) raster map layer the name of the original raster map
  107. layer.
  108. <p>
  109. <em>r.patch</em> reads the existing category label files and color tables
  110. from the <em>input</em> maps and creates these files for the patched,
  111. composite <em>output</em> map. This can be quite time consuming for
  112. certain maps, especially if there are many different category values
  113. across the patched maps. The <em>-s</em> flag allows disabling the reading
  114. and creation of these support files, meaning that the <em>output</em>
  115. map will have no category labels and no explicit color table.
  116. <p>
  117. Number of raster maps to be processed is given by the limit of the
  118. operating system. For example, both the hard and soft limits are
  119. typically 1024. The soft limit can be changed with e.g. <tt>ulimit -n
  120. 1500</tt> (UNIX-based operating systems) but not higher than the hard
  121. limit. If it is too low, you can as superuser add an entry in
  122. <div class="code"><pre>
  123. /etc/security/limits.conf
  124. # &lt;domain&gt; &lt;type&gt; &lt;item&gt; &lt;value&gt;
  125. your_username hard nofile 1500
  126. </pre></div>
  127. This would raise the hard limit to 1500 file. Be warned that more
  128. files open need more RAM. See also the Wiki page
  129. <a href="http://grasswiki.osgeo.org/wiki/Large_raster_data_processing">Hints for large raster data processing</a>.
  130. <p>
  131. Operating systems usually limit the length of the command line
  132. which limits the number of input raster maps user can pass to the module
  133. using the option <b>input</b>. In that case,
  134. <em><a href="r.series.html">r.series</a></em> can be used instead of
  135. <em>r.patch</em>.
  136. <h2>EXAMPLES</h2>
  137. <h3>Example with three maps</h3>
  138. The input are three maps called roads, water and forest. Primarily,
  139. we want to use the values from roads, then from water and if no
  140. other values are available we want to use forest.
  141. First we set the computation region assuming that the all three maps
  142. fully overlap and have the same resolution (so we can safely use the
  143. just the one without further modifications of the region).
  144. Then we perform the patching.
  145. <div class="code"><pre>
  146. g.region raster=roads
  147. r.patch input=roads,water,forest output=result
  148. </pre></div>
  149. <h3>Map mosaic example using Bash syntax</h3>
  150. Create a list of maps matching a pattern, extend the region to include them
  151. all, and patch them together to create a mosaic. Overlapping maps will be
  152. used in the order listed.
  153. <div class="code"><pre>
  154. MAPS=`g.list type=raster separator=comma pat="map_*"`
  155. g.region raster=$MAPS -p
  156. r.patch input=$MAPS output=maps_mosaic
  157. </pre></div>
  158. <h2>SEE ALSO</h2>
  159. <em>
  160. <a href="g.region.html">g.region</a>,
  161. <a href="g.remove.html">g.remove</a>,
  162. <a href="g.rename.html">g.rename</a>,
  163. <a href="r.mapcalc.html">r.mapcalc</a>,
  164. <a href="r.support.html">r.support</a>,
  165. <a href="r.series.html">r.series</a>,
  166. <a href="v.mkgrid.html">v.mkgrid</a>
  167. </em>
  168. <p>
  169. <a href="http://grasswiki.osgeo.org/wiki/Large_raster_data_processing">Hints for large raster data processing</a>
  170. <h2>AUTHOR</h2>
  171. Michael Shapiro,
  172. U.S. Army Construction Engineering Research Laboratory
  173. <br>
  174. -z flag and performance improvement by Huidae Cho
  175. <p><i>Last changed: $Date$</i>