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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 18 02:24:11 EDT 2009


Author: mmetz
Date: 2009-04-18 02:24:10 -0400 (Sat, 18 Apr 2009)
New Revision: 36769

Modified:
   grass/trunk/raster/r.out.gdal/export_band.c
   grass/trunk/raster/r.out.gdal/main.c
Log:
added -f flag to force export

Modified: grass/trunk/raster/r.out.gdal/export_band.c
===================================================================
--- grass/trunk/raster/r.out.gdal/export_band.c	2009-04-17 14:42:27 UTC (rev 36768)
+++ grass/trunk/raster/r.out.gdal/export_band.c	2009-04-18 06:24:10 UTC (rev 36769)
@@ -287,21 +287,6 @@
 	}
     }
 
-    if (nodatavalmatch && n_nulls) {
-	if (default_nodataval) {  /* default nodataval didn't work */
-	    G_fatal_error(_("Raster band <%s> contains NULL cells and "
-	    "the default nodata value would lead to data loss. Please "
-	    "specify a nodata value with the %s parameter."),
-	     name, nodatakey);
-	}
-	else {  /* user-specified nodataval didn't work */
-	    G_fatal_error(_("Raster band <%s> contains NULL cells and "
-	    "the given nodata value would lead to data loss. Please "
-	    "specify a different nodata value with the %s parameter."),
-	     name, nodatakey);
-	}
-    }
-
     if (n_nulls > 0 && default_nodataval) {
 	if (maptype == CELL_TYPE)
 	    G_important_message(_("Input raster map contains cells with NULL-value (no-data). "
@@ -315,5 +300,22 @@
 		      nodataval, nodatakey);
     }
 
+    if (nodatavalmatch && n_nulls) {
+	if (default_nodataval) {  /* default nodataval didn't work */
+	    G_warning(_("The default nodata value is present in raster"
+	    "band <%s> and would lead to data loss. Please specify a "
+	    "different nodata value with the %s parameter."),
+	     name, nodatakey);
+	}
+	else {  /* user-specified nodataval didn't work */
+	    G_warning(_("The given nodata value is present in raster"
+	    "band <%s> and would lead to data loss. Please specify a "
+	    "different nodata value with the %s parameter."),
+	     name, nodatakey);
+	}
+
+	return -2;
+    }
+
     return 0;
 }

Modified: grass/trunk/raster/r.out.gdal/main.c
===================================================================
--- grass/trunk/raster/r.out.gdal/main.c	2009-04-17 14:42:27 UTC (rev 36768)
+++ grass/trunk/raster/r.out.gdal/main.c	2009-04-18 06:24:10 UTC (rev 36769)
@@ -104,7 +104,7 @@
 {
 
     struct GModule *module;
-    struct Flag *flag_l, *flag_c;
+    struct Flag *flag_l, *flag_c, *flag_f;
     struct Option *input, *format, *type, *output, *createopt, *metaopt,
 	*nodataopt;
 
@@ -116,6 +116,7 @@
     double dfCellMin;
     double dfCellMax;
     struct FPRange sRange;
+    int retval;
 
     G_gisinit(argv[0]);
 
@@ -134,6 +135,11 @@
     flag_c->label = _("Do not write GDAL standard colortable");
     flag_c->description = _("Only applicable to Byte or UInt16 data types.");
 
+    flag_f = G_define_flag();
+    flag_f->key = 'f';
+    flag_f->label = _("Force raster export also if data loss may occur");
+    flag_f->description = _("Overrides saftey checks.");
+
     input = G_define_standard_option(G_OPT_R_INPUT);
     input->required = NO;
     input->description = _("Name of raster map (or group) to export");
@@ -396,8 +402,12 @@
 	nodataval = atof(nodataopt->answer);
 	default_nodataval = 0;
 	/* check nodataval here, not in export_band(), because it is specified only once */
-	if (nullvalue_check(nodataval, datatype))
-	    G_fatal_error("Raster export aborted.");
+	if (nullvalue_check(nodataval, datatype)) {
+	    if (flag_f->answer)
+		G_warning(_("Forcing raster export."));
+	    else
+		G_fatal_error(_("Raster export aborted."));
+	}
     }
 
     G_debug(3, "Input map datatype=%s\n",
@@ -489,17 +499,29 @@
 	G_debug(3, "Range: min: %f, max: %f", dfCellMin, dfCellMax);
 	if (bHaveMinMax == TRUE) {
 	    if (range_check
-		(dfCellMin, dfCellMax, datatype, ref.file[band].name))
-		G_fatal_error("Raster export aborted");
+		(dfCellMin, dfCellMax, datatype, ref.file[band].name)) {
+		if (flag_f->answer)
+		    G_warning(_("Forcing raster export."));
+		else
+		    G_fatal_error(_("Raster export aborted."));
+		}
 	}
 
 	/* ready to export */
-	if (export_band
+	retval = export_band
 	    (hCurrDS, band + 1, ref.file[band].name, ref.file[band].mapset,
 	     &cellhead, maptype, nodataval, nodataopt->key, flag_c->answer,
-	     default_nodataval) < 0)
+	     default_nodataval);
+	if (retval == -1) {
 	    G_warning(_("Unable to export raster map <%s>"),
 		      ref.file[band].name);
+	}
+	else if (retval == -2) {
+	    if (flag_f->answer)
+		G_warning(_("Forcing raster export."));
+	    else
+		G_fatal_error(_("Raster export aborted."));
+	}
     }
 
     /* Finaly create user required raster format from memory raster if in-memory driver was used */



More information about the grass-commit mailing list