[GRASS-SVN] r53454 - grass/branches/releasebranch_6_4/general/g.proj

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Oct 17 13:20:37 PDT 2012


Author: neteler
Date: 2012-10-17 13:20:36 -0700 (Wed, 17 Oct 2012)
New Revision: 53454

Added:
   grass/branches/releasebranch_6_4/general/g.proj/create.c
Log:
backport with GRASS 6 adaptations of datum handling patches by Paul Kelly: r53297, r53305, r53310 from trunk

Added: grass/branches/releasebranch_6_4/general/g.proj/create.c
===================================================================
--- grass/branches/releasebranch_6_4/general/g.proj/create.c	                        (rev 0)
+++ grass/branches/releasebranch_6_4/general/g.proj/create.c	2012-10-17 20:20:36 UTC (rev 53454)
@@ -0,0 +1,68 @@
+#include <errno.h>
+#include <string.h>
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+void create_location(char *location)
+{
+    int ret;
+
+    ret = G__make_location(location, &cellhd, projinfo, projunits, NULL);
+    if (ret == 0)
+	G_message(_("Location <%s> created"), location);
+    else if (ret == -1)
+	G_fatal_error(_("Unable to create location <%s>: %s"),
+		    location, strerror(errno));
+    else if (ret == -2)
+	G_fatal_error(_("Unable to create projection files: %s"),
+		    strerror(errno));
+    else
+	/* Shouldn't happen */
+	G_fatal_error(_("Unspecified error while creating new location"));
+
+    G_message(_("You can switch to the new location by\n`%s=%s`"),
+	      "g.mapset mapset=PERMANENT location", location);
+}
+
+void modify_projinfo()
+{
+    const char *mapset = G_mapset();
+    struct Cell_head old_cellhd;
+    
+    if (strcmp(mapset, "PERMANENT") != 0)
+	G_fatal_error(_("You must select the PERMANENT mapset before updating the "
+			"current location's projection (current mapset is <%s>)."),
+		      mapset);
+    
+    /* Read projection information from current location first */
+    G_get_default_window(&old_cellhd);
+    
+    char path[GPATH_MAX];
+    int stat;
+	
+    /* Write out the PROJ_INFO, and PROJ_UNITS if available. */
+    if (projinfo != NULL) {
+	G__file_name(path, "", "PROJ_INFO", "PERMANENT");
+	G_write_key_value_file(path, projinfo, &stat);
+    }
+    
+    if (projunits != NULL) {
+	G__file_name(path, "", "PROJ_UNITS", "PERMANENT");
+	G_write_key_value_file(path, projunits, &stat);
+    }
+    
+    if ((old_cellhd.zone != cellhd.zone) ||
+	(old_cellhd.proj != cellhd.proj)) {
+	/* Recreate the default, and current window files if projection
+	 * number or zone have changed */
+	G__put_window(&cellhd, "", "DEFAULT_WIND");
+	G__put_window(&cellhd, "", "WIND");
+	G_message(_("Default region was updated to the new projection, but if you have "
+		    "multiple mapsets `g.region -d` should be run in each to update the "
+		    "region from the default"));
+    }
+    G_important_message(_("Projection information updated"));
+}



More information about the grass-commit mailing list