[GRASS-SVN] r40969 - grass/branches/releasebranch_6_4/raster/r.external

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Feb 13 04:37:06 EST 2010


Author: neteler
Date: 2010-02-13 04:37:06 -0500 (Sat, 13 Feb 2010)
New Revision: 40969

Modified:
   grass/branches/releasebranch_6_4/raster/r.external/description.html
   grass/branches/releasebranch_6_4/raster/r.external/main.c
Log:
Link all bands by default (trac #914, backport of r40961)

Modified: grass/branches/releasebranch_6_4/raster/r.external/description.html
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.external/description.html	2010-02-13 09:36:21 UTC (rev 40968)
+++ grass/branches/releasebranch_6_4/raster/r.external/description.html	2010-02-13 09:37:06 UTC (rev 40969)
@@ -9,9 +9,8 @@
 <h3>RGB Orthophoto from GeoTIFF</h3>
 
 <div class="code"><pre>
-r.external  /home/user/data/maps/059100.tif out=ortho.1 band=1
-r.external  /home/user/data/maps/059100.tif out=ortho.2 band=2
-r.external  /home/user/data/maps/059100.tif out=ortho.3 band=3
+# import of all channels:
+r.external  /home/user/data/maps/059100.tif out=ortho
 g.region rast=ortho.3 -p
 d.rgb r=ortho.1 g=ortho.2 b=ortho.3
 r.composite r=ortho.1 g=ortho.2 b=ortho.3 output=ortho.rgb

Modified: grass/branches/releasebranch_6_4/raster/r.external/main.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.external/main.c	2010-02-13 09:36:21 UTC (rev 40968)
+++ grass/branches/releasebranch_6_4/raster/r.external/main.c	2010-02-13 09:37:06 UTC (rev 40969)
@@ -498,7 +498,7 @@
 	struct Option *input, *source, *output, *band, *title;
     } parm;
     struct Flag *flag_o, *flag_f, *flag_e, *flag_r;
-    int band;
+    int min_band, max_band, band;
     struct band_info info;
 
     G_gisinit(argv[0]);
@@ -527,8 +527,7 @@
     parm.band->key = "band";
     parm.band->type = TYPE_INTEGER;
     parm.band->required = NO;
-    parm.band->description = _("Band to select");
-    parm.band->answer = "1";
+    parm.band->description = _("Band to select (default: all)");
 
     parm.title = G_define_option();
     parm.title->key = "title";
@@ -577,11 +576,6 @@
     else
 	title = NULL;
 
-    if (parm.band->answer)
-	band = atoi(parm.band->answer);
-    else
-	band = 1;
-
     if (!input && !source)
 	G_fatal_error(_("Name for input source not specified"));
 
@@ -610,19 +604,43 @@
 
     check_projection(&cellhd, hDS, flag_o->answer);
 
+    if (G_set_window(&cellhd) < 0)
+        G_fatal_error(_("Unable to set window"));
+
+    if (parm.band->answer)
+	min_band = max_band = atoi(parm.band->answer);
+    else
+	min_band = 1, max_band = GDALGetRasterCount(hDS);
+
     G_verbose_message(_("Proceeding with import..."));
-    G_message("Importing band %d of %d...", band, GDALGetRasterCount( hDS ));
 
-    hBand = GDALGetRasterBand(hDS, band);
-    if (!hBand)
-	G_fatal_error(_("Selected band (%d) does not exist"), band);
+    for (band = min_band; band <= max_band; band++) {
+	char *output2, *title2 = NULL;
 
-    if (G_set_window(&cellhd) < 0)
-	G_fatal_error(_("Unable to set window"));
+	G_message("Importing band %d of %d...", band, GDALGetRasterCount( hDS ));
 
-    query_band(hBand, output, flag_r->answer, &cellhd, &info);
-    create_map(input, band, output, &cellhd, &info, title);
+	hBand = GDALGetRasterBand(hDS, band);
+	if (!hBand)
+	    G_fatal_error(_("Selected band (%d) does not exist"), band);
 
+	if (max_band > min_band) {
+	    G_asprintf(&output2, "%s.%d", output, band);
+	    if (title)
+		G_asprintf(&title2, "%s (band %d)", title, band);
+	}
+	else {
+	    output2 = G_store(output);
+	    if (title)
+		title2 = G_store(title);
+	}
+
+	query_band(hBand, output2, flag_r->answer, &cellhd, &info);
+	create_map(input, band, output2, &cellhd, &info, title);
+
+	G_free(output2);
+	G_free(title2);
+    }
+
     if (flag_e->answer)
 	update_default_window(&cellhd);
 



More information about the grass-commit mailing list