[GRASS-SVN] r68434 - in grass/trunk/imagery: i.cluster i.gensig i.gensigset
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun May 15 05:43:14 PDT 2016
Author: marisn
Date: 2016-05-15 05:43:14 -0700 (Sun, 15 May 2016)
New Revision: 68434
Modified:
grass/trunk/imagery/i.cluster/main.c
grass/trunk/imagery/i.cluster/open_files.c
grass/trunk/imagery/i.gensig/parse.c
grass/trunk/imagery/i.gensigset/parse.c
Log:
Imagery modules: Ask to overwrite signature files. Fixes #3000
Modified: grass/trunk/imagery/i.cluster/main.c
===================================================================
--- grass/trunk/imagery/i.cluster/main.c 2016-05-15 12:37:40 UTC (rev 68433)
+++ grass/trunk/imagery/i.cluster/main.c 2016-05-15 12:43:14 UTC (rev 68434)
@@ -91,7 +91,7 @@
parm.out_sig->type = TYPE_STRING;
parm.out_sig->key_desc = "name";
parm.out_sig->required = YES;
- parm.out_sig->gisprompt = "old,sig,sigfile";
+ parm.out_sig->gisprompt = "new,sig,sigfile";
parm.out_sig->description = _("Name for output file containing result signatures");
parm.class = G_define_option();
@@ -160,6 +160,25 @@
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
+ group = parm.group_name->answer; /* a required parameter */
+ subgroup = parm.subgroup_name->answer; /* required */
+ outsigfile = parm.out_sig->answer;
+
+ /* check all the inputs */
+ if (!I_find_group(group)) {
+ G_fatal_error(_("Group <%s> not found in current mapset"), group);
+ }
+ if (!I_find_subgroup(group, subgroup)) {
+ G_fatal_error(_("Subgroup <%s> in group <%s> not found"), subgroup, group);
+ }
+
+ /* GRASS parser fails to detect existing signature files as
+ * detection needs answers from other parameters as group and subgroup.
+ * Thus check is performed only now. */
+ if (!G_get_overwrite() && I_find_signature_file(group, subgroup, "sig", outsigfile)) {
+ G_fatal_error(_("option <%s>: <%s> exists. To overwrite, use the --overwrite flag"),
+ parm.out_sig->key, parm.out_sig->answer);
+ }
G_get_window(&window);
nrows = Rast_window_rows();
@@ -167,11 +186,7 @@
I_cluster_clear(&C);
- group = parm.group_name->answer; /* a required parameter */
- subgroup = parm.subgroup_name->answer; /* required */
- outsigfile = parm.out_sig->answer;
-
if (sscanf(parm.class->answer, "%d", &maxclass) != 1 || maxclass < 1
|| maxclass > 255) {
G_fatal_error(_("Illegal number of initial classes (%s)"),
Modified: grass/trunk/imagery/i.cluster/open_files.c
===================================================================
--- grass/trunk/imagery/i.cluster/open_files.c 2016-05-15 12:37:40 UTC (rev 68433)
+++ grass/trunk/imagery/i.cluster/open_files.c 2016-05-15 12:43:14 UTC (rev 68434)
@@ -12,16 +12,6 @@
int n, missing;
I_init_group_ref(&ref);
-
- G_strip(group);
- if (!I_find_group(group))
- G_fatal_error(_("Group <%s> not found in current mapset"), group);
-
- G_strip(subgroup);
- if (!I_find_subgroup(group, subgroup))
- G_fatal_error(_("Subgroup <%s> in group <%s> not found"),
- subgroup, group);
-
I_free_group_ref(&ref);
I_get_subgroup_ref(group, subgroup, &ref);
Modified: grass/trunk/imagery/i.gensig/parse.c
===================================================================
--- grass/trunk/imagery/i.gensig/parse.c 2016-05-15 12:37:40 UTC (rev 68433)
+++ grass/trunk/imagery/i.gensig/parse.c 2016-05-15 12:43:14 UTC (rev 68434)
@@ -22,7 +22,7 @@
sigfile->type = TYPE_STRING;
sigfile->key_desc = "name";
sigfile->required = YES;
- sigfile->gisprompt = "old,sig,sigfile";
+ sigfile->gisprompt = "new,sig,sigfile";
sigfile->description = _("Name for output file containing result signatures");
if (G_parser(argc, argv))
@@ -42,6 +42,14 @@
if (!I_find_subgroup(parms->group, parms->subgroup))
G_fatal_error(_("Subgroup <%s> in group <%s> not found"), parms->subgroup, parms->group);
-
+
+ /* GRASS parser fails to detect existing signature files as
+ * detection needs answers from other parameters as group and subgroup.
+ * Thus check is performed only now. */
+ if (!G_get_overwrite() && I_find_signature_file(parms->group, parms->subgroup, "sig", parms->sigfile)) {
+ G_fatal_error(_("option <%s>: <%s> exists. To overwrite, use the --overwrite flag"),
+ sigfile->key, sigfile->answer);
+ }
+
return 0;
}
Modified: grass/trunk/imagery/i.gensigset/parse.c
===================================================================
--- grass/trunk/imagery/i.gensigset/parse.c 2016-05-15 12:37:40 UTC (rev 68433)
+++ grass/trunk/imagery/i.gensigset/parse.c 2016-05-15 12:43:14 UTC (rev 68434)
@@ -21,7 +21,7 @@
sigfile->type = TYPE_STRING;
sigfile->key_desc = "name";
sigfile->required = YES;
- sigfile->gisprompt = "old,sig,sigfile";
+ sigfile->gisprompt = "new,sig,sigfile";
sigfile->description = _("Name for output file containing result signatures");
maxsig = G_define_option();
@@ -49,6 +49,15 @@
if (!I_find_subgroup(parms->group, parms->subgroup)) {
G_fatal_error(_("Subgroup <%s> in group <%s> not found"), parms->subgroup, parms->group);
}
+
+ /* GRASS parser fails to detect existing signature files as
+ * detection needs answers from other parameters as group and subgroup.
+ * Thus check is performed only now. */
+ if (!G_get_overwrite() && I_find_signature_file(parms->group, parms->subgroup, "sigset", parms->sigfile)) {
+ G_fatal_error(_("option <%s>: <%s> exists. To overwrite, use the --overwrite flag"),
+ sigfile->key, sigfile->answer);
+ }
+
if (sscanf(maxsig->answer, "%d", &parms->maxsubclasses) != 1 ||
parms->maxsubclasses <= 0) {
G_fatal_error(_("Illegal number of sub-signatures (%s)"),
More information about the grass-commit
mailing list