[GRASS-SVN] r72908 - grass-addons/grass7/raster/r.accumulate

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 25 22:42:05 PDT 2018


Author: hcho
Date: 2018-06-25 22:42:05 -0700 (Mon, 25 Jun 2018)
New Revision: 72908

Added:
   grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_multiple.png
   grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single.png
   grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single_warning.png
   grass-addons/grass7/raster/r.accumulate/r_watershed_nc_example.png
Removed:
   grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_r_watershed_output.png
Modified:
   grass-addons/grass7/raster/r.accumulate/main.c
   grass-addons/grass7/raster/r.accumulate/r.accumulate.html
Log:
r.accumulate: Add longest flow path examples from r.lfp manual

Modified: grass-addons/grass7/raster/r.accumulate/main.c
===================================================================
--- grass-addons/grass7/raster/r.accumulate/main.c	2018-06-26 04:57:30 UTC (rev 72907)
+++ grass-addons/grass7/raster/r.accumulate/main.c	2018-06-26 05:42:05 UTC (rev 72908)
@@ -42,13 +42,13 @@
         struct Option *accum;
         struct Option *thresh;
         struct Option *stream;
-        struct Option *lfp;
-        struct Option *idcol;
         struct Option *coords;
         struct Option *id;
         struct Option *outlet;
         struct Option *outlet_layer;
         struct Option *outlet_idcol;
+        struct Option *idcol;
+        struct Option *lfp;
     } opt;
     struct
     {
@@ -55,8 +55,7 @@
         struct Flag *neg;
     } flag;
     char *desc;
-    char *dir_name, *weight_name, *accum_name, *stream_name, *lfp_name,
-        *outlet_name;
+    char *dir_name, *weight_name, *accum_name, *stream_name, *outlet_name, *lfp_name;
     int dir_fd;
     double dir_format, thresh;
     struct Range dir_range;
@@ -69,7 +68,7 @@
     struct Map_info Map;
     struct point_list outlet_pl;
     int *id;
-    char *idcol, *outlet_layer, *outlet_idcol;
+    char *outlet_layer, *outlet_idcol, *idcol;
 
     G_gisinit(argv[0]);
 
@@ -118,15 +117,6 @@
     opt.stream->required = NO;
     opt.stream->description = _("Name for output stream vector map");
 
-    opt.lfp = G_define_standard_option(G_OPT_V_OUTPUT);
-    opt.lfp->key = "longest_flow_path";
-    opt.lfp->required = NO;
-    opt.lfp->description = _("Name for output longest flow path vector map");
-
-    opt.idcol = G_define_standard_option(G_OPT_DB_COLUMN);
-    opt.idcol->key = "id_column";
-    opt.idcol->description = _("Name for output longest flow path ID column");
-
     opt.coords = G_define_standard_option(G_OPT_M_COORDS);
     opt.coords->multiple = YES;
     opt.coords->description =
@@ -153,6 +143,15 @@
     opt.outlet_idcol->description =
         _("Name of longest flow path ID column in outlet vector map");
 
+    opt.idcol = G_define_standard_option(G_OPT_DB_COLUMN);
+    opt.idcol->key = "id_column";
+    opt.idcol->description = _("Name for output longest flow path ID column");
+
+    opt.lfp = G_define_standard_option(G_OPT_V_OUTPUT);
+    opt.lfp->key = "longest_flow_path";
+    opt.lfp->required = NO;
+    opt.lfp->description = _("Name for output longest flow path vector map");
+
     flag.neg = G_define_flag();
     flag.neg->key = 'n';
     flag.neg->label =
@@ -176,12 +175,12 @@
     weight_name = opt.weight->answer;
     accum_name = opt.accum->answer;
     stream_name = opt.stream->answer;
+    outlet_name = opt.outlet->answer;
     lfp_name = opt.lfp->answer;
-    outlet_name = opt.outlet->answer;
 
-    idcol = opt.idcol->answer;
     outlet_layer = opt.outlet_layer->answer;
     outlet_idcol = opt.outlet_idcol->answer;
+    idcol = opt.idcol->answer;
 
     if (opt.id->answers && outlet_name && !outlet_idcol)
         G_fatal_error(_("Option <%s> must be specified when <%s> and <%s> are present"),
@@ -282,7 +281,7 @@
                                                              &Map));
             if (db_column_Ctype(driver, Fi->table, outlet_idcol) !=
                 DB_C_TYPE_INT)
-                G_fatal_error(_("Column <%s> in vector map <%s> must be of integer"),
+                G_fatal_error(_("Column <%s> in vector map <%s> must be of integer type"),
                               outlet_idcol, outlet_name);
         }
 
@@ -307,8 +306,11 @@
             if (driver) {
                 dbValue val;
 
-                db_select_value(driver, Fi->table, Fi->key, cat, outlet_idcol,
-                                &val);
+                if (db_select_value
+                    (driver, Fi->table, Fi->key, cat, outlet_idcol, &val) < 0)
+                    G_fatal_error(_("Unable to read column <%s> in vector map <%s>"),
+                                  outlet_idcol, outlet_name);
+
                 id[n++] = db_get_value_int(&val);
             }
         }

Modified: grass-addons/grass7/raster/r.accumulate/r.accumulate.html
===================================================================
--- grass-addons/grass7/raster/r.accumulate/r.accumulate.html	2018-06-26 04:57:30 UTC (rev 72907)
+++ grass-addons/grass7/raster/r.accumulate/r.accumulate.html	2018-06-26 05:42:05 UTC (rev 72908)
@@ -32,6 +32,17 @@
                    (r.watershed drainage)
 </pre></div>
 
+<p>With <b>longest_flow_path</b> option, the module will create a longest flow
+path vector map for outlet points speecified by <b>coordinates</b> and/or
+<b>outlet</b> with <b>outlet_layer</b> option. 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.
@@ -61,7 +72,7 @@
 
 <p>For some reaon, there are slight differences between the two output maps.
 
-<p><img src="r_accumulate_nc_r_watershed_output.png">
+<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
@@ -105,11 +116,81 @@
 
 <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>
+# calculate outlet point and 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>
+# calculate longest flow paths at two outlets
+r.accumulate direction=drain_directions lfp=lfp coordinates=642455,222614,642306,222734
+
+# calculate longest flow paths at two outlets and assign IDs
+r.accumulate direction=drain_directions lfp=lfp coordinates=642455,222614,642306,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 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 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 coordinates=642455,222614,642306,222734 outlet=outlets \
+    id=1,2 id_column=lfp_id outlet_id_column=outlet_id
+</pre></div>
+
+<p>Calculate the longest flow paths for sub-watersheds:
+<div class="code"><pre>
+# 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 columns="length double"
+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
+</pre></div>
+
+<img src="r_accumulate_nc_lfp_example_multiple.png">
+
 <h2>SEE ALSO</h2>
 
 <em>
-<a href="r.watershed.html">r.watershed</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="http://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>
 

Added: grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_multiple.png
===================================================================
(Binary files differ)

Index: grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_multiple.png
===================================================================
--- grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_multiple.png	2018-06-26 04:57:30 UTC (rev 72907)
+++ grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_multiple.png	2018-06-26 05:42:05 UTC (rev 72908)

Property changes on: grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_multiple.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+image/png
\ No newline at end of property
Added: grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single.png
===================================================================
(Binary files differ)

Index: grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single.png
===================================================================
--- grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single.png	2018-06-26 04:57:30 UTC (rev 72907)
+++ grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single.png	2018-06-26 05:42:05 UTC (rev 72908)

Property changes on: grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+image/png
\ No newline at end of property
Added: grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single_warning.png
===================================================================
(Binary files differ)

Index: grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single_warning.png
===================================================================
--- grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single_warning.png	2018-06-26 04:57:30 UTC (rev 72907)
+++ grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single_warning.png	2018-06-26 05:42:05 UTC (rev 72908)

Property changes on: grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_lfp_example_single_warning.png
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+image/png
\ No newline at end of property
Deleted: grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_r_watershed_output.png
===================================================================
(Binary files differ)

Copied: grass-addons/grass7/raster/r.accumulate/r_watershed_nc_example.png (from rev 72907, grass-addons/grass7/raster/r.accumulate/r_accumulate_nc_r_watershed_output.png)
===================================================================
(Binary files differ)



More information about the grass-commit mailing list