[GRASS-SVN] r47020 - grass/trunk/general/g.proj
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jul 6 08:29:41 EDT 2011
Author: martinl
Date: 2011-07-06 05:29:40 -0700 (Wed, 06 Jul 2011)
New Revision: 47020
Added:
grass/trunk/general/g.proj/create.c
Modified:
grass/trunk/general/g.proj/input.c
grass/trunk/general/g.proj/local_proto.h
grass/trunk/general/g.proj/main.c
grass/trunk/general/g.proj/output.c
Log:
g.proj: don't require `-c` when `location` is defined
code reorganization
message cosmetics
Added: grass/trunk/general/g.proj/create.c
===================================================================
--- grass/trunk/general/g.proj/create.c (rev 0)
+++ grass/trunk/general/g.proj/create.c 2011-07-06 12:29:40 UTC (rev 47020)
@@ -0,0 +1,67 @@
+#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 `%s=%s`"),
+ "g.gisenv set=LOCATION_NAME", 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];
+
+ /* 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);
+ }
+
+ if (projunits != NULL) {
+ G_file_name(path, "", "PROJ_UNITS", "PERMANENT");
+ G_write_key_value_file(path, projunits);
+ }
+
+ 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"));
+}
Property changes on: grass/trunk/general/g.proj/create.c
___________________________________________________________________
Added: svn:mime-type
+ text/x-csrc
Added: svn:eol-style
+ native
Modified: grass/trunk/general/g.proj/input.c
===================================================================
--- grass/trunk/general/g.proj/input.c 2011-07-06 12:21:41 UTC (rev 47019)
+++ grass/trunk/general/g.proj/input.c 2011-07-06 12:29:40 UTC (rev 47020)
@@ -95,7 +95,7 @@
G_squeeze(buff);
}
else
- G_fatal_error(_("Unable to open file [%s] for reading"), wktfile);
+ G_fatal_error(_("Unable to open file '%s' for reading"), wktfile);
ret = GPJ_wkt_to_grass(&cellhd, &projinfo, &projunits, buff, 0);
set_default_region();
Modified: grass/trunk/general/g.proj/local_proto.h
===================================================================
--- grass/trunk/general/g.proj/local_proto.h 2011-07-06 12:21:41 UTC (rev 47019)
+++ grass/trunk/general/g.proj/local_proto.h 2011-07-06 12:29:40 UTC (rev 47020)
@@ -19,7 +19,10 @@
#ifdef HAVE_OGR
void print_wkt(int, int);
#endif
-void create_location(char *);
/* datumtrans.c */
int set_datumtrans(int, int);
+
+/* create.c */
+void create_location(char *);
+void modify_projinfo();
Modified: grass/trunk/general/g.proj/main.c
===================================================================
--- grass/trunk/general/g.proj/main.c 2011-07-06 12:21:41 UTC (rev 47019)
+++ grass/trunk/general/g.proj/main.c 2011-07-06 12:29:40 UTC (rev 47020)
@@ -61,12 +61,13 @@
module = G_define_module();
G_add_keyword(_("general"));
G_add_keyword(_("projection"));
+ G_add_keyword(_("create location"));
#ifdef HAVE_OGR
module->label =
- _("Converts co-ordinate system descriptions (i.e. projection "
- "information) between various formats (including GRASS format).");
+ _("Prints and manipulates GRASS projection information files "
+ "(in various co-ordinate system descriptions).");
module->description =
- _("Can also be used to create GRASS locations.");
+ _("Can also be used to create new GRASS locations.");
#else
module->description =
_("Prints and manipulates GRASS projection information files.");
@@ -123,8 +124,8 @@
ingeo->type = TYPE_STRING;
ingeo->key_desc = "file";
ingeo->required = NO;
- ingeo->guisection = _("Input");
- ingeo->description = _("Georeferenced data file to read projection "
+ ingeo->guisection = _("Specification");
+ ingeo->description = _("Name of georeferenced data file to read projection "
"information from");
inwkt = G_define_option();
@@ -132,24 +133,26 @@
inwkt->type = TYPE_STRING;
inwkt->key_desc = "file";
inwkt->required = NO;
- inwkt->guisection = _("Input");
- inwkt->description = _("ASCII file containing a WKT projection "
- "description (- for stdin)");
+ inwkt->guisection = _("Specification");
+ inwkt->label = _("Name of ASCII file containing a WKT projection "
+ "description");
+ inwkt->description = _("'-' for standard input");
inproj4 = G_define_option();
inproj4->key = "proj4";
inproj4->type = TYPE_STRING;
inproj4->key_desc = "params";
inproj4->required = NO;
- inproj4->guisection = _("Input");
- inproj4->description = _("PROJ.4 projection description (- for stdin)");
+ inproj4->guisection = _("Specification");
+ inproj4->label = _("PROJ.4 projection description");
+ inproj4->description = _("'-' for standard input");
inepsg = G_define_option();
inepsg->key = "epsg";
inepsg->type = TYPE_INTEGER;
inepsg->required = NO;
inepsg->options = "1-1000000";
- inepsg->guisection = _("Input");
+ inepsg->guisection = _("Specification");
inepsg->description = _("EPSG projection code");
#endif
@@ -172,16 +175,16 @@
create = G_define_flag();
create->key = 'c';
- create->guisection = _("Create/Edit");
+ create->guisection = _("Modify");
create->description = _("Create new projection files (modifies current "
- "location unless 'location' option specified)");
+ "location)");
location = G_define_option();
location->key = "location";
location->type = TYPE_STRING;
location->key_desc = "name";
location->required = NO;
- location->guisection = _("Create/Edit");
+ location->guisection = _("Create");
location->description = _("Name of new location to create");
if (G_parser(argc, argv))
@@ -264,12 +267,16 @@
else if (printwkt->answer)
print_wkt(esristyle->answer, dontprettify->answer);
#endif
+ else if (location->answer)
+ create_location(location->answer);
else if (create->answer)
- create_location(location->answer);
+ modify_projinfo();
else
- G_warning(_("No output! Please specify an output option."));
+ G_fatal_error(_("No output format specified, define one "
+ "of flags -%c, -%c, -%c, or -%c"),
+ printinfo->key, shellinfo->key, printproj4->key, printwkt->key);
+
-
/* Tidy Up */
if (projinfo != NULL)
Modified: grass/trunk/general/g.proj/output.c
===================================================================
--- grass/trunk/general/g.proj/output.c 2011-07-06 12:21:41 UTC (rev 47019)
+++ grass/trunk/general/g.proj/output.c 2011-07-06 12:29:40 UTC (rev 47020)
@@ -15,8 +15,6 @@
*****************************************************************************/
#include <stdio.h>
-#include <string.h>
-#include <errno.h>
#include <proj_api.h>
@@ -164,68 +162,6 @@
}
#endif
-void create_location(char *location)
-{
- int ret;
-
- if (location) {
- 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"));
- }
- else {
- /* Create flag given but no location specified; overwrite
- * projection files for current location */
-
- 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];
-
- /* 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);
- }
-
- if (projunits != NULL) {
- G_file_name(path, "", "PROJ_UNITS", "PERMANENT");
- G_write_key_value_file(path, projunits);
- }
-
- 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(_("N.B. The 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_message(_("Projection information updated!"));
- }
-
- return;
-}
-
static int check_xy(int shell)
{
if (cellhd.proj == PROJECTION_XY) {
More information about the grass-commit
mailing list