[GRASS-SVN] r29560 - grass/trunk/raster/r.in.gdal

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 4 14:19:27 EST 2008


Author: martinl
Date: 2008-01-04 14:19:27 -0500 (Fri, 04 Jan 2008)
New Revision: 29560

Modified:
   grass/trunk/raster/r.in.gdal/main.c
Log:
Fixing bug GForge/449: r.in.gdal - output test for parameter location= fails

Modified: grass/trunk/raster/r.in.gdal/main.c
===================================================================
--- grass/trunk/raster/r.in.gdal/main.c	2008-01-04 18:24:18 UTC (rev 29559)
+++ grass/trunk/raster/r.in.gdal/main.c	2008-01-04 19:19:27 UTC (rev 29560)
@@ -60,6 +60,7 @@
     int         force_imagery = FALSE;
     char	error_msg[8096];
     int 	projcomp_error=0;
+    int overwrite;
 
     struct GModule *module;
     struct
@@ -134,6 +135,11 @@
     flag_k->key = 'k';
     flag_k->description = _("Keep band numbers instead of using band color names");
 
+    /* The parser checks if the map already exists in current mapset, this is
+     * wrong if location options is used, so we switch out the check and do it
+     * in the module after the parser */
+    overwrite = G_check_overwrite(argc, argv);
+
     if (G_parser(argc,argv))
         exit(EXIT_FAILURE);
 
@@ -196,6 +202,18 @@
 	G_fatal_error(_("Name for output raster map not specified"));
     }
 
+    if (G_legal_filename(output) < 0)
+        G_fatal_error(_("<%s> is an illegal file name"), output);
+
+    if ( !parm.outloc->answer ) { /* Check if the map exists */
+	if ( G_find_cell2 (output, G_mapset()) ) {
+	    if (overwrite)
+	        G_warning ( _("Raster map <%s> already exists and will be overwritten"), output );
+	    else
+	        G_fatal_error ( _("Raster map <%s> already exists"), output );
+	}
+    }
+
 /* -------------------------------------------------------------------- */
 /*      Open the file.                                                  */
 /* -------------------------------------------------------------------- */
@@ -271,12 +289,15 @@
         /* Convert projection information non-interactively as we can't
 	 * assume the user has a terminal open */
         if ( GPJ_wkt_to_grass( &cellhd, &proj_info, 
-			       &proj_units, GDALGetProjectionRef(hDS), 0) < 0 )
+			       &proj_units, GDALGetProjectionRef(hDS), 0) < 0 ) {
 	    G_fatal_error(_("Unable to convert input map projection to GRASS "
 			    "format; cannot create new location."));
-	else		  
+	}
+	else {		  
             G_make_location( parm.outloc->answer, &cellhd,
 			     proj_info, proj_units, NULL );
+	    G_message(_("Location <%s> created"), parm.outloc->answer);
+	}
     }
     else
     {
@@ -380,10 +401,11 @@
             else {
     	        G_message(_("Projection of input dataset and current location "
 			    "appear to match"));
-		G_verbose_message(_("Proceeding with import..."));
 	    }
 	}
     }
+
+    G_verbose_message(_("Proceeding with import..."));
     
 /* -------------------------------------------------------------------- */
 /*      Set the active window to match the available data.              */



More information about the grass-commit mailing list