1r.drain(1)                  GRASS GIS User's Manual                 r.drain(1)
2
3
4

NAME

6       r.drain   - Traces a flow through an elevation model or cost surface on
7       a raster map.
8

KEYWORDS

10       raster, hydrology, cost surface
11

SYNOPSIS

13       r.drain
14       r.drain --help
15       r.drain [-cand] input=name  [direction=name]  output=name  [drain=name]
16       [start_coordinates=east,north[,east,north,...]]
17       [start_points=name[,name,...]]   [--overwrite]   [--help]   [--verbose]
18       [--quiet]  [--ui]
19
20   Flags:
21       -c
22           Copy input cell values on output
23
24       -a
25           Accumulate input values along the path
26
27       -n
28           Count cell numbers along the path
29
30       -d
31           The input raster map is a cost surface (direction surface must also
32           be specified)
33
34       --overwrite
35           Allow output files to overwrite existing files
36
37       --help
38           Print usage summary
39
40       --verbose
41           Verbose module output
42
43       --quiet
44           Quiet module output
45
46       --ui
47           Force launching GUI dialog
48
49   Parameters:
50       input=name [required]
51           Name of input elevation or cost surface raster map
52
53       direction=name
54           Name of input movement direction map associated with the cost  sur‐
55           face
56           Direction in degrees CCW from east
57
58       output=name [required]
59           Name for output raster map
60
61       drain=name
62           Name for output drain vector map
63           Recommended for cost surface made using knight’s move
64
65       start_coordinates=east,north[,east,north,...]
66           Coordinates of starting point(s) (E,N)
67
68       start_points=name[,name,...]
69           Name of starting vector points map(s)
70

DESCRIPTION

72       r.drain  traces  a flow through a least-cost path in an elevation model
73       or cost surface. For cost surfaces, a movement direction  map  must  be
74       specified  with  the  direction  option and the -d flag to trace a flow
75       path following the given directions. Such a movement direction map  can
76       be  generated  with  r.walk, r.cost, r.slope.aspect or r.watershed pro‐
77       vided that the direction is in degrees, measured counterclockwise  from
78       east.
79
80       The  output  raster  map will show one or more least-cost paths between
81       each user-provided location(s) and the minima (low category values)  in
82       the  raster  input  map.  If  the -d flag is used the output least-cost
83       paths will be found using the direction raster map.   By  default,  the
84       output will be an integer CELL map with category 1 along the least cost
85       path, and null cells elsewhere.
86
87       With the -c (copy) flag, the input raster map cell  values  are  copied
88       verbatim along the path. With the -a (accumulate) flag, the accumulated
89       cell value from the starting point up to the current cell is written on
90       output.  With  either the -c or the -a flags, the output map is created
91       with the same cell type as the input raster map (integer, float or dou‐
92       ble).   With the -n (number) flag, the cells are numbered consecutively
93       from the starting point to the final point.  The -c, -a, and  -n  flags
94       are mutually incompatible.
95
96       For  an  elevation  surface,  the  path  is  calculated by choosing the
97       steeper "slope" between adjacent cells.  The  slope  calculation  accu‐
98       rately  accounts  for  the variable scale in lat-lon projections. For a
99       cost surface, the path is calculated by following the  movement  direc‐
100       tion  surface  back  to  the start point given in r.walk or r.cost. The
101       path search stops as soon as a region border or a neighboring NULL cell
102       is  encountered, because in these cases the direction can not be deter‐
103       mined (the path could continue outside the current region).
104
105       The start_coordinates parameter consists of map E and  N  grid  coordi‐
106       nates  of  a  starting point. Each x,y pair is the easting and northing
107       (respectively) of a starting point from  which  a  least-cost  corridor
108       will be developed.  The start_points parameter can take multiple vector
109       maps containing additional starting points.  Up to 1024 starting points
110       can   be   input  from  a  combination  of  the  start_coordinates  and
111       start_points parameters.
112
113   Explanation of output values
114       Consider the following example:
115       Input:                          Output:
116         ELEVATION SURFACE               LEAST COST PATH
117       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
118       . 19. 20. 18. 19. 16. 15. 15.    .   .   .   .   .   .   .   .
119       . .  ---  . . . . . . . . . .    . . . . . . . . . . . . . . .
120       . 20| 19| 17. 16. 17. 16. 16.    .   . 1 . 1 . 1 .   .   .   .
121       . .  ---  . . . . . . . . . .    . . . . . . . . . . . . . . .
122       . 18. 18. 24. 18. 15. 12. 11.    .   .   .   .   . 1 .   .   .
123       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
124       . 22. 16. 16. 18. 10. 10. 10.    .   .   .   .   . 1 .   .   .
125       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
126       . 17. 15. 15. 15. 10. 8 . 8 .    .   .   .   .   .   . 1 .   .
127       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
128       . 24. 16. 8 . 7 . 8 . 0 . 12.    .   .   .   .   .   . 1 .   .
129       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
130       . 17. 9 . 8 . 7 . 8 . 6 . 12.    .   .   .   .   .   .   .   .
131       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
132
133       The user-provided starting location in the above example is  the  boxed
134       19  in  the  left-hand map. The path in the output shows the least-cost
135       corridor for moving from the starting box to the lowest (smallest) pos‐
136       sible point. This is the path a raindrop would take in this landscape.
137
138       With the -c (copy) flag, you get the following result:
139       Input:                          Output:
140         ELEVATION SURFACE               LEAST COST PATH
141       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
142       . 19. 20. 18. 19. 16. 15. 15.    .   .   .   .   .   .   .   .
143       . .  ---  . . . . . . . . . .    . . . . . . . . . . . . . . .
144       . 20| 19| 17. 16. 17. 16. 16.    .   . 19. 17. 16.   .   .   .
145       . .  ---  . . . . . . . . . .    . . . . . . . . . . . . . . .
146       . 18. 18. 24. 18. 15. 12. 11.    .   .   .   .   . 15.   .   .
147       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
148       . 22. 16. 16. 18. 10. 10. 10.    .   .   .   .   . 10.   .   .
149       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
150       . 17. 15. 15. 15. 10. 8 . 8 .    .   .   .   .   .   . 8 .   .
151       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
152       . 24. 16. 8 . 7 . 8 . 0 .12 .    .   .   .   .   .   . 0 .   .
153       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
154       . 17. 9 . 8 . 7 . 8 . 6 .12 .    .   .   .   .   .   .   .   .
155       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
156       Note that the last 0 will not be put in the null values map.
157
158       With the -a (accumulate) flag, you get the following result:
159       Input:                          Output:
160         ELEVATION SURFACE               LEAST COST PATH
161       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
162       . 19. 20. 18. 19. 16. 15. 15.    .   .   .   .   .   .   .   .
163       . .  ---  . . . . . . . . . .    . . . . . . . . . . . . . . .
164       . 20| 19| 17. 16. 17. 16. 16.    .   . 19. 36. 52.   .   .   .
165       . .  ---  . . . . . . . . . .    . . . . . . . . . . . . . . .
166       . 18. 18. 24. 18. 15. 12. 11.    .   .   .   .   . 67.   .   .
167       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
168       . 22. 16. 16. 18. 10. 10. 10.    .   .   .   .   . 77.   .   .
169       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
170       . 17. 15. 15. 15. 10. 8 . 8 .    .   .   .   .   .   . 85.   .
171       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
172       . 24. 16. 8 . 7 . 8 . 0 .12 .    .   .   .   .   .   . 85.   .
173       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
174       . 17. 9 . 8 . 7 . 8 . 6 .12 .    .   .   .   .   .   .   .   .
175       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
176
177       With the -n (number) flag, you get the following result:
178       Input:                          Output:
179         ELEVATION SURFACE               LEAST COST PATH
180       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
181       . 19. 20. 18. 19. 16. 15. 15.    .   .   .   .   .   .   .   .
182       . .  ---  . . . . . . . . . .    . . . . . . . . . . . . . . .
183       . 20| 19| 17. 16. 17. 16. 16.    .   . 1 . 2 . 3 .   .   .   .
184       . .  ---  . . . . . . . . . .    . . . . . . . . . . . . . . .
185       . 18. 18. 24. 18. 15. 12. 11.    .   .   .   .   . 4 .   .   .
186       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
187       . 22. 16. 16. 18. 10. 10. 10.    .   .   .   .   . 5 .   .   .
188       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
189       . 17. 15. 15. 15. 10. 8 . 8 .    .   .   .   .   .   . 6 .   .
190       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
191       . 24. 16. 8 . 7 . 8 . 0 .12 .    .   .   .   .   .   . 7 .   .
192       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
193       . 17. 9 . 8 . 7 . 8 . 6 .12 .    .   .   .   .   .   .   .   .
194       . . . . . . . . . . . . . . .    . . . . . . . . . . . . . . .
195       With  the  -d  (direction)  flag,  the direction raster is used for the
196       input, rather than the elevation surface. The output  is  then  created
197       according to one of the -can flags.
198       The directions are recorded as degrees CCW from East:
199              112.5     67.5         i.e. a cell with the value 135
200       157.5  135   90  45   22.5    means the next cell is to the North-West
201              180   x   0
202       202.5  225  270  315  337.5
203              247.5     292.5
204

NOTES

206       If  no  direction  input map is given, r.drain currently finds only the
207       lowest point (the cell having the smallest category value) in the input
208       file  that can be reached through directly adjacent cells that are less
209       than or equal in value to the cell reached  immediately  prior  to  it;
210       therefore,  it will not necessarily reach the lowest point in the input
211       file. It currently finds pits in the data, rather than the lowest point
212       in the entire input map. The r.fill.dir, r.terraflow, and r.basins.fill
213       modules can be used to fill  in  subbasins  prior  to  processing  with
214       r.drain.
215
216       r.drain  will  not  give  sane results at the region boundary. On outer
217       rows and columns bordering the edge of the region, the  flow  direction
218       is  always  directly  out  of the map. In this case, the user could try
219       adjusting the region extents slightly with g.region to allow additional
220       outlet paths for r.drain.
221

EXAMPLES

223   Path to the lowest point
224       In this example we compute drainage paths from two given points follow‐
225       ing decreasing elevation values to the lowest point.  We are using  the
226       full  North  Carolina  sample  dataset.  First we create the two points
227       from a text file using v.in.ascii module (here the text file is CSV and
228       we are using unix here-file syntax with EOF, in GUI just enter the val‐
229       ues directly for the parameter input):
230       v.in.ascii input=- output=start format=point separator=comma <<EOF
231       638667.15686275,220610.29411765
232       638610.78431373,220223.03921569
233       EOF
234       Now we compute the drainage path:
235       r.drain input=elev_lid792_1m output=drain_path drain=drain start_points=start
236       Before we visualize the result, we set a color table for the  elevation
237       we are using and we create a shaded relief map:
238       r.colors map=elev_lid792_1m color=elevation
239       r.relief input=elev_lid792_1m output=relief
240       Finally we visualize all the input and output data:
241       d.shade shade=relief color=elev_lid792_1m
242       d.vect map=drain_path color=0:0:61 width=4 legend_label="drainage paths"
243       d.vect map=start color=none fill_color=224:0:0 icon=basic/circle size=15 legend_label=origins
244       d.legend.vect -b
245       Figure:  Drainage  paths  from  two points flowing into the points with
246       lowest values
247
248   Path following directions
249       To continue flow even after it hits a depression, we need to  supply  a
250       direction raster map which will tell the r.drain module how to continue
251       from the depression. To get these directions, we  use  the  r.watershed
252       module:
253       r.watershed elevation=elev_lid792_1m accumulation=accum drainage=drain_dir
254       The  directions  are  categorical  and we convert them to degrees using
255       raster algebra:
256       r.mapcalc "drain_deg = if(drain_dir != 0, 45. * abs(drain_dir), null())"
257       Together with directions, we need to provide the  r.drain  module  with
258       cost  values. We don’t have any cost to assign to specific cells, so we
259       create a constant surface:
260       r.mapcalc "const1 = 1"
261       Now we are ready to compute the drainage paths.  We are using  the  two
262       points from the previous example.
263       r.drain -d input=const1 direction=drain_deg output=drain_path_2 drain=drain_2 start_points=start
264       We visualize the result in the same way as in the previous example.
265       Figure:  Drainage  paths from two points where directions from r.water‐
266       shed were used
267

KNOWN ISSUES

269       Sometimes, when the differences among integer cell category  values  in
270       the  r.cost  cumulative  cost surface output are small, this cumulative
271       cost output cannot accurately be used as input to r.drain (r.drain will
272       output  bad  results).   This problem can be circumvented by making the
273       differences between cell category values in the cumulative cost  output
274       bigger.  It is recommended that if the output from r.cost is to be used
275       as input to r.drain, the user multiply the r.cost  input  cost  surface
276       map  by  the value of the map’s cell resolution, before running r.cost.
277       This can be done using r.mapcalc. The map resolution can be found using
278       g.region.  This problem doesn’t arise with floating point maps.
279

SEE ALSO

281        g.region, r.cost, r.fill.dir, r.basins.fill, r.watershed, r.terraflow,
282       r.mapcalc, r.walk
283

AUTHORS

285       Completely rewritten by Roger S. Miller, 2001
286       July 2004 at WebValley 2004, error checking and vector points added  by
287       Matteo  Franchi  (Liceo  Leonardo  Da  Vinci,  Trento) and Roberto Flor
288       (ITC-irst, Trento, Italy)
289

SOURCE CODE

291       Available at: r.drain source code (history)
292
293       Main index | Raster index | Topics index | Keywords index  |  Graphical
294       index | Full index
295
296       © 2003-2020 GRASS Development Team, GRASS GIS 7.8.5 Reference Manual
297
298
299
300GRASS 7.8.5                                                         r.drain(1)
Impressum