[GRASS-SVN] r29561 - grass/branches/releasebranch_6_3/raster/r.in.gdal

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 4 14:31:32 EST 2008


Author: martinl
Date: 2008-01-04 14:31:32 -0500 (Fri, 04 Jan 2008)
New Revision: 29561

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

Modified: grass/branches/releasebranch_6_3/raster/r.in.gdal/main.c
===================================================================
--- grass/branches/releasebranch_6_3/raster/r.in.gdal/main.c	2008-01-04 19:19:27 UTC (rev 29560)
+++ grass/branches/releasebranch_6_3/raster/r.in.gdal/main.c	2008-01-04 19:31:32 UTC (rev 29561)
@@ -52,6 +52,7 @@
     int         force_imagery = FALSE;
     char	error_msg[8096];
     int 	projcomp_error=0;
+    int overwrite;
 
     struct GModule *module;
     struct
@@ -123,6 +124,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);
 
@@ -176,6 +182,18 @@
 	exit(EXIT_SUCCESS);
     }
 
+    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.                                                  */
 /* -------------------------------------------------------------------- */
@@ -250,12 +268,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
     {



More information about the grass-commit mailing list