Explorar o código

r.texture: Fatal error if one of the requested output maps exists (fix for https://trac.osgeo.org/grass/ticket/3492)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@72380 15284696-431f-4ddb-bdfa-cd5b030d7da7
Moritz Lennert %!s(int64=7) %!d(string=hai) anos
pai
achega
bb7cf16c09
Modificáronse 1 ficheiros con 13 adicións e 4 borrados
  1. 13 4
      raster/r.texture/main.c

+ 13 - 4
raster/r.texture/main.c

@@ -76,7 +76,7 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
     G_add_keyword(_("texture"));
     module->description =
 	_("Generate images with textural features from a raster map.");
-    module->overwrite = 1;
 
     /* Define the different options */
 
@@ -243,6 +242,8 @@ int main(int argc, char *argv[])
 	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));
@@ -251,13 +252,21 @@ int main(int argc, char *argv[])
 	    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();