[GRASS-SVN] r71667 - grass/trunk/raster/r.out.gdal

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 11 04:02:18 PST 2017


Author: mmetz
Date: 2017-11-11 04:02:18 -0800 (Sat, 11 Nov 2017)
New Revision: 71667

Modified:
   grass/trunk/raster/r.out.gdal/main.c
Log:
r.out.gdal: +option to add overviews

Modified: grass/trunk/raster/r.out.gdal/main.c
===================================================================
--- grass/trunk/raster/r.out.gdal/main.c	2017-11-11 11:48:17 UTC (rev 71666)
+++ grass/trunk/raster/r.out.gdal/main.c	2017-11-11 12:02:18 UTC (rev 71667)
@@ -118,7 +118,7 @@
     struct GModule *module;
     struct Flag *flag_l, *flag_c, *flag_m, *flag_f, *flag_t;
     struct Option *input, *format, *type, *output, *createopt, *metaopt,
-	*nodataopt;
+	          *nodataopt, *overviewopt;
 
     struct Cell_head cellhead;
     struct Ref ref;
@@ -129,6 +129,7 @@
     double dfCellMax, export_max;
     struct FPRange sRange;
     int retval = 0;
+    int n_overviews = 0;
 
     G_gisinit(argv[0]);
 
@@ -238,6 +239,17 @@
     nodataopt->required = NO;
     nodataopt->guisection = _("Creation");
     
+    overviewopt = G_define_option();
+    overviewopt->key = "overviews";
+    overviewopt->type = TYPE_INTEGER;
+    overviewopt->options = "0-5";
+    overviewopt->answer = "0";
+    overviewopt->label =
+	_("Number of overviews to create for the output dataset");
+    overviewopt->multiple = NO;
+    overviewopt->required = NO;
+    overviewopt->guisection = _("Creation");
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -642,6 +654,31 @@
 	}
     }
 
+    /* overviews */
+    if (overviewopt->answer) {
+	n_overviews = atoi(overviewopt->answer);
+	if (n_overviews < 0 || n_overviews > 5) {
+	    G_warning(_("Number of overviews must be between 0 and 5"));
+	    n_overviews = 0;
+	}
+    }
+    if (n_overviews) {
+	int i, oi, *ol;
+
+	G_message(_("Building overviews ..."));
+	
+	ol = G_malloc(n_overviews * sizeof(int));
+	oi = 2;
+	for (i = 0; i < n_overviews; i++) {
+	    ol[i] = oi;
+	    oi *= 2;
+	}
+	if (GDALBuildOverviews(hDstDS, "NEAREST", n_overviews, ol,
+	                       0, NULL, NULL, NULL) != CE_None) {
+	    G_warning(_("Unable to build overviews"));
+	}
+    }
+
     /* Finaly create user requested raster format from memory raster 
      * if in-memory driver was used */
     if (hMEMDS) {



More information about the grass-commit mailing list