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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 19 07:38:34 EST 2011


Author: hamish
Date: 2011-11-19 04:38:34 -0800 (Sat, 19 Nov 2011)
New Revision: 49298

Modified:
   grass/trunk/general/g.proj/main.c
   grass/trunk/general/g.proj/output.c
Log:
Retain EPSG code, if available, into a metadata file. NOTE: The EPSG
code is preserved for historical metadata interest only; the contents
of this file are not used by pj_*() routines at all. (wish #667)


Modified: grass/trunk/general/g.proj/main.c
===================================================================
--- grass/trunk/general/g.proj/main.c	2011-11-19 12:34:51 UTC (rev 49297)
+++ grass/trunk/general/g.proj/main.c	2011-11-19 12:38:34 UTC (rev 49298)
@@ -277,8 +277,25 @@
 		      printinfo->key, shellinfo->key, printproj4->key, printwkt->key);
     
 
+    if (create->answer && inepsg->answer) {
+	/* preserve epsg code for user records only (not used by grass's pj routines) */
+	FILE *fp;
+	char path[GPATH_MAX];
+	/* if inputs were not clean it should of failed by now */
+	if (location->answer) {
+            snprintf(path, sizeof(path), "%s/%s/%s/%s", G_gisdbase(),
+		     location->answer, "PERMANENT", "PROJ_EPSG");
+	    path[sizeof(path)-1] = '\0';
+	}
+	else
+	    G_file_name(path, "", "PROJ_EPSG", "PERMANENT");
+	fp = fopen(path, "w");
+	fprintf(fp, "epsg: %s\n", inepsg->answer);
+	fclose(fp);
+    }
+
+
     /* Tidy Up */
-
     if (projinfo != NULL)
 	G_free_key_value(projinfo);
     if (projunits != NULL)

Modified: grass/trunk/general/g.proj/output.c
===================================================================
--- grass/trunk/general/g.proj/output.c	2011-11-19 12:34:51 UTC (rev 49297)
+++ grass/trunk/general/g.proj/output.c	2011-11-19 12:38:34 UTC (rev 49298)
@@ -15,7 +15,7 @@
  *****************************************************************************/
 
 #include <stdio.h>
-
+#include <unistd.h>
 #include <proj_api.h>
 
 #include <grass/gis.h>
@@ -30,6 +30,7 @@
 void print_projinfo(int shell)
 {
     int i;
+    char path[GPATH_MAX];
 
     if (check_xy(shell))
 	return;
@@ -43,7 +44,27 @@
 	else
 	    fprintf(stdout, "%-11s: %s\n", projinfo->key[i], projinfo->value[i]);
     }
-    
+
+    /* EPSG code is preserved for historical metadata interest only:
+	the contents of this file are not used by pj_*() routines at all */
+    G_file_name(path, "", "PROJ_EPSG", "PERMANENT");
+    if (access(path, F_OK) == 0) {
+	struct Key_Value *in_epsg_key;
+	in_epsg_key = G_read_key_value_file(path);
+	if (!shell) {
+	    fprintf(stdout,
+		"-PROJ_EPSG-------------------------------------------------\n");
+	    fprintf(stdout, "%-11s: %s\n", in_epsg_key->key[0],
+		    in_epsg_key->value[0]);
+	}
+	else
+	    fprintf(stdout, "%s=%s\n", in_epsg_key->key[0],
+		    in_epsg_key->value[0]);
+
+	if (in_epsg_key != NULL)
+	    G_free_key_value(in_epsg_key);
+    }
+ 
     if (!shell)
 	fprintf(stdout,
 		"-PROJ_UNITS------------------------------------------------\n");



More information about the grass-commit mailing list