[GRASS-SVN] r68980 - grass/trunk/vector/v.external

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 15 08:06:55 PDT 2016


Author: martinl
Date: 2016-07-15 08:06:55 -0700 (Fri, 15 Jul 2016)
New Revision: 68980

Modified:
   grass/trunk/vector/v.external/args.c
   grass/trunk/vector/v.external/local_proto.h
   grass/trunk/vector/v.external/main.c
Log:
v.external: implement -o flag

Modified: grass/trunk/vector/v.external/args.c
===================================================================
--- grass/trunk/vector/v.external/args.c	2016-07-15 14:54:04 UTC (rev 68979)
+++ grass/trunk/vector/v.external/args.c	2016-07-15 15:06:55 UTC (rev 68980)
@@ -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/trunk/vector/v.external/local_proto.h
===================================================================
--- grass/trunk/vector/v.external/local_proto.h	2016-07-15 14:54:04 UTC (rev 68979)
+++ grass/trunk/vector/v.external/local_proto.h	2016-07-15 15:06:55 UTC (rev 68980)
@@ -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/trunk/vector/v.external/main.c
===================================================================
--- grass/trunk/vector/v.external/main.c	2016-07-15 14:54:04 UTC (rev 68979)
+++ grass/trunk/vector/v.external/main.c	2016-07-15 15:06:55 UTC (rev 68980)
@@ -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