r.drain.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. <h2>DESCRIPTION</h2>
  2. <em>r.drain</em> traces a flow through a least-cost path in an
  3. elevation model or cost surface. For cost surfaces, a movement
  4. direction map must be specified with the
  5. <b>direction</b> option and the <b>-d</b> flag to trace a flow path following
  6. the given directions. Such a movement direction map can be generated with
  7. <em><a href="r.walk.html">r.walk</a></em>,
  8. <em><a href="r.cost.html">r.cost</a></em>,
  9. <em><a href="r.slope.aspect.html">r.slope.aspect</a></em> or
  10. <em><a href="r.watershed.html">r.watershed</a></em>
  11. provided that the direction is in degrees, measured counterclockwise
  12. from east.
  13. <p>
  14. The <b>output</b> raster map will show one or more least-cost paths
  15. between each user-provided location(s) and the minima (low category
  16. values) in the raster <b>input</b> map. If the <b>-d</b> flag is used
  17. the output least-cost paths will be found using the direction raster
  18. map. By default, the <b>output</b> will be an integer CELL map with
  19. category 1 along the least cost path, and null cells elsewhere.
  20. <p>With the <b>-c</b> (<em>copy</em>) flag, the input raster map cell values are
  21. copied verbatim along the path. With the <b>-a</b> (<em>accumulate</em>)
  22. flag, the accumulated cell value from the starting point up to the current
  23. cell is written on output. With either the <b>-c</b> or the <b>-a</b> flags, the
  24. <b>output</b> map is created with the same cell type as
  25. the <b>input</b> raster map (integer, float or double). With
  26. the <b>-n</b> (<em>number</em>) flag, the cells are numbered
  27. consecutively from the starting point to the final point.
  28. The <b>-c</b>, <b>-a</b>, and <b>-n</b> flags are mutually
  29. incompatible.
  30. <p>For an elevation surface, the path is calculated by choosing the
  31. steeper "slope" between adjacent cells. The slope calculation
  32. accurately accounts for the variable scale in lat-lon projections. For
  33. a cost surface, the path is calculated by following the movement
  34. direction surface back to the start point given
  35. in <em><a href="r.walk.html">r.walk</a></em> or
  36. <em><a href="r.cost.html">r.cost</a></em>. The path search stops
  37. as soon as a region border or a neighboring NULL cell is encountered,
  38. because in these cases the direction can not be determined (the path
  39. could continue outside the current region).
  40. <p>The <b>start_coordinates</b> parameter consists of map E and N grid coordinates of
  41. a starting point. Each x,y pair is the easting and northing (respectively) of
  42. a starting point from which a least-cost corridor will be developed.
  43. The <b>start_points</b> parameter can take multiple vector maps containing
  44. additional starting points.
  45. Up to 1024 starting points can be input from a combination of the
  46. <b>start_coordinates</b> and <b>start_points</b> parameters.
  47. <h3>Explanation of output values</h3>
  48. Consider the following example:
  49. <div class="code"><pre>
  50. Input: Output:
  51. ELEVATION SURFACE LEAST COST PATH
  52. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  53. . 19. 20. 18. 19. 16. 15. 15. . . . . . . . .
  54. . . --- . . . . . . . . . . . . . . . . . . . . . . . . .
  55. . 20| 19| 17. 16. 17. 16. 16. . . 1 . 1 . 1 . . . .
  56. . . --- . . . . . . . . . . . . . . . . . . . . . . . . .
  57. . 18. 18. 24. 18. 15. 12. 11. . . . . . 1 . . .
  58. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  59. . 22. 16. 16. 18. 10. 10. 10. . . . . . 1 . . .
  60. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  61. . 17. 15. 15. 15. 10. 8 . 8 . . . . . . . 1 . .
  62. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  63. . 24. 16. 8 . 7 . 8 . 0 . 12. . . . . . . 1 . .
  64. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  65. . 17. 9 . 8 . 7 . 8 . 6 . 12. . . . . . . . .
  66. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  67. </pre></div>
  68. <p>
  69. The user-provided starting location in the above example is
  70. the boxed <b>19</b> in the left-hand map. The path in the output
  71. shows the least-cost corridor for moving from the starting
  72. box to the lowest (smallest) possible point. This is the path a raindrop
  73. would take in this landscape.
  74. <p>
  75. With the <b>-c</b> <em>(copy)</em> flag, you get the following result:
  76. <div class="code"><pre>
  77. Input: Output:
  78. ELEVATION SURFACE LEAST COST PATH
  79. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  80. . 19. 20. 18. 19. 16. 15. 15. . . . . . . . .
  81. . . --- . . . . . . . . . . . . . . . . . . . . . . . . .
  82. . 20| 19| 17. 16. 17. 16. 16. . . 19. 17. 16. . . .
  83. . . --- . . . . . . . . . . . . . . . . . . . . . . . . .
  84. . 18. 18. 24. 18. 15. 12. 11. . . . . . 15. . .
  85. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  86. . 22. 16. 16. 18. 10. 10. 10. . . . . . 10. . .
  87. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  88. . 17. 15. 15. 15. 10. 8 . 8 . . . . . . . 8 . .
  89. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  90. . 24. 16. 8 . 7 . 8 . 0 .12 . . . . . . . 0 . .
  91. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  92. . 17. 9 . 8 . 7 . 8 . 6 .12 . . . . . . . . .
  93. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  94. Note that the last <em>0</em> will not be put in the null values map.
  95. </pre></div>
  96. <p>
  97. With the <b>-a</b> <em>(accumulate)</em> flag, you get the following result:
  98. <div class="code"><pre>
  99. Input: Output:
  100. ELEVATION SURFACE LEAST COST PATH
  101. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  102. . 19. 20. 18. 19. 16. 15. 15. . . . . . . . .
  103. . . --- . . . . . . . . . . . . . . . . . . . . . . . . .
  104. . 20| 19| 17. 16. 17. 16. 16. . . 19. 36. 52. . . .
  105. . . --- . . . . . . . . . . . . . . . . . . . . . . . . .
  106. . 18. 18. 24. 18. 15. 12. 11. . . . . . 67. . .
  107. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  108. . 22. 16. 16. 18. 10. 10. 10. . . . . . 77. . .
  109. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  110. . 17. 15. 15. 15. 10. 8 . 8 . . . . . . . 85. .
  111. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  112. . 24. 16. 8 . 7 . 8 . 0 .12 . . . . . . . 85. .
  113. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  114. . 17. 9 . 8 . 7 . 8 . 6 .12 . . . . . . . . .
  115. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  116. </pre></div>
  117. <p>
  118. With the <b>-n</b> <em>(number)</em> flag, you get the following result:
  119. <div class="code"><pre>
  120. Input: Output:
  121. ELEVATION SURFACE LEAST COST PATH
  122. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  123. . 19. 20. 18. 19. 16. 15. 15. . . . . . . . .
  124. . . --- . . . . . . . . . . . . . . . . . . . . . . . . .
  125. . 20| 19| 17. 16. 17. 16. 16. . . 1 . 2 . 3 . . . .
  126. . . --- . . . . . . . . . . . . . . . . . . . . . . . . .
  127. . 18. 18. 24. 18. 15. 12. 11. . . . . . 4 . . .
  128. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  129. . 22. 16. 16. 18. 10. 10. 10. . . . . . 5 . . .
  130. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  131. . 17. 15. 15. 15. 10. 8 . 8 . . . . . . . 6 . .
  132. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  133. . 24. 16. 8 . 7 . 8 . 0 .12 . . . . . . . 7 . .
  134. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  135. . 17. 9 . 8 . 7 . 8 . 6 .12 . . . . . . . . .
  136. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
  137. </pre></div>
  138. With the <b>-d</b> <em>(direction)</em> flag, the direction raster is used
  139. for the input, rather than the elevation surface. The output is then created
  140. according to one of the <b>-can</b> flags.
  141. <div class="code"><pre>
  142. The directions are recorded as degrees CCW from East:
  143. 112.5 67.5 i.e. a cell with the value 135
  144. 157.5 135 90 45 22.5 means the next cell is to the North-West
  145. 180 x 0
  146. 202.5 225 270 315 337.5
  147. 247.5 292.5
  148. </pre></div>
  149. <h2>NOTES</h2>
  150. If no direction input map is given, <em>r.drain</em> currently finds
  151. only the lowest point (the cell having the smallest category value) in
  152. the input file that can be reached through directly adjacent cells
  153. that are less than or equal in value to the cell reached immediately
  154. prior to it; therefore, it will not necessarily reach the lowest point
  155. in the input file. It currently finds <em>pits</em> in the data,
  156. rather than the lowest point in the entire input
  157. map. The <em><a href="r.fill.dir.html">r.fill.dir</a></em>,
  158. <em><a href="r.terraflow.html">r.terraflow</a></em>,
  159. and <em><a href="r.basins.fill.html">r.basins.fill</a></em> modules
  160. can be used to fill in subbasins prior to processing
  161. with <em>r.drain</em>.
  162. <p>
  163. <em>r.drain</em> will not give sane results at the region boundary. On outer rows
  164. and columns bordering the edge of the region, the flow direction is always directly out
  165. of the map. In this case, the user could try adjusting the region extents slightly with
  166. <em>g.region</em> to allow additional outlet paths for <em>r.drain</em>.
  167. <h2>EXAMPLES</h2>
  168. <h3>Path to the lowest point</h3>
  169. In this example we compute drainage paths from two given points
  170. following decreasing elevation values to the lowest point.
  171. We are using the full North Carolina sample dataset.
  172. First we create the two points from a text file using
  173. <em><a href="v.in.ascii.html">v.in.ascii</a></em> module
  174. (here the text file is CSV and we are using unix here-file syntax
  175. with EOF, in GUI just enter the values directly for the parameter input):
  176. <div class="code"><pre>
  177. v.in.ascii input=- output=start format=point separator=comma &lt;&lt;EOF
  178. 638667.15686275,220610.29411765
  179. 638610.78431373,220223.03921569
  180. EOF
  181. </pre></div>
  182. Now we compute the drainage path:
  183. <div class="code"><pre>
  184. r.drain input=elev_lid792_1m output=drain_path drain=drain start_points=start
  185. </pre></div>
  186. Before we visualize the result, we set a color table for the elevation
  187. we are using and we create a shaded relief map:
  188. <div class="code"><pre>
  189. r.colors map=elev_lid792_1m color=elevation
  190. r.relief input=elev_lid792_1m output=relief
  191. </pre></div>
  192. Finally we visualize all the input and output data:
  193. <div class="code"><pre>
  194. d.shade shade=relief color=elev_lid792_1m
  195. d.vect map=drain_path color=0:0:61 width=4 legend_label="drainage paths"
  196. d.vect map=start color=none fill_color=224:0:0 icon=basic/circle size=15 legend_label=origins
  197. d.legend.vect -b
  198. </pre></div>
  199. <div align="center">
  200. <a href="r_drain.png"><img src="r_drain.png" alt="drainage using r.watershed" width="300" height="280"></a>
  201. <br>
  202. <i>Figure: Drainage paths from two points flowing into the points with
  203. lowest values</i>
  204. </div>
  205. <h3>Path following directions</h3>
  206. To continue flow even after it hits a depression, we need to supply a
  207. direction raster map which will tell the <em>r.drain</em> module how to
  208. continue from the depression. To get these directions, we use the
  209. <em><a href="r.watershed.html">r.watershed</a></em> module:
  210. <div class="code"><pre>
  211. r.watershed elevation=elev_lid792_1m accumulation=accum drainage=drain_dir
  212. </pre></div>
  213. The directions are categorical and we convert them to degrees using
  214. raster algebra:
  215. <div class="code"><pre>
  216. r.mapcalc "drain_deg = if(drain_dir != 0, 45. * abs(drain_dir), null())"
  217. </pre></div>
  218. Together with directions, we need to provide the <em>r.drain</em> module
  219. with cost values. We don't have any cost to assign to specific cells,
  220. so we create a constant surface:
  221. <div class="code"><pre>
  222. r.mapcalc "const1 = 1"
  223. </pre></div>
  224. Now we are ready to compute the drainage paths.
  225. We are using the two points from the previous example.
  226. <div class="code"><pre>
  227. r.drain -d input=const1 direction=drain_deg output=drain_path_2 drain=drain_2 start_points=start
  228. </pre></div>
  229. We visualize the result in the same way as in the previous example.
  230. <div align="center">
  231. <a href="r_drain_with_r_watershed_direction.png"><img src="r_drain_with_r_watershed_direction.png" alt="drainage using r.watershed" width="300" height="280"></a>
  232. <br>
  233. <i>Figure: Drainage paths from two points where directions from
  234. r.watershed were used</i>
  235. </div>
  236. <h2>KNOWN ISSUES</h2>
  237. <p>Sometimes, when the differences among integer cell category values in the
  238. <em><a href="r.cost.html">r.cost</a></em> cumulative cost surface output are
  239. small, this cumulative cost output cannot accurately be used as input to
  240. <em>r.drain</em> (<em>r.drain</em> will output bad results).
  241. This problem can be circumvented by making the differences
  242. between cell category values in the cumulative cost output bigger. It
  243. is recommended that if the output from <em>r.cost</em> is to be used
  244. as input to <em>r.drain</em>, the user multiply the <em>r.cost</em>
  245. input cost surface map by the value of the map's cell resolution,
  246. before running <em>r.cost</em>. This can be done using
  247. <em><a href="r.mapcalc.html">r.mapcalc</a></em>. The map resolution can be
  248. found using <em><a href="g.region.html">g.region</a></em>.
  249. This problem doesn't arise with floating point maps.
  250. <h2>SEE ALSO</h2>
  251. <em>
  252. <a href="g.region.html">g.region</a>,
  253. <a href="r.cost.html">r.cost</a>,
  254. <a href="r.fill.dir.html">r.fill.dir</a>,
  255. <a href="r.basins.fill.html">r.basins.fill</a>,
  256. <a href="r.watershed.html">r.watershed</a>,
  257. <a href="r.terraflow.html">r.terraflow</a>,
  258. <a href="r.mapcalc.html">r.mapcalc</a>,
  259. <a href="r.walk.html">r.walk</a>
  260. </em>
  261. <h2>AUTHORS</h2>
  262. Completely rewritten by Roger S. Miller, 2001<br>
  263. July 2004 at WebValley 2004, error checking and vector points added by
  264. Matteo Franchi (Liceo Leonardo Da Vinci, Trento) and
  265. Roberto Flor (ITC-irst, Trento, Italy)
  266. <!--
  267. <p>
  268. <i>Last changed: $Date$</i>
  269. -->