[GRASS-SVN] r64273 - in grass/branches/releasebranch_7_0: . general/g.proj
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jan 21 05:47:31 PST 2015
Author: martinl
Date: 2015-01-21 05:47:31 -0800 (Wed, 21 Jan 2015)
New Revision: 64273
Modified:
grass/branches/releasebranch_7_0/
grass/branches/releasebranch_7_0/general/g.proj/create.c
grass/branches/releasebranch_7_0/general/g.proj/local_proto.h
grass/branches/releasebranch_7_0/general/g.proj/main.c
Log:
g.proj: generate PROJ_EPSG file when location is given #2490
(merge r64258 from trunk)
Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Added: svn:mergeinfo
+ /grass/trunk:64258
Modified: grass/branches/releasebranch_7_0/general/g.proj/create.c
===================================================================
--- grass/branches/releasebranch_7_0/general/g.proj/create.c 2015-01-21 09:24:43 UTC (rev 64272)
+++ grass/branches/releasebranch_7_0/general/g.proj/create.c 2015-01-21 13:47:31 UTC (rev 64273)
@@ -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/branches/releasebranch_7_0/general/g.proj/local_proto.h
===================================================================
--- grass/branches/releasebranch_7_0/general/g.proj/local_proto.h 2015-01-21 09:24:43 UTC (rev 64272)
+++ grass/branches/releasebranch_7_0/general/g.proj/local_proto.h 2015-01-21 13:47:31 UTC (rev 64273)
@@ -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/branches/releasebranch_7_0/general/g.proj/main.c
===================================================================
--- grass/branches/releasebranch_7_0/general/g.proj/main.c 2015-01-21 09:24:43 UTC (rev 64272)
+++ grass/branches/releasebranch_7_0/general/g.proj/main.c 2015-01-21 13:47:31 UTC (rev 64273)
@@ -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