[GRASS-SVN] r71716 - grass/trunk/imagery/i.segment

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Nov 12 12:07:19 PST 2017


Author: mmetz
Date: 2017-11-12 12:07:19 -0800 (Sun, 12 Nov 2017)
New Revision: 71716

Modified:
   grass/trunk/imagery/i.segment/open_files.c
   grass/trunk/imagery/i.segment/parse_args.c
Log:
i.segment: input can be a group or a list of raster maps

Modified: grass/trunk/imagery/i.segment/open_files.c
===================================================================
--- grass/trunk/imagery/i.segment/open_files.c	2017-11-12 20:03:04 UTC (rev 71715)
+++ grass/trunk/imagery/i.segment/open_files.c	2017-11-12 20:07:19 UTC (rev 71716)
@@ -31,20 +31,6 @@
     flag_clear_all(globals->null_flag);
     flag_clear_all(globals->candidate_flag);
 
-    G_debug(1, "Checking image group...");
-
-    /* ****** open the input rasters ******* */
-
-    if (!I_get_group_ref(globals->image_group, &globals->Ref))
-	G_fatal_error(_("Group <%s> not found in the current mapset"),
-		      globals->image_group);
-
-    if (globals->Ref.nfiles <= 0)
-	G_fatal_error(_("Group <%s> contains no raster maps"),
-		      globals->image_group);
-
-    /* Read Imagery Group */
-
     in_fd = G_malloc(globals->Ref.nfiles * sizeof(int));
     inbuf = (DCELL **) G_malloc(globals->Ref.nfiles * sizeof(DCELL *));
     fp_range = G_malloc(globals->Ref.nfiles * sizeof(struct FPRange));

Modified: grass/trunk/imagery/i.segment/parse_args.c
===================================================================
--- grass/trunk/imagery/i.segment/parse_args.c	2017-11-12 20:03:04 UTC (rev 71715)
+++ grass/trunk/imagery/i.segment/parse_args.c	2017-11-12 20:07:19 UTC (rev 71716)
@@ -18,9 +18,12 @@
 		   *mem;
     struct Flag *diagonal, *weighted, *ms_a, *ms_p;
     struct Option *gof, *endt;
+    int bands;
 
     /* required parameters */
-    group = G_define_standard_option(G_OPT_I_GROUP);
+    group = G_define_standard_option(G_OPT_R_INPUTS);
+    group->key = "group";
+    group->description = _("Name of input imagery group or raster maps");
 
     output = G_define_standard_option(G_OPT_R_OUTPUT);
 
@@ -180,8 +183,40 @@
 
     /* Check and save parameters */
 
-    globals->image_group = group->answer;
+    for (bands = 0; group->answers[bands] != NULL; bands++) ;
 
+    I_init_group_ref(&globals->Ref);
+    if (bands > 1 || !I_find_group(group->answers[0])) {
+	/* create group from input is raster map(s) */
+	char name[GNAME_MAX];
+	const char *mapset;
+
+	for (bands = 0; group->answers[bands] != NULL; bands++) {
+	    /* strip @mapset, do not modify opt_in->answers */
+	    strcpy(name, group->answers[bands]);
+	    mapset = G_find_raster(name, "");
+	    if (!mapset)
+		G_fatal_error(_("Raster map <%s> not found"),
+			      group->answers[bands]);
+	    /* Add input to group. */
+	    I_add_file_to_group_ref(name, mapset, &globals->Ref);
+	}
+
+	globals->image_group = NULL;
+    }
+    else {
+	/* input is group. Try to read group file */
+	if (!I_get_group_ref(group->answers[0], &globals->Ref))
+	    G_fatal_error(_("Group <%s> not found in the current mapset"),
+			  group->answers[0]);
+
+	if (globals->Ref.nfiles <= 0)
+	    G_fatal_error(_("Group <%s> contains no raster maps"),
+			  globals->image_group);
+
+	globals->image_group = group->answers[0];
+    }
+
     if (G_legal_filename(output->answer) == TRUE)
 	globals->out_name = output->answer;
     else



More information about the grass-commit mailing list