|
@@ -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,35 +56,25 @@ int main(int argc, char *argv[])
|
|
|
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");
|
|
|
-
|
|
|
- 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");
|
|
|
+ opt.coords = G_define_standard_option(G_OPT_M_COORDS);
|
|
|
+ opt.coords->description = _("Coordinates of outlet point");
|
|
|
+ opt.coords->required = YES;
|
|
|
|
|
|
/* Parse command line */
|
|
|
if (G_parser(argc, argv))
|
|
@@ -92,22 +82,18 @@ int main(int argc, char *argv[])
|
|
|
|
|
|
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 @@ int main(int argc, char *argv[])
|
|
|
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 @@ int main(int argc, char *argv[])
|
|
|
}
|
|
|
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);
|
|
|
}
|