1r.path(1) Grass User's Manual r.path(1)
2
3
4
6 r.path - Traces paths from starting points following input directions.
7
9 raster, hydrology, cost surface
10
12 r.path
13 r.path --help
14 r.path [-can] input=name format=string [values=name]
15 [raster_path=name] [vector_path=name] [start_coordi‐
16 nates=east,north[,east,north,...]] [start_points=name[,name,...]]
17 [--overwrite] [--help] [--verbose] [--quiet] [--ui]
18
19 Flags:
20 -c
21 Copy input cell values on output
22
23 -a
24 Accumulate input values along the path
25
26 -n
27 Count cell numbers along the path
28
29 --overwrite
30 Allow output files to overwrite existing files
31
32 --help
33 Print usage summary
34
35 --verbose
36 Verbose module output
37
38 --quiet
39 Quiet module output
40
41 --ui
42 Force launching GUI dialog
43
44 Parameters:
45 input=name [required]
46 Name of input direction
47 Direction in degrees CCW from east, or bitmask encoded
48
49 format=string [required]
50 Format of the input direction map
51 Options: auto, degree, 45degree, bitmask
52 Default: auto
53 auto: auto-detect direction format
54 degree: degrees CCW from East
55 45degree: degrees CCW from East divided by 45 (e.g. r.watershed
56 directions)
57 bitmask: bitmask encoded directions (e.g. r.cost -b)
58
59 values=name
60 Name of input raster values to be used for output
61 Name of input raster map
62
63 raster_path=name
64 Name for output raster path map
65 Name for output raster map
66
67 vector_path=name
68 Name for output vector path map
69 Name for output vector map
70
71 start_coordinates=east,north[,east,north,...]
72 Coordinates of starting point(s) (E,N)
73
74 start_points=name[,name,...]
75 Name of starting vector points map(s)
76 Or data source(s) for direct OGR access
77
79 r.path traces a path from starting points following input directions.
80 Such a movement direction map can be generated with r.walk, r.cost,
81 r.slope.aspect, r.watershed, or r.fill.dir, provided that the direction
82 is in degrees, measured counterclockwise from east.
83
84 Alternatively, bitmask-encoded directions can be provided where each
85 bit position corresponds to a specific neighbour. A path will continue
86 to all neighbours with their bit set. This means a path can split and
87 merge. Such bitmasked directions can be created with the -b flag of
88 r.cost and r.walk.
89 Direction encoding for neighbors of x
90 135 90 45 7 8 1
91 180 x 360 6 x 2
92 225 270 315 5 4 3
93 degrees bit positions
94 CCW from East
95 A path stops when the direction is zero or negative, indicating a stop
96 point or outlet.
97
98 The output raster map will show one or more least-cost paths between
99 each user-provided location(s) and the target points (direction ⤠0).
100 By default, the output will be an integer CELL map with the id of the
101 start points along the least cost path, and null cells elsewhere.
102
103 With the -c (copy) flag, the values raster map cell values are copied
104 verbatim along the path. With the -a (accumulate) flag, the accumulated
105 cell value from the starting point up to the current cell is written on
106 output. With either the -c or the -a flags, the raster_path map is cre‐
107 ated with the same cell type as the values raster map (integer, float
108 or double). With the -n (number) flag, the cells are numbered consecu‐
109 tively from the starting point to the final point. The -c, -a, and -n
110 flags are mutually incompatible.
111
112 The start_coordinates parameter consists of map E and N grid coordi‐
113 nates of a starting point. Each x,y pair is the easting and northing
114 (respectively) of a starting point from which a path will be traced
115 following input directions. The start_points parameter can take multi‐
116 ple vector maps containing additional starting points.
117
119 The directions are recorded as degrees CCW from East, the Knight’s move
120 of r.cost and r.walk is considered:
121 112.5 67.5
122 157.5 135 90 45 22.5
123 180 x 0
124 202.5 225 270 315 337.5
125 247.5 292.5
126 i.e. a cell with the value 135 means the next cell is to the
127 North-West, and a cell with the value 157.5 means that the next cell is
128 to the West-North-West.
129
131 Hydrological path
132 We are using the full North Carolina sample dataset. First we create
133 the two points from a text file using v.in.ascii module (here the text
134 file is CSV and we are using unix here-file syntax with EOF, in GUI
135 just enter the values directly for the parameter input):
136 v.in.ascii input=- output=start format=point separator=comma <<EOF
137 638667.15686275,220610.29411765
138 638610.78431373,220223.03921569
139 EOF
140 We need to supply a direction raster map to the r.path module. To get
141 these directions, we use the r.watershed module:
142 r.watershed elevation=elev_lid792_1m accumulation=accum drainage=drain_dir
143 The directions are categorical and we convert them to degrees using
144 raster algebra:
145 r.mapcalc "drain_deg = if(drain_dir != 0, 45. * abs(drain_dir), null())"
146 Now we are ready to extract the drainage paths starting at the two
147 points.
148 r.path input=drain_deg raster_path=drain_path vector_path=drain_path start_points=start
149 Before we visualize the result, we set a color table for the elevation
150 we are using and create a shaded relief map:
151 r.colors map=elev_lid792_1m color=elevation
152 r.relief input=elev_lid792_1m output=relief
153 We visualize the input and output data:
154 d.shade shade=relief color=elev_lid792_1m
155 d.vect map=drain_path color=0:0:61 width=4 legend_label="drainage paths"
156 d.vect map=start color=none fill_color=224:0:0 icon=basic/circle size=15 legend_label=origins
157 d.legend.vect -b
158 Figure: Drainage paths from two points where directions from r.water‐
159 shed were used
160
161 Least-cost path
162 We compute bitmask encoded movement directions using r.walk:
163 g.region swwake_30m -p
164 # create friction map based on land cover
165 r.recode input=landclass96 output=friction rules=- << EOF
166 1:3:0.1:0.1
167 4:5:10.:10.
168 6:6:1000.0:1000.0
169 7:7:0.3:0.3
170 EOF
171 # without Knight’s move
172 r.walk -b elevation=elev_ned_30m friction=friction output=walkcost \
173 outdir=walkdir start_coordinates=635576,216485
174 r.path input=walkdir start_coordinates=640206,222795 \
175 raster_path=walkpath vector_path=walkpath
176 # with Knight’s move
177 r.walk -b -k elevation=elev_ned_30m friction=friction output=walkcost_k \
178 outdir=walkdir_k start_coordinates=635576,216485
179 r.path input=walkdir_k start_coordinates=640206,222795 \
180 raster_path=walkpath_k vector_path=walkpath_k
181 # without Knight’s move and without bitmask encoding (single direction)
182 r.walk elevation=elev_ned_30m friction=friction output=walkcost_s \
183 outdir=walkdir_s start_coordinates=635576,216485
184 r.path input=walkdir_s start_coordinates=640206,222795 \
185 raster_path=walkpath_s vector_path=walkpath_s
186 The extracted least-cost path splits and merges on the way from the
187 start point to the stop point (start point for r.walk). Note the gaps
188 in the raster path when using the Knight’s move.
189 Figure: Comparison of shortest paths using single directions and multi‐
190 ple bitmask encoded directions without and with Knight’s move
191
193 g.region, r.basins.fill, r.cost, r.fill.dir, r.mapcalc, r.recode,
194 r.terraflow, r.walk, r.watershed
195
197 Markus Metz
198 Multiple path directions sponsored by mundialis
199
201 Available at: r.path source code (history)
202
203 Main index | Raster index | Topics index | Keywords index | Graphical
204 index | Full index
205
206 © 2003-2019 GRASS Development Team, GRASS GIS 7.8.2 Reference Manual
207
208
209
210GRASS 7.8.2 r.path(1)