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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 20 10:38:02 PST 2015


Author: martinl
Date: 2015-01-20 10:38:01 -0800 (Tue, 20 Jan 2015)
New Revision: 64258

Modified:
   grass/trunk/general/g.proj/create.c
   grass/trunk/general/g.proj/local_proto.h
   grass/trunk/general/g.proj/main.c
Log:
g.proj: generate PROJ_EPSG file when `location` is given #2490


Modified: grass/trunk/general/g.proj/create.c
===================================================================
--- grass/trunk/general/g.proj/create.c	2015-01-20 17:54:03 UTC (rev 64257)
+++ grass/trunk/general/g.proj/create.c	2015-01-20 18:38:01 UTC (rev 64258)
@@ -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 @@
 	/* 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 @@
     }
     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);
+}

Modified: grass/trunk/general/g.proj/local_proto.h
===================================================================
--- grass/trunk/general/g.proj/local_proto.h	2015-01-20 17:54:03 UTC (rev 64257)
+++ grass/trunk/general/g.proj/local_proto.h	2015-01-20 18:38:01 UTC (rev 64258)
@@ -25,5 +25,6 @@
 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 *);

Modified: grass/trunk/general/g.proj/main.c
===================================================================
--- grass/trunk/general/g.proj/main.c	2015-01-20 17:54:03 UTC (rev 64257)
+++ grass/trunk/general/g.proj/main.c	2015-01-20 18:38:01 UTC (rev 64258)
@@ -299,7 +299,7 @@
 	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 @@
     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);
     }
 
 



More information about the grass-commit mailing list