r.path.html 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <h2>DESCRIPTION</h2>
  2. <em>r.path</em> traces a path from starting points following input
  3. directions. Such a movement direction map can be generated with
  4. <em><a href="r.walk.html">r.walk</a></em>,
  5. <em><a href="r.cost.html">r.cost</a></em>,
  6. <em><a href="r.slope.aspect.html">r.slope.aspect</a></em>,
  7. <em><a href="r.watershed.html">r.watershed</a></em>, or
  8. <em><a href="r.fill.dir.html">r.fill.dir</a></em>,
  9. provided that the direction is in degrees, measured counterclockwise
  10. from east.
  11. <p>
  12. Alternatively, bitmask-encoded directions can be provided where each
  13. bit position corresponds to a specific neighbour. A path will continue
  14. to all neighbours with their bit set. This means a path can split and
  15. merge. Such bitmasked directions can be created with the <b>-b</b>
  16. flag of <em><a href="r.cost.html">r.cost</a></em> and
  17. <em><a href="r.walk.html">r.walk</a></em>.
  18. <div class="code"><pre>
  19. Direction encoding for neighbors of x
  20. 135 90 45 7 8 1
  21. 180 x 360 6 x 2
  22. 225 270 315 5 4 3
  23. degrees bit positions
  24. CCW from East
  25. </pre></div>
  26. A path stops when the direction is zero or negative, indicating a stop
  27. point or outlet.
  28. <p>
  29. The <b>output</b> raster map will show one or more least-cost paths
  30. between each user-provided location(s) and the target points (direction
  31. &le; 0). By default, the <b>output</b> will be an integer CELL map with
  32. the id of the start points along the least cost path, and null cells elsewhere.
  33. <p>
  34. With the <b>-c</b> (<em>copy</em>) flag, the values raster map cell values are
  35. copied verbatim along the path. With the <b>-a</b> (<em>accumulate</em>)
  36. flag, the accumulated cell value from the starting point up to the current
  37. cell is written on output. With either the <b>-c</b> or the <b>-a</b> flags, the
  38. <b>raster_path</b> map is created with the same cell type as
  39. the <b>values</b> raster map (integer, float or double). With
  40. the <b>-n</b> (<em>number</em>) flag, the cells are numbered
  41. consecutively from the starting point to the final point.
  42. The <b>-c</b>, <b>-a</b>, and <b>-n</b> flags are mutually
  43. incompatible.
  44. <p>
  45. The <b>start_coordinates</b> parameter consists of map E and N grid
  46. coordinates of a starting point. Each x,y pair is the easting and
  47. northing (respectively) of a starting point from which a path will be
  48. traced following <b>input</b> directions. The <b>start_points</b>
  49. parameter can take multiple vector maps containing additional starting
  50. points.
  51. <h2>NOTES</h2>
  52. The directions are recorded as degrees CCW from East, the Knight's move
  53. of r.cost and r.walk is considered:
  54. <div class="code"><pre>
  55. 112.5 67.5
  56. 157.5 135 90 45 22.5
  57. 180 x 0
  58. 202.5 225 270 315 337.5
  59. 247.5 292.5
  60. </pre></div>
  61. i.e. a cell with the value 135 means the next cell is to the North-West,
  62. and a cell with the value 157.5 means that the next cell is to the
  63. West-North-West.
  64. <h2>EXAMPLES</h2>
  65. <h3>Hydrological path</h3>
  66. We are using the full North Carolina sample dataset.
  67. First we create the two points from a text file using
  68. <em><a href="v.in.ascii.html">v.in.ascii</a></em> module
  69. (here the text file is CSV and we are using unix here-file syntax
  70. with EOF, in GUI just enter the values directly for the parameter input):
  71. <div class="code"><pre>
  72. v.in.ascii input=- output=start format=point separator=comma &lt;&lt;EOF
  73. 638667.15686275,220610.29411765
  74. 638610.78431373,220223.03921569
  75. EOF
  76. </pre></div>
  77. We need to supply a direction raster map to the <em>r.path</em> module.
  78. To get these directions, we use the
  79. <em><a href="r.watershed.html">r.watershed</a></em> module:
  80. <div class="code"><pre>
  81. r.watershed elevation=elev_lid792_1m accumulation=accum drainage=drain_dir
  82. </pre></div>
  83. The directions are categorical and we convert them to degrees using
  84. raster algebra:
  85. <div class="code"><pre>
  86. r.mapcalc "drain_deg = if(drain_dir != 0, 45. * abs(drain_dir), null())"
  87. </pre></div>
  88. Now we are ready to extract the drainage paths starting at the two points.
  89. <div class="code"><pre>
  90. r.path input=drain_deg raster_path=drain_path vector_path=drain_path start_points=start
  91. </pre></div>
  92. Before we visualize the result, we set a color table for the elevation
  93. we are using and create a shaded relief map:
  94. <div class="code"><pre>
  95. r.colors map=elev_lid792_1m color=elevation
  96. r.relief input=elev_lid792_1m output=relief
  97. </pre></div>
  98. We visualize the input and output data:
  99. <div class="code"><pre>
  100. d.shade shade=relief color=elev_lid792_1m
  101. d.vect map=drain_path color=0:0:61 width=4 legend_label="drainage paths"
  102. d.vect map=start color=none fill_color=224:0:0 icon=basic/circle size=15 legend_label=origins
  103. d.legend.vect -b
  104. </pre></div>
  105. <div align="center">
  106. <a href="r_path_with_r_watershed_direction.png"><img src="r_path_with_r_watershed_direction.png" alt="drainage using r.watershed" width="300" height="280"></a>
  107. <br>
  108. <i>Figure: Drainage paths from two points where directions from
  109. r.watershed were used</i>
  110. </div>
  111. <h3>Least-cost path</h3>
  112. We compute bitmask encoded movement directions using <em>r.walk:</em>
  113. <div class="code"><pre>
  114. g.region swwake_30m -p
  115. # create friction map based on land cover
  116. r.recode input=landclass96 output=friction rules=- &lt;&lt; EOF
  117. 1:3:0.1:0.1
  118. 4:5:10.:10.
  119. 6:6:1000.0:1000.0
  120. 7:7:0.3:0.3
  121. EOF
  122. # without Knight's move
  123. r.walk -b elevation=elev_ned_30m friction=friction output=walkcost \
  124. outdir=walkdir start_coordinates=635576,216485
  125. r.path input=walkdir start_coordinates=640206,222795 \
  126. raster_path=walkpath vector_path=walkpath
  127. # with Knight's move
  128. r.walk -b -k elevation=elev_ned_30m friction=friction output=walkcost_k \
  129. outdir=walkdir_k start_coordinates=635576,216485
  130. r.path input=walkdir_k start_coordinates=640206,222795 \
  131. raster_path=walkpath_k vector_path=walkpath_k
  132. # without Knight's move and without bitmask encoding (single direction)
  133. r.walk elevation=elev_ned_30m friction=friction output=walkcost_s \
  134. outdir=walkdir_s start_coordinates=635576,216485
  135. r.path input=walkdir_s start_coordinates=640206,222795 \
  136. raster_path=walkpath_s vector_path=walkpath_s
  137. </pre></div>
  138. <!--
  139. d.vect map=walkpath_s color=243:66:53 width=10 legend_label="Single direction"
  140. d.vect map=walkpath color=254:192:6 width=4 legend_label=Bitmask
  141. d.vect map=walkpath_k color=62:80:180 width=2 legend_label="Bitmask + knight's"
  142. -->
  143. The extracted least-cost path splits and merges on the way from
  144. the start point to the stop point (start point for r.walk). Note the
  145. gaps in the raster path when using the Knight's move.
  146. <div class="code"><pre>
  147. </pre></div>
  148. <div align="center">
  149. <a href="r_path_with_bitmask.png">
  150. <img src="r_path_with_bitmask.png" alt="least cost path using bitmask" width="600" height="274">
  151. </a>
  152. <br>
  153. <i>Figure: Comparison of shortest paths using single directions and
  154. multiple bitmask encoded directions without and with Knight's move</i>
  155. </div>
  156. <h2>SEE ALSO</h2>
  157. <em>
  158. <a href="g.region.html">g.region</a>,
  159. <a href="r.basins.fill.html">r.basins.fill</a>,
  160. <a href="r.cost.html">r.cost</a>,
  161. <a href="r.fill.dir.html">r.fill.dir</a>,
  162. <a href="r.mapcalc.html">r.mapcalc</a>,
  163. <a href="r.recode.html">r.recode</a>,
  164. <a href="r.terraflow.html">r.terraflow</a>,
  165. <a href="r.walk.html">r.walk</a>,
  166. <a href="r.watershed.html">r.watershed</a>
  167. </em>
  168. <h2>AUTHORS</h2>
  169. Markus Metz<br>
  170. Multiple path directions sponsored by <a href="https://www.mundialis.de">mundialis</a>
  171. <p>
  172. <i>Last changed: $Date$</i>