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