[GRASS-SVN] r72501 - grass/branches/releasebranch_7_2/raster/r.texture

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Mar 22 08:51:11 PDT 2018


Author: mlennert
Date: 2018-03-22 08:51:11 -0700 (Thu, 22 Mar 2018)
New Revision: 72501

Modified:
   grass/branches/releasebranch_7_2/raster/r.texture/main.c
Log:
r.texture: Fatal error if one of the requested output maps exists (fix for #3492, backport from trunk r72380)



Modified: grass/branches/releasebranch_7_2/raster/r.texture/main.c
===================================================================
--- grass/branches/releasebranch_7_2/raster/r.texture/main.c	2018-03-22 15:49:43 UTC (rev 72500)
+++ grass/branches/releasebranch_7_2/raster/r.texture/main.c	2018-03-22 15:51:11 UTC (rev 72501)
@@ -76,7 +76,7 @@
     char *name, *result;
     char **mapname;
     FCELL **fbuf;
-    int n_measures, n_outputs, *measure_idx;
+    int n_measures, n_outputs, *measure_idx, overwrite;
     int nrows, ncols;
     int row, col, first_row, last_row, first_col, last_col;
     int i, j;
@@ -105,7 +105,6 @@
     G_add_keyword(_("texture"));
     module->description =
 	_("Generate images with textural features from a raster map.");
-    module->overwrite = 1;
 
     /* Define the different options */
 
@@ -236,6 +235,8 @@
 	mapname[i] = G_malloc(GNAME_MAX * sizeof(char));
 	fbuf[i] = Rast_allocate_buf(out_data_type);
     }
+    
+    overwrite = G_check_overwrite(argc, argv);
 
     /* open output maps */
     outfd = G_malloc(n_outputs * sizeof(int));
@@ -244,13 +245,21 @@
 	    for (j = 0; j < 4; j++) {
 		sprintf(mapname[i * 4 + j], "%s%s_%d", result,
 		        menu[measure_idx[i]].suffix, j * 45);
-		outfd[i * 4 + j] = Rast_open_new(mapname[i * 4 + j], out_data_type);
+		if (!G_find_raster(mapname[i * 4 + j], G_mapset()) || overwrite) {
+			outfd[i * 4 + j] = Rast_open_new(mapname[i * 4 + j], out_data_type);
+	        } else {
+		        G_fatal_error(_("At least one of the requested output maps exists. Use --o to overwrite."));
+	        }
 	    }
 	}
 	else {
 	    sprintf(mapname[i], "%s%s", result,
 	            menu[measure_idx[i]].suffix);
-	    outfd[i] = Rast_open_new(mapname[i], out_data_type);
+	    if (!G_find_raster(mapname[i], G_mapset()) || overwrite) {
+		    outfd[i] = Rast_open_new(mapname[i], out_data_type);
+	    } else {
+		    G_fatal_error(_("At least one of the requested output maps exists. Use --o to overwrite."));
+	    }
 	}
     }
     nrows = Rast_window_rows();



More information about the grass-commit mailing list