[GRASS-SVN] r74016 - grass-addons/grass7/raster/r.accumulate
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jan 25 20:34:46 PST 2019
Author: hcho
Date: 2019-01-25 20:34:46 -0800 (Fri, 25 Jan 2019)
New Revision: 74016
Modified:
grass-addons/grass7/raster/r.accumulate/accumulate.c
grass-addons/grass7/raster/r.accumulate/main.c
grass-addons/grass7/raster/r.accumulate/r.accumulate.html
Log:
r.accumulate: Add input_accumulation option
Modified: grass-addons/grass7/raster/r.accumulate/accumulate.c
===================================================================
--- grass-addons/grass7/raster/r.accumulate/accumulate.c 2019-01-26 02:07:04 UTC (rev 74015)
+++ grass-addons/grass7/raster/r.accumulate/accumulate.c 2019-01-26 04:34:46 UTC (rev 74016)
@@ -10,7 +10,7 @@
int rows = dir_buf->rows, cols = dir_buf->cols;
int row, col;
- G_message(_("Accumulating flow..."));
+ G_message(_("Accumulating flows..."));
for (row = 0; row < rows; row++) {
G_percent(row, rows, 1);
for (col = 0; col < cols; col++)
Modified: grass-addons/grass7/raster/r.accumulate/main.c
===================================================================
--- grass-addons/grass7/raster/r.accumulate/main.c 2019-01-26 02:07:04 UTC (rev 74015)
+++ grass-addons/grass7/raster/r.accumulate/main.c 2019-01-26 04:34:46 UTC (rev 74016)
@@ -39,6 +39,7 @@
struct Option *dir;
struct Option *format;
struct Option *weight;
+ struct Option *input_accum;
struct Option *accum;
struct Option *thresh;
struct Option *stream;
@@ -56,8 +57,8 @@
struct Flag *conf;
} flag;
char *desc;
- char *dir_name, *weight_name, *accum_name, *stream_name, *outlet_name,
- *lfp_name;
+ char *dir_name, *weight_name, *input_accum_name, *accum_name, *stream_name,
+ *outlet_name, *lfp_name;
int dir_fd;
double dir_format, thresh;
struct Range dir_range;
@@ -103,6 +104,13 @@
opt.weight->required = NO;
opt.weight->description = _("Name of input flow weight map");
+ opt.input_accum = G_define_standard_option(G_OPT_R_INPUT);
+ opt.input_accum->key = "input_accumulation";
+ opt.input_accum->required = NO;
+ opt.input_accum->type = TYPE_STRING;
+ opt.input_accum->description =
+ _("Name of input weighted flow accumulation map");
+
opt.accum = G_define_standard_option(G_OPT_R_OUTPUT);
opt.accum->key = "accumulation";
opt.accum->required = NO;
@@ -168,6 +176,8 @@
* themselves can be negative; the longest flow path requires positive
* non-weighted accumulation */
G_option_exclusive(opt.weight, opt.lfp, flag.neg, NULL);
+ G_option_exclusive(opt.input_accum, opt.accum, NULL);
+ G_option_exclusive(opt.weight, opt.input_accum, NULL);
G_option_required(opt.accum, opt.stream, opt.lfp, NULL);
G_option_collective(opt.thresh, opt.stream, NULL);
G_option_requires(opt.lfp, opt.coords, opt.outlet, NULL);
@@ -181,6 +191,7 @@
dir_name = opt.dir->answer;
weight_name = opt.weight->answer;
+ input_accum_name = opt.input_accum->answer;
accum_name = opt.accum->answer;
stream_name = opt.stream->answer;
outlet_name = opt.outlet->answer;
@@ -362,7 +373,13 @@
G_percent(1, 1, 1);
Rast_close(dir_fd);
+ /* prepare to create accumulation buffer */
+ accum_buf.rows = rows;
+ accum_buf.cols = cols;
+ accum_buf.map.v = (void **)G_malloc(rows * sizeof(void *));
+
/* optionally, read a weight map */
+ weight_buf.map.v = NULL;
if (weight_name) {
int weight_fd = Rast_open_old(weight_name, "");
@@ -381,20 +398,30 @@
G_percent(1, 1, 1);
Rast_close(weight_fd);
}
- else {
- weight_buf.map.v = NULL;
+ /* create non-weighted accumulation if input accumulation is not given */
+ else if (!input_accum_name)
accum_buf.type = CELL_TYPE;
- }
- /* create accumulation buffer */
- accum_buf.rows = rows;
- accum_buf.cols = cols;
- accum_buf.map.v = (void **)G_malloc(rows * sizeof(void *));
- for (row = 0; row < rows; row++)
- accum_buf.map.v[row] = (void *)Rast_allocate_buf(accum_buf.type);
+ /* optionally, read an accumulation map */
+ if (input_accum_name) {
+ int accum_fd = Rast_open_old(input_accum_name, "");
- /* accumulate flows */
- accumulate(&dir_buf, &weight_buf, &accum_buf, done, neg);
+ accum_buf.type = Rast_get_map_type(accum_fd);
+ G_message(_("Reading accumulation map..."));
+ for (row = 0; row < rows; row++) {
+ G_percent(row, rows, 1);
+ accum_buf.map.v[row] = (void *)Rast_allocate_buf(accum_buf.type);
+ Rast_get_row(accum_fd, accum_buf.map.v[row], row, accum_buf.type);
+ }
+ G_percent(1, 1, 1);
+ Rast_close(accum_fd);
+ }
+ /* accumulate flows if input accumulation is not given */
+ else {
+ for (row = 0; row < rows; row++)
+ accum_buf.map.v[row] = (void *)Rast_allocate_buf(accum_buf.type);
+ accumulate(&dir_buf, &weight_buf, &accum_buf, done, neg);
+ }
/* write out buffer to the accumulatoin map if requested */
if (accum_name) {
@@ -401,6 +428,7 @@
int accum_fd = Rast_open_new(accum_name, accum_buf.type);
struct History hist;
+ G_message(_("Writing accumulation map..."));
for (row = 0; row < rows; row++)
Rast_put_row(accum_fd, accum_buf.map.v[row], accum_buf.type);
Rast_close(accum_fd);
Modified: grass-addons/grass7/raster/r.accumulate/r.accumulate.html
===================================================================
--- grass-addons/grass7/raster/r.accumulate/r.accumulate.html 2019-01-26 02:07:04 UTC (rev 74015)
+++ grass-addons/grass7/raster/r.accumulate/r.accumulate.html 2019-01-26 04:34:46 UTC (rev 74016)
@@ -1,6 +1,6 @@
<h2>DESCRIPTION</h2>
-<em>r.accumulate</em> calculates weighted flow accumulatin, stream networks,
+<em>r.accumulate</em> calculates weighted flow accumulation, stream networks,
and the longest flow path using a flow direction map.
<h2>NOTES</h2>
@@ -8,7 +8,7 @@
<h3>Flow accumulation</h3>
Unlike <em>r.watershed</em>, <em>r.accumulate</em> does not require the
-elevation data to calculate weigited flow accumulation. Instead, this module
+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.
@@ -38,6 +38,8 @@
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
@@ -101,7 +103,7 @@
<p><img src="r_accumulate_nc_comparison.png">
-<p>For comparison, these numbers show the new flow accumulatoin
+<p>For comparison, these numbers show the new flow accumulation
(<i>flow_accum_new</i> from <em>r.accumulate</em>). The same cells are properly
accumulated from the headwater cells.
More information about the grass-commit
mailing list