Browse Source

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 https://trac.osgeo.org/grass/ticket/667)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@49298 15284696-431f-4ddb-bdfa-cd5b030d7da7

Hamish Bowman 13 years ago
parent
commit
0890cd1a18
2 changed files with 41 additions and 3 deletions
  1. 18 1
      general/g.proj/main.c
  2. 23 2
      general/g.proj/output.c

+ 18 - 1
general/g.proj/main.c

@@ -277,8 +277,25 @@ int main(int argc, char *argv[])
 		      printinfo->key, shellinfo->key, printproj4->key, printwkt->key);
     
 
-    /* Tidy Up */
+    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)

+ 23 - 2
general/g.proj/output.c

@@ -15,7 +15,7 @@
  *****************************************************************************/
 
 #include <stdio.h>
-
+#include <unistd.h>
 #include <proj_api.h>
 
 #include <grass/gis.h>
@@ -30,6 +30,7 @@ static int check_xy(int shell);
 void print_projinfo(int shell)
 {
     int i;
+    char path[GPATH_MAX];
 
     if (check_xy(shell))
 	return;
@@ -43,7 +44,27 @@ void print_projinfo(int shell)
 	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");