[GRASS-SVN] r57762 - grass/trunk/raster/r.water.outlet
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Sep 20 05:55:05 PDT 2013
Author: martinl
Date: 2013-09-20 05:55:03 -0700 (Fri, 20 Sep 2013)
New Revision: 57762
Modified:
grass/trunk/raster/r.water.outlet/basin.h
grass/trunk/raster/r.water.outlet/main.c
grass/trunk/raster/r.water.outlet/r.water.outlet.html
Log:
r.water.outlet: #2084 (Combine r.water.outlet easting=, northing= into
coordinates= (G_OPT_M_COORDS) for mouse interactivity in g.gui).
update manual
fix compiler warning for MIN define
Modified: grass/trunk/raster/r.water.outlet/basin.h
===================================================================
--- grass/trunk/raster/r.water.outlet/basin.h 2013-09-20 12:39:39 UTC (rev 57761)
+++ grass/trunk/raster/r.water.outlet/basin.h 2013-09-20 12:55:03 UTC (rev 57762)
@@ -7,7 +7,10 @@
#define AR_SIZE 16
#define AR_INCR 64
#define ABS(x) (((x) < 0) ? -(x) : (x))
-#define MIN(x,y) (((x) < (y)) ? (x) : (y))
+#ifdef MIN
+ #undef MIN
+ #define MIN(x,y) (((x) < (y)) ? (x) : (y))
+#endif
#define MAX_RAM 1000000
#define SROW 11
#define SCOL 10
Modified: grass/trunk/raster/r.water.outlet/main.c
===================================================================
--- grass/trunk/raster/r.water.outlet/main.c 2013-09-20 12:39:39 UTC (rev 57761)
+++ grass/trunk/raster/r.water.outlet/main.c 2013-09-20 12:55:03 UTC (rev 57762)
@@ -13,7 +13,7 @@
* PURPOSE: this program makes a watershed basin raster map using the
* drainage pointer map, from an outlet point defined by an
* easting and a northing.
- * COPYRIGHT: (C) 1999-2006, 2010 by the GRASS Development Team
+ * COPYRIGHT: (C) 1999-2006, 2010, 2013 by the GRASS Development Team
*
* This program is free software under the GNU General Public
* License (>=v2). Read the file COPYING that comes with GRASS
@@ -56,58 +56,44 @@
CELL *cell_buf;
char drain_name[GNAME_MAX], E_f, dr_f, ba_f, N_f, errr;
struct GModule *module;
- struct Option *opt1, *opt2, *opt3, *opt4;
+ struct {
+ struct Option *input, *output, *coords;
+ } opt;
G_gisinit(argv[0]);
module = G_define_module();
- module->description = _("Creates watershed basins.");
+ module->description = _("Creates watershed basins from a drainage direction map.");
G_add_keyword(_("raster"));
G_add_keyword(_("hydrology"));
G_add_keyword(_("watershed"));
- opt1 = G_define_standard_option(G_OPT_R_INPUT);
+ opt.input = G_define_standard_option(G_OPT_R_INPUT);
- opt2 = G_define_standard_option(G_OPT_R_OUTPUT);
+ opt.output = G_define_standard_option(G_OPT_R_OUTPUT);
- opt3 = G_define_option();
- opt3->key = "easting";
- opt3->type = TYPE_STRING;
- opt3->key_desc = "x";
- opt3->multiple = NO;
- opt3->required = YES;
- opt3->description = _("Easting grid coordinates");
+ opt.coords = G_define_standard_option(G_OPT_M_COORDS);
+ opt.coords->description = _("Coordinates of outlet point");
+ opt.coords->required = YES;
- opt4 = G_define_option();
- opt4->key = "northing";
- opt4->type = TYPE_STRING;
- opt4->key_desc = "y";
- opt4->multiple = NO;
- opt4->required = YES;
- opt4->description = _("Northing grid coordinates");
-
/* Parse command line */
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
G_get_window(&window);
- strcpy(drain_name, opt1->answer);
- strcpy(basin_name, opt2->answer);
- if (!G_scan_easting(*opt3->answers, &E, G_projection())) {
- G_warning(_("Illegal east coordinate <%s>\n"), opt3->answer);
- G_usage();
- exit(EXIT_FAILURE);
- }
- if (!G_scan_northing(*opt4->answers, &N, G_projection())) {
- G_warning(_("Illegal north coordinate <%s>\n"), opt4->answer);
- G_usage();
- exit(EXIT_FAILURE);
- }
+ strcpy(drain_name, opt.input->answer);
+ strcpy(basin_name, opt.output->answer);
+ if (!G_scan_easting(opt.coords->answers[0], &E, G_projection()))
+ G_fatal_error(_("Illegal east coordinate '%s'"), opt.coords->answers[0]);
+ if (!G_scan_northing(opt.coords->answers[1], &N, G_projection()))
+ G_fatal_error(_("Illegal north coordinate '%s'"), opt.coords->answers[1]);
+
+ G_debug(1, "easting = %.4f northing = %.4f", E, N);
if (E < window.west || E > window.east || N < window.south ||
N > window.north) {
- G_warning(_("Warning, ignoring point outside window: \n %.4f,%.4f\n"),
+ G_warning(_("Ignoring point outside computation region: %.4f,%.4f"),
E, N);
}
@@ -144,6 +130,7 @@
basin_fd = Rast_open_c_new(basin_name);
for (row = 0; row < nrows; row++) {
+ G_percent(row, nrows, 5);
for (col = 0; col < ncols; col++) {
cell_buf[col] = bas[SEG_INDEX(ba_seg, row, col)];
if (cell_buf[col] == 0)
@@ -151,9 +138,11 @@
}
Rast_put_row(basin_fd, cell_buf, CELL_TYPE);
}
+ G_percent(1, 1, 1);
+
G_free(bas);
G_free(cell_buf);
Rast_close(basin_fd);
- return 0;
+ exit(EXIT_SUCCESS);
}
Modified: grass/trunk/raster/r.water.outlet/r.water.outlet.html
===================================================================
--- grass/trunk/raster/r.water.outlet/r.water.outlet.html 2013-09-20 12:39:39 UTC (rev 57761)
+++ grass/trunk/raster/r.water.outlet/r.water.outlet.html 2013-09-20 12:55:03 UTC (rev 57762)
@@ -1,71 +1,56 @@
<h2>DESCRIPTION</h2>
<em>r.water.outlet</em> generates a watershed basin from a drainage
-direction map (from <em><a href="r.watershed.html">r.watershed</a></em>) and
-a set of coordinates representing the outlet point of watershed.
+direction map and a set of coordinates representing the outlet point
+of watershed.
-<h3>Selected Parameters</h3>
-<dl>
-
-<dt><b>input=</b><em>name</em>
-
-<dd>Input map: drainage direction. Indicates the "aspect" for each
-cell. Multiplying positive values by 45 will give the direction in
-degrees that the surface runoff will travel from that cell. The
-value -1 indicates that the cell is a depression area.
-Other negative values indicate that
-surface runoff is leaving the boundaries of the current geographic
-region. The absolute value of these negative cells indicates the
-direction of flow. This map is generated from
+<p>
+Input drainage direction map indicates the "aspect" for each
+cell. Multiplying positive values by 45 will give the direction in
+degrees that the surface runoff will travel from that cell. The value
+-1 indicates that the cell is a depression area. Other negative values
+indicate that surface runoff is leaving the boundaries of the current
+geographic region. The absolute value of these negative cells
+indicates the direction of flow. This raster map is generated from
<em><a href="r.watershed.html">r.watershed</a></em>.
-<dt><b>output=</b><em>name</em>
+<p>
+Output raster map values of one (1) indicate the watershed
+basin. Values of zero (0) are not in the watershed basin.
-<dd>Output map: Values of one (1) indicate the watershed
-basin. Values of zero are not in the watershed basin.
-
-<dt><b>easting=</b><em>value</em>
-
-<dd>Input value: Easting value of outlet point.
-
-<dt><b>northing=</b><em>value</em>
-
-<dd>Input value: Northing value of outlet point.
-
-</dl>
-
<h2>NOTES</h2>
-In the context of this program, a watershed basin is the
-region upstream of an outlet point. Thus, if the user
-chooses an outlet point on a hill slope, the resulting map
-will be a thin silver of land representing the overland
-slope uphill of the point.
+In the context of this program, a watershed basin is the region
+upstream of an outlet point. Thus, if the user chooses an outlet point
+on a hill slope, the resulting map will be a thin silver of land
+representing the overland slope uphill of the point.
<h2>EXAMPLE</h2>
-A watershed in the North Carolina sample dataset region:
+A watershed in
+the <a href="http://grass.osgeo.org/download/sample-data/">North
+Carolina sample dataset</a> region:
<div class="code"><pre>
g.region rast=elev_lid792_1m -p
# the watershed outlet position should be placed on a stream (from
# accumulation map):
-r.watershed elev_lid792_1m thresh=5000 accum=accum_5K \
- drain=draindir_5K output=basin_5K
-r.water.outlet input=draindir_5K output=basin_A30 \
- east=638741.43125 north=220269.7
-d.mon x0
-d.rast accum_5K
-d.rast -o basin_A30
+r.watershed elev_lid792_1m thresh=5000 accum=accum_5K drain=draindir_5K basin=basin_5K
+r.water.outlet input=draindir_5K output=basin_A30 coord=638741.43125,220269.7
+d.mon wx0
+d.rast map=accum_5K
+d.rast map=basin_A30
+
# overlay with transparency
-r.colors basin_A30 color=grey
+r.colors map=basin_A30 color=grey
d.his h=accum_5K i=basin_A30
</pre></div>
-<p><center>
+<p>
+<center>
<img src="r_water_outlet.png" border=0><br>
-<i>Watershed draped over flow accumulation</i>
+<i>Figure: Watershed draped over flow accumulation</i>
</center>
<h2>SEE ALSO</h2>
@@ -81,4 +66,5 @@
Charles Ehlschlaeger, U.S. Army Construction Engineering Research Laboratory
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>
More information about the grass-commit
mailing list