-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathr.accumulate.lessmem.html
290 lines (217 loc) · 11.7 KB
/
r.accumulate.lessmem.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<h2>DESCRIPTION</h2>
<em>r.accumulate.lessmem</em> calculates weighted flow accumulation, stream
networks, and the longest flow path using a flow direction map. It is a
modified version of <em>r.accumulate</em> and requires less memory. It can be
slower than <em>r.accumulate</em> because of heavy bit operations.
<h2>NOTES</h2>
<h3>Flow accumulation</h3>
Unlike <em>r.watershed</em>, <em>r.accumulate.lessmem</em> does not require the
elevation data to calculate weighted flow accumulation. Instead, this module
only uses a flow direction map to trace and accumulate the amount of flow
draining through and including each cell.
<p>With <b>-n</b> flag, the module will count the number of upstream cells plus
one and convert it to the negative if any upstream cells are likely to receive
flow from outside the computational region (flow direction edges). Negative
values identify cells with likely underestimates because not all upstream cells
were accounted for. Since raster map <b>weight</b> may contain negative flow
weights, <b>-n</b> flag is not compatible with <b>weight</b> option. Running
the module twice with and without <b>-n</b> flag and <b>weight</b> option may
be useful in this specific case.
<p>The module recognizes two different formats of the flow direction map:
<div align="center">
<img src="r_accumulate_formats.png" alt="degree">
</div>
<p>Since the module does not use elevation data (i.e., slope), flow
accumulation is calculated by single flow direction (SFD) routing and may not
be comparable to the result from multiple flow direction (MFD) routing.
<p>The module requires flow accumulation for any output, so it will internally
accumulate flows every time it runs unless <b>input_accumulation</b> option is
provided to save computational time by not repeating this process. In this
case, it is important to use flow accumulation consistent with the flow
direction map (e.g., <b>accumulation</b> output from this module).
<h3>Stream network delineation</h3>
With <b>stream</b> and <b>threshold</b> options, the module will delineate
stream networks with the minimum flow accumulation for stream generation. A
<b>weight</b> input map may be used with <b>threshold</b>. Delineated stream
lines are split at confluences.
<p>With <b>-c</b> flag, stream lines are delineated across confluences and may
overlap with other stream lines that share the same downstream outlet.
<p>With <b>input_subaccumulation</b> option, streams will be delineated as if
there are no incoming flows from upstream subwatersheds defined by
subaccumulation. This option is useful when you want to delineate streams
completely contained inside a subwatershed without considering the main channel
coming from outside the subwatershed (e.g., surface runoff within
subwatersheds).
<h3>Longest flow path calculation</h3>
With <b>longest_flow_path</b> option, the module will create a longest flow
path vector map for outlet points specified by <b>coordinates</b> and/or
<b>outlet</b> with <b>outlet_layer</b> option. By default, longest flow paths
will be created as if there were subwatersheds at the outlets by calculating
the subaccumulation map. Downstream longest flow paths will never traverse
through upstream outlets. With <b>-a</b> flag, longest flow paths will be
created in an accumulated manner resulting in an overlap between downstream and
upstream longest flow paths.
<p>You can assign unique IDs to longest flow paths using <b>id</b> (with
<b>coordinates</b>) and/or <b>outlet_id_column</b> (with <b>outlet</b>).
Assigning IDs also requires <b>id_column</b> option to specify the output
column name for the IDs in the <b>longest_flow_path</b> vector map. The
<b>outlet_id_column</b> specifies a column in the <b>outlet</b> vector map that
contains unique IDs to be copied over to the <b>id_column</b> column in the
output map. This column must be of integer type.
<h2>EXAMPLES</h2>
These examples use the North Carolina sample dataset.
<h3>Flow accumulation</h3>
<p>Calculate flow accumulation using <em>r.watershed</em> and
<em>r.accumulate.lessmem</em>:
<div class="code"><pre>
# set computational region
g.region raster=elevation -p
# calculate positive flow accumulation and drainage directions using r.watershed
# for comparison, use -s (SFD)
r.watershed elevation=elevation accumulation=flow_accum drainage=drain_directions -s -a
# calculate flow accumulation using r.accumulate
r.accumulate direction=drain_directions accumulation=flow_accum_new
# copy color table
r.colors map=flow_accum_new raster=flow_accum
# check difference betwen flow_accum and flow_accum_new
r.mapcalc expression="accum_diff=if(flow_accum-flow_accum_new, flow_accum-flow_accum_new, null())"
</pre></div>
<img src="r_accumulate_nc_example.png">
<p>For some reaon, there are slight differences between the two output maps.
<p><img src="r_watershed_nc_example.png">
<p>The yellow and purple cells show the difference raster map
(<i>accum_diff</i>). The red arrows and numbers represent drainage directions
(<i>drain_directions</i>) and flow accumulation (<i>flow_accum</i> from
<em>r.watershed</em>), respectively. Note that some cells close to headwater
cells are assigned 1 even if they are located downstream of other cells.
<p><img src="r_accumulate_nc_comparison.png">
<p>For comparison, these numbers show the new flow accumulation
(<i>flow_accum_new</i> from <em>r.accumulate.lessmem</em>). The same cells are
properly accumulated from the headwater cells.
<h3>Stream network delineation</h3>
<p>Calculate flow accumulation and delineate stream networks at once:
<div class="code"><pre>
# set computational region
g.region raster=elevation -p
# calculate positive flow accumulation and drainage directions using r.watershed
# for comparison, use -s (SFD)
r.watershed elevation=elevation accumulation=flow_accum drainage=drain_directions -s -a
# use r.accumulate to create flow_accum_new and streams_new at once
r.accumulate direction=drain_directions accumulation=flow_accum_new threshold=50000 \
stream=streams_new
# or delineate stream networks only without creating an accumulation map
r.accumulate direction=drain_directions threshold=50000 stream=streams_new_only
# use r.stream.extract, elevation, and flow_accum to delineate stream networks
r.stream.extract elevation=elevation accumulation=flow_accum threshold=50000 \
stream_vector=streams_extract direction=drain_directions_extract
</pre></div>
<img src="r_accumulate_nc_stream_example.png">
<p>In this example, <em>r.accumulate.lessmem</em> and <em>r.stream.extract</em>
produced slightly different stream networks where the flow turns 90 degrees or
there are multiple downstream cells with the same elevation. The following
figure shows an example where the <i>streams</i> (red from
<em>r.stream.extract</em>) and <i>streams_new</i> (blue from
<em>r.accumulate.lessmem</em>) vector maps present different stream paths. The
numbers show cell elevations (<i>elevation</i> map), and the yellow
(<i>drain_directions</i> map) and green (<i>drain_directions_2</i> map) arrows
represent flow directions generated by <em>r.watershed</em> with <b>-s</b> flag
and <em>r.stream.extract</em>, respectively. Note that the two flow direction
maps are different.
<p><img src="r_accumulate_nc_stream_comparison.png">
<h3>Longest flow path calculation</h3>
<p>Create the longest flow path for one outlet:
<div class="code"><pre>
# set computational region
g.region raster=elevation -p
# calculate drainage directions using r.watershed
r.watershed elevation=elevation drainage=drain_directions -s -a
# delineate watershed
r.water.outlet input=drain_directions output=basin coordinates=642455,222614
# calculate longest flow path
r.accumulate direction=drain_directions lfp=lfp coordinates=642455,222614
</pre></div>
<img src="r_accumulate_nc_lfp_example_single.png">
<p>Note that there can be more than one longest flow path when multiple paths
have the same flow length. In fact, the above example produces two lines with
the same length.
<p><img src="r_accumulate_nc_lfp_example_single_warning.png">
<p>There are different ways to calculate multiple longest flow paths in one run:
<div class="code"><pre>
# set computational region
g.region raster=elevation -p
# calculate drainage directions using r.watershed
r.watershed elevation=elevation drainage=drain_directions -s -a
# calculate longest flow paths at two outlets
r.accumulate direction=drain_directions lfp=lfp coordinates=642455,222614,642314,222734
# calculate longest flow paths at two outlets and assign IDs
r.accumulate direction=drain_directions lfp=lfp_w_id coordinates=642455,222614,642314,222734 \
id=1,2 id_column=lfp_id
# calculate longest flow paths at all points in the outlets map
r.accumulate direction=drain_directions lfp=lfp_at_outlets outlet=outlets
# calculate longest flow paths at all points in the outlets map and assign IDs using a column \
# in this map
r.accumulate direction=drain_directions lfp=lfp_at_outlets_w_id outlet=outlets \
id_column=lfp_id outlet_id_column=outlet_id
# calculate longest flow paths at given coordinates and all points in the outlets map and \
# assign IDs
r.accumulate direction=drain_directions lfp=lfp_multi_w_id \
coordinates=642455,222614,642314,222734 \
outlet=outlets id=1,2 id_column=lfp_id outlet_id_column=outlet_id
</pre></div>
<p><img src="r_accumulate_nc_lfp_example_multiple.png">
<p>Calculate the longest flow paths for subwatersheds:
<div class="code"><pre>
# set computational region
g.region raster=elevation -p
# calculate drainage directions using r.watershed
r.watershed elevation=elevation drainage=drain_directions -s -a
# get nsres
eval `r.info -g map=elevation`
# delineate streams using a threshold
r.accumulate direction=drain_directions threshold=50000 stream=streams
# populate stream lengths
v.db.addtable map=streams
v.to.db map=streams option=length columns=length
# create points along the streams starting from downstream
v.to.points -r input=streams output=stream_points dmax=$nsres
# find outlets (downstream-most less nsres points)
cats=`db.select -c sql="select stream_points_2.cat from stream_points_2 \
inner join stream_points_1 on stream_points_1.cat = stream_points_2.lcat \
where length-along > 0.5*$nsres and length-along < 1.5*$nsres"`
cats=`echo $cats | tr " " ,`
v.extract input=stream_points layer=2 cats=$cats output=stream_outlets
# create the longest flow paths for all outlets
r.accumulate direction=drain_directions lfp=lfp id_column=id \
outlet=stream_outlets outlet_layer=2 outlet_id_column=lcat
# delineate subwatersheds
i=1
coors=`v.report -c map=stream_outlets layer=2 option=coor | awk -F'|' '{printf "%s,%s\n", $4, $5}'`
for coor in $coors; do
r.water.outlet --o input=drain_directions output=tmp coordinates=$coor
r.mapcalc expression="subwatershed_$i=if(isnull(tmp),0,1<<($i-1))"
i=`expr $i + 1`
done
# patch subwatersheds
subwatersheds=`g.list type=rast pattern=subwatershed_* sep=+`
r.mapcalc express="subwatersheds=if($subwatersheds,$subwatersheds,null())"
# convert subwatersheds to vector
r.to.vect input=subwatersheds type=area output=subwatersheds
# delete subwatershed rasters
g.remove -f type=rast pattern=subwatershed*
</pre></div>
<img src="r_accumulate_nc_lfp_example_subwatersheds.png">
<h2>SEE ALSO</h2>
<em>
<a href="r.accumulate.html">r.accumulate</a>,
<a href="r.watershed.html">r.watershed</a>,
<a href="r.stream.extract.html">r.stream.extract</a>,
<a href="r.stream.distance.html">r.stream.distance</a>
</em>
<br><a href="https://idea.isnew.info/how-to-delineate-stream-networks-in-grass-gis.html">How to delineate stream networks in GRASS GIS</a>
<br><a href="https://idea.isnew.info/how-to-calculate-the-longest-flow-path-in-grass-gis.html">How to calculate the longest flow path in GRASS GIS</a>
<h2>AUTHOR</h2>
<a href="mailto:grass4u@gmail com">Huidae Cho</a>
<!--
<p>
<i>Last changed: $Date$</i>
-->