[GRASS-SVN] r68981 - grass/branches/releasebranch_7_2/vector/v.external
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jul 15 08:11:17 PDT 2016
Author: martinl
Date: 2016-07-15 08:11:17 -0700 (Fri, 15 Jul 2016)
New Revision: 68981
Modified:
grass/branches/releasebranch_7_2/vector/v.external/args.c
grass/branches/releasebranch_7_2/vector/v.external/local_proto.h
grass/branches/releasebranch_7_2/vector/v.external/main.c
Log:
v.external: implement -o flag (merge r68980 from trunk)
Modified: grass/branches/releasebranch_7_2/vector/v.external/args.c
===================================================================
--- grass/branches/releasebranch_7_2/vector/v.external/args.c 2016-07-15 15:06:55 UTC (rev 68980)
+++ grass/branches/releasebranch_7_2/vector/v.external/args.c 2016-07-15 15:11:17 UTC (rev 68981)
@@ -37,6 +37,13 @@
options->output->required = NO;
options->output->description = _("Name for output GRASS vector map (default: input layer)");
+ flags->override = G_define_flag();
+ flags->override->key = 'o';
+ flags->override->label =
+ _("Override projection check (use current location's projection)");
+ flags->override->description =
+ _("Assume that the dataset has the same projection as the current location");
+
flags->format = G_define_flag();
flags->format->key = 'f';
flags->format->description = _("List supported formats and exit");
Modified: grass/branches/releasebranch_7_2/vector/v.external/local_proto.h
===================================================================
--- grass/branches/releasebranch_7_2/vector/v.external/local_proto.h 2016-07-15 15:06:55 UTC (rev 68980)
+++ grass/branches/releasebranch_7_2/vector/v.external/local_proto.h 2016-07-15 15:11:17 UTC (rev 68981)
@@ -6,7 +6,7 @@
};
struct _flags {
- struct Flag *format, *layer, *tlist, *topo, *list;
+ struct Flag *format, *layer, *tlist, *topo, *list, *override;
};
/* args.c */
Modified: grass/branches/releasebranch_7_2/vector/v.external/main.c
===================================================================
--- grass/branches/releasebranch_7_2/vector/v.external/main.c 2016-07-15 15:06:55 UTC (rev 68980)
+++ grass/branches/releasebranch_7_2/vector/v.external/main.c 2016-07-15 15:11:17 UTC (rev 68981)
@@ -128,6 +128,104 @@
G_fatal_error(_("option <%s>: <%s> exists. To overwrite, use the --overwrite flag"),
options.output->key, output);
}
+
+ /* check projection match */
+ if (!flags.override->answer) {
+ int err = 0;
+ char error_msg[8192];
+
+ struct Cell_head cellhd, loc_wind;
+ struct Key_Value *loc_proj_info, *loc_proj_units;
+ struct Key_Value *proj_info, *proj_units;
+
+ proj_info = proj_units = NULL;
+ loc_proj_info = G_get_projinfo();
+ loc_proj_units = G_get_projunits();
+
+ G_get_default_window(&loc_wind);
+ G_get_window(&cellhd);
+
+ if ((err =
+ G_compare_projections(loc_proj_info, loc_proj_units,
+ proj_info, proj_units)) != TRUE) {
+ int i_value;
+
+ strcpy(error_msg,
+ _("Projection of dataset does not"
+ " appear to match current location.\n\n"));
+
+ /* TODO: output this info sorted by key: */
+ if (loc_wind.proj != cellhd.proj || err != -2) {
+ if (loc_proj_info != NULL) {
+ strcat(error_msg, _("GRASS LOCATION PROJ_INFO is:\n"));
+ for (i_value = 0; i_value < loc_proj_info->nitems;
+ i_value++)
+ sprintf(error_msg + strlen(error_msg), "%s: %s\n",
+ loc_proj_info->key[i_value],
+ loc_proj_info->value[i_value]);
+ strcat(error_msg, "\n");
+ }
+
+ if (proj_info != NULL) {
+ strcat(error_msg, _("Import dataset PROJ_INFO is:\n"));
+ for (i_value = 0; i_value < proj_info->nitems; i_value++)
+ sprintf(error_msg + strlen(error_msg), "%s: %s\n",
+ proj_info->key[i_value],
+ proj_info->value[i_value]);
+ }
+ else {
+ strcat(error_msg, _("Import dataset PROJ_INFO is:\n"));
+ if (cellhd.proj == PROJECTION_XY)
+ sprintf(error_msg + strlen(error_msg),
+ "Dataset proj = %d (unreferenced/unknown)\n",
+ cellhd.proj);
+ else if (cellhd.proj == PROJECTION_LL)
+ sprintf(error_msg + strlen(error_msg),
+ "Dataset proj = %d (lat/long)\n",
+ cellhd.proj);
+ else if (cellhd.proj == PROJECTION_UTM)
+ sprintf(error_msg + strlen(error_msg),
+ "Dataset proj = %d (UTM), zone = %d\n",
+ cellhd.proj, cellhd.zone);
+ else
+ sprintf(error_msg + strlen(error_msg),
+ "Dataset proj = %d (unknown), zone = %d\n",
+ cellhd.proj, cellhd.zone);
+ }
+ }
+ else {
+ if (loc_proj_units != NULL) {
+ strcat(error_msg, "GRASS LOCATION PROJ_UNITS is:\n");
+ for (i_value = 0; i_value < loc_proj_units->nitems;
+ i_value++)
+ sprintf(error_msg + strlen(error_msg), "%s: %s\n",
+ loc_proj_units->key[i_value],
+ loc_proj_units->value[i_value]);
+ strcat(error_msg, "\n");
+ }
+
+ if (proj_units != NULL) {
+ strcat(error_msg, "Import dataset PROJ_UNITS is:\n");
+ for (i_value = 0; i_value < proj_units->nitems; i_value++)
+ sprintf(error_msg + strlen(error_msg), "%s: %s\n",
+ proj_units->key[i_value],
+ proj_units->value[i_value]);
+ }
+ }
+ sprintf(error_msg + strlen(error_msg),
+ _("\nIn case of no significant differences in the projection definitions,"
+ " use the -o flag to ignore them and use"
+ " current location definition.\n"));
+ strcat(error_msg,
+ _("Consider generating a new location with 'location' parameter"
+ " from input data set.\n"));
+ G_fatal_error(error_msg);
+ }
+ else {
+ G_verbose_message(_("Projection of input dataset and current location "
+ "appear to match"));
+ }
+ }
/* create new vector map */
putenv("GRASS_VECTOR_EXTERNAL_IGNORE=1");
More information about the grass-commit
mailing list