[GRASS-SVN] r46850 - grass/trunk/general/g.proj

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jun 29 09:54:35 EDT 2011


Author: martinl
Date: 2011-06-29 06:54:35 -0700 (Wed, 29 Jun 2011)
New Revision: 46850

Modified:
   grass/trunk/general/g.proj/local_proto.h
   grass/trunk/general/g.proj/main.c
   grass/trunk/general/g.proj/output.c
Log:
g.proj: `-g` flag implemented


Modified: grass/trunk/general/g.proj/local_proto.h
===================================================================
--- grass/trunk/general/g.proj/local_proto.h	2011-06-29 13:22:44 UTC (rev 46849)
+++ grass/trunk/general/g.proj/local_proto.h	2011-06-29 13:54:35 UTC (rev 46850)
@@ -13,7 +13,7 @@
 #endif
 
 /* output.c */
-void print_projinfo(void);
+void print_projinfo(int);
 void print_datuminfo(void);
 void print_proj4(int);
 #ifdef HAVE_OGR

Modified: grass/trunk/general/g.proj/main.c
===================================================================
--- grass/trunk/general/g.proj/main.c	2011-06-29 13:22:44 UTC (rev 46849)
+++ grass/trunk/general/g.proj/main.c	2011-06-29 13:54:35 UTC (rev 46850)
@@ -3,14 +3,15 @@
  *
  * MODULE:       g.proj 
  * AUTHOR(S):    Paul Kelly - paul-grass at stjohnspoint.co.uk
+ *               Shell script style by Martin Landa <landa.martin gmail.com>
  * PURPOSE:      Provides a means of reporting the contents of GRASS
  *               projection information files and creating
  *               new projection information files.
- * COPYRIGHT:    (C) 2003-2007 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2003-2007, 2011 by the GRASS Development Team
  *
- *               This program is free software under the GNU General Public
- *               License (>=v2). Read the file COPYING that comes with GRASS
- *               for details.
+ *               This program is free software under the GNU General
+ *               Public License (>=v2). Read the file COPYING that
+ *               comes with GRASS for details.
  *
  *****************************************************************************/
 
@@ -28,27 +29,28 @@
 int main(int argc, char *argv[])
 {
     struct Flag *printinfo,	/* Print contents of PROJ_INFO & PROJ_UNITS */
-     *printproj4,		/* Print projection in PROJ.4 format        */
-     *datuminfo,		/* Check if datum information is present    */
-     *create,			/* Create new projection files              */
+	*shellinfo,             /* Print in shell script style              */
+	*printproj4,		/* Print projection in PROJ.4 format        */
+	*datuminfo,		/* Check if datum information is present    */
+	*create,		/* Create new projection files              */
 #ifdef HAVE_OGR
-     *printwkt,			/* Print projection in WKT format           */
-     *esristyle,		/* Use ESRI-style WKT format                */
+	*printwkt,		/* Print projection in WKT format           */
+	*esristyle,		/* Use ESRI-style WKT format                */
 #endif
-     *dontprettify,		/* Print 'flat' output (no linebreaks)      */
-     *forcedatumtrans;		/* Force override of datumtrans parameters  */
-
+	*dontprettify,		/* Print 'flat' output (no linebreaks)      */
+	*forcedatumtrans;	/* Force override of datumtrans parameters  */
+    
     struct Option *location,	/* Name of new location to create           */
 #ifdef HAVE_OGR
-     *inepsg,			/* EPSG projection code                     */
-     *inwkt,			/* Input file with projection in WKT format */
-     *inproj4,			/* Projection in PROJ.4 format              */
-     *ingeo,			/* Input geo-referenced file readable by 
+	*inepsg,		/* EPSG projection code                     */
+	*inwkt,			/* Input file with projection in WKT format */
+	*inproj4,		/* Projection in PROJ.4 format              */
+	*ingeo,			/* Input geo-referenced file readable by 
 				 * GDAL or OGR                              */
 #endif
-     *dtrans;			/* index to datum transform option          */
+	*dtrans;		/* index to datum transform option          */
     struct GModule *module;
-
+    
     int formats;
 
     G_set_program_name(argv[0]);
@@ -74,8 +76,14 @@
     printinfo->key = 'p';
     printinfo->guisection = _("Print");
     printinfo->description =
-	_("Print projection information (in conventional GRASS format)");
+	_("Print projection information in conventional GRASS format");
 
+    shellinfo = G_define_flag();
+    shellinfo->key = 'g';
+    shellinfo->guisection = _("Print");
+    shellinfo->description =
+	_("Print projection information in shell script style");
+
     datuminfo = G_define_flag();
     datuminfo->key = 'd';
     datuminfo->guisection = _("Print");
@@ -227,26 +235,27 @@
 
     /* Output */
     /* Only allow one output format at a time, to reduce confusion */
-    formats = ((printinfo->answer ? 1 : 0) + (datuminfo->answer ? 1 : 0) +
+    formats = ((printinfo->answer ? 1 : 0) + (shellinfo->answer ? 1 : 0) +
+	       (datuminfo->answer ? 1 : 0) +
 	       (printproj4->answer ? 1 : 0) +
 #ifdef HAVE_OGR
 	       (printwkt->answer ? 1 : 0) +
 #endif
 	       (create->answer ? 1 : 0));
     if (formats > 1)
-	G_fatal_error(_("Only one of -%c, -%c, -%c"
+	G_fatal_error(_("Only one of -%c, -%c, -%c, -%c"
 #ifdef HAVE_OGR
 			", -%c"
 #endif
 			" or -%c flags may be specified"),
-		      printinfo->key, datuminfo->key, printproj4->key,
+		      printinfo->key, shellinfo->key, datuminfo->key, printproj4->key,
 #ifdef HAVE_OGR
 		      printwkt->key,
 #endif
 		      create->key);
 
-    if (printinfo->answer)
-	print_projinfo();
+    if (printinfo->answer || shellinfo->answer)
+	print_projinfo(shellinfo->answer);
     else if (datuminfo->answer)
 	print_datuminfo();
     else if (printproj4->answer)

Modified: grass/trunk/general/g.proj/output.c
===================================================================
--- grass/trunk/general/g.proj/output.c	2011-06-29 13:22:44 UTC (rev 46849)
+++ grass/trunk/general/g.proj/output.c	2011-06-29 13:54:35 UTC (rev 46850)
@@ -27,26 +27,37 @@
 
 #include "local_proto.h"
 
-static int check_xy(void);
+static int check_xy(int shell);
 
-void print_projinfo(void)
+void print_projinfo(int shell)
 {
     int i;
 
-    if (check_xy())
+    if (check_xy(shell))
 	return;
 
-    fprintf(stdout,
-	    "-PROJ_INFO-------------------------------------------------\n");
-    for (i = 0; i < projinfo->nitems; i++)
-	fprintf(stdout, "%-11s: %s\n", projinfo->key[i], projinfo->value[i]);
-
-    fprintf(stdout,
-	    "-PROJ_UNITS------------------------------------------------\n");
-    for (i = 0; i < projunits->nitems; i++)
-	fprintf(stdout, "%-11s: %s\n",
-		projunits->key[i], projunits->value[i]);
-
+    if (!shell)
+	fprintf(stdout,
+		"-PROJ_INFO-------------------------------------------------\n");
+    for (i = 0; i < projinfo->nitems; i++) {
+	if (shell)
+	    fprintf(stdout, "%s=%s\n", projinfo->key[i], projinfo->value[i]);
+	else
+	    fprintf(stdout, "%-11s: %s\n", projinfo->key[i], projinfo->value[i]);
+    }
+    
+    if (!shell)
+	fprintf(stdout,
+		"-PROJ_UNITS------------------------------------------------\n");
+    for (i = 0; i < projunits->nitems; i++) {
+	if (shell)
+	    fprintf(stdout, "%s=%s\n",
+		    projunits->key[i], projunits->value[i]);
+	else
+	    fprintf(stdout, "%-11s: %s\n",
+		    projunits->key[i], projunits->value[i]);
+    }
+    
     return;
 }
 
@@ -56,7 +67,7 @@
     struct gpj_datum dstruct;
     int validdatum = 0;
 
-    if (check_xy())
+    if (check_xy(FALSE))
 	return;
 
     GPJ__get_datum_params(projinfo, &datum, &params);
@@ -100,7 +111,7 @@
     char *proj4, *proj4mod, *i;
     const char *unfact;
 
-    if (check_xy())
+    if (check_xy(FALSE))
 	return;
 
     pj_get_kv(&pjinfo, projinfo, projunits);
@@ -137,7 +148,7 @@
 {
     char *outwkt;
 
-    if (check_xy())
+    if (check_xy(FALSE))
 	return;
 
     outwkt = GPJ_grass_to_wkt(projinfo, projunits, esristyle,
@@ -160,12 +171,12 @@
     if (location) {
 	ret = G__make_location(location, &cellhd, projinfo, projunits, NULL);
 	if (ret == 0)
-	    G_message(_("Location %s created!"), location);
+	    G_message(_("Location <%s> created"), location);
 	else if (ret == -1)
-	    G_fatal_error(_("Unable to create location: %s"),
-			  strerror(errno));
+	    G_fatal_error(_("Unable to create location <%s>: %s"),
+			  location, strerror(errno));
 	else if (ret == -2)
-	    G_fatal_error(_("Unable to create projection files: %s"),
+			 G_fatal_error(_("Unable to create projection files: %s"),
 			  strerror(errno));
 	else
 	    /* Shouldn't happen */
@@ -176,7 +187,6 @@
 	 * projection files for current location */
 
 	const char *mapset = G_mapset();
-	struct Key_Value *old_projinfo = NULL, *old_projunits = NULL;
 	struct Cell_head old_cellhd;
 
 	if (strcmp(mapset, "PERMANENT") != 0)
@@ -186,46 +196,41 @@
 
 	/* Read projection information from current location first */
 	G_get_default_window(&old_cellhd);
-
-	if (old_cellhd.proj != PROJECTION_XY) {
-	    old_projinfo = G_get_projinfo();
-	    old_projunits = G_get_projunits();
+	
+	char path[GPATH_MAX];
+	
+	/* Write out the PROJ_INFO, and PROJ_UNITS if available. */
+	if (projinfo != NULL) {
+	    G_file_name(path, "", "PROJ_INFO", "PERMANENT");
+	    G_write_key_value_file(path, projinfo);
 	}
-
-	{
-	    char path[GPATH_MAX];
-
-	    /* Write out the PROJ_INFO, and PROJ_UNITS if available. */
-	    if (projinfo != NULL) {
-		G_file_name(path, "", "PROJ_INFO", "PERMANENT");
-		G_write_key_value_file(path, projinfo);
-	    }
-
-	    if (projunits != NULL) {
-		G_file_name(path, "", "PROJ_UNITS", "PERMANENT");
-		G_write_key_value_file(path, projunits);
-	    }
-
-	    if ((old_cellhd.zone != cellhd.zone) ||
-		(old_cellhd.proj != cellhd.proj)) {
-		/* Recreate the default, and current window files if projection
-		 * number or zone have changed */
-		G__put_window(&cellhd, "", "DEFAULT_WIND");
+	
+	if (projunits != NULL) {
+	    G_file_name(path, "", "PROJ_UNITS", "PERMANENT");
+	    G_write_key_value_file(path, projunits);
+	}
+	
+	if ((old_cellhd.zone != cellhd.zone) ||
+	    (old_cellhd.proj != cellhd.proj)) {
+	    /* Recreate the default, and current window files if projection
+	     * number or zone have changed */
+	    G__put_window(&cellhd, "", "DEFAULT_WIND");
 		G__put_window(&cellhd, "", "WIND");
 		G_message(_("N.B. The default region was updated to the new projection, but if you have "
-			   "multiple mapsets g.region -d should be run in each to update the region from "
-			   "the default."));
-	    }
-	    G_message(_("Projection information updated!"));
+			    "multiple mapsets g.region -d should be run in each to update the region from "
+			    "the default."));
 	}
+	G_message(_("Projection information updated!"));
     }
 
     return;
 }
 
-static int check_xy(void)
+static int check_xy(int shell)
 {
     if (cellhd.proj == PROJECTION_XY) {
+	if (shell)
+	    fprintf(stdout, "name=");
 	fprintf(stdout, "XY location (unprojected)\n");
 	return 1;
     }



More information about the grass-commit mailing list