Browse Source

g.proj: generate PROJ_EPSG file when location is given https://trac.osgeo.org/grass/ticket/2490
(merge https://trac.osgeo.org/grass/changeset/64258 from trunk)


git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@64273 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 10 years ago
parent
commit
5af9cc5ba7
3 changed files with 35 additions and 18 deletions
  1. 31 1
      general/g.proj/create.c
  2. 2 1
      general/g.proj/local_proto.h
  3. 2 16
      general/g.proj/main.c

+ 31 - 1
general/g.proj/create.c

@@ -6,7 +6,7 @@
 
 #include "local_proto.h"
 
-void create_location(char *location)
+void create_location(const char *location, const char *epsg)
 {
     int ret;
 
@@ -23,6 +23,10 @@ void create_location(char *location)
 	/* Shouldn't happen */
       G_fatal_error(_("Unable to create location <%s>"), location);
 
+    /* create also PROJ_EPSG */
+    if (epsg)
+        create_epsg(location, epsg);
+        
     G_message(_("You can switch to the new location by\n`%s=%s`"),
 	      "g.mapset mapset=PERMANENT location", location);
 }
@@ -65,3 +69,29 @@ void modify_projinfo()
     }
     G_important_message(_("Projection information updated"));
 }
+
+void create_epsg(const char *location, const char *epsg)
+{
+    FILE *fp;
+    char path[GPATH_MAX];
+    
+    /* if inputs were not clean it should of failed by now */
+    if (location) {
+        snprintf(path, sizeof(path), "%s%c%s%c%s%c%s", G_gisdbase(), HOST_DIRSEP, 
+                 location, HOST_DIRSEP,
+                 "PERMANENT", HOST_DIRSEP, "PROJ_EPSG");
+        path[sizeof(path)-1] = '\0';
+    }
+    else {
+        G_file_name(path, "", "PROJ_EPSG", "PERMANENT");
+    }
+    
+    fp = fopen(path, "w");
+    if (!fp)
+        G_fatal_error(_("Unable to create PROJ_EPSG file: %s"), strerror (errno));
+    
+#ifdef HAVE_OGR
+    fprintf(fp, "epsg: %s\n", epsg);
+#endif
+    fclose(fp);
+}

+ 2 - 1
general/g.proj/local_proto.h

@@ -25,5 +25,6 @@ int set_datum(char *);
 int set_datumtrans(int, int);
 
 /* create.c */
-void create_location(char *);
+void create_location(const char *, const char *);
 void modify_projinfo();
+void create_epsg(const char *, const char *);

+ 2 - 16
general/g.proj/main.c

@@ -299,7 +299,7 @@ int main(int argc, char *argv[])
 	print_wkt(esristyle->answer, dontprettify->answer);
 #endif
     else if (location->answer)
-	create_location(location->answer);
+	create_location(location->answer, inepsg->answer);
     else if (create->answer)
 	modify_projinfo();
     else
@@ -319,21 +319,7 @@ int main(int argc, char *argv[])
     if (create->answer){ 
 #endif
 	/* 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");
-#ifdef HAVE_OGR
-	fprintf(fp, "epsg: %s\n", inepsg->answer);
-#endif
-	fclose(fp);
+        create_epsg(location->answer, inepsg->answer);
     }