[GRASS-SVN] r69652 - grass/branches/releasebranch_7_2/vector/v.external

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Oct 3 08:52:37 PDT 2016


Author: martinl
Date: 2016-10-03 08:52:37 -0700 (Mon, 03 Oct 2016)
New Revision: 69652

Added:
   grass/branches/releasebranch_7_2/vector/v.external/proj.c
Modified:
   grass/branches/releasebranch_7_2/vector/v.external/local_proto.h
   grass/branches/releasebranch_7_2/vector/v.external/main.c
Log:
 v.external: fix check projection (relbr72: merge r69651 from trunk)

Modified: grass/branches/releasebranch_7_2/vector/v.external/local_proto.h
===================================================================
--- grass/branches/releasebranch_7_2/vector/v.external/local_proto.h	2016-10-03 15:47:30 UTC (rev 69651)
+++ grass/branches/releasebranch_7_2/vector/v.external/local_proto.h	2016-10-03 15:52:37 UTC (rev 69652)
@@ -21,4 +21,6 @@
 int list_layers(FILE *, const char *, char **, int, int);
 void get_table_name(const char *, char **, char **);
 
+/* proj.c */
+void check_projection(const char *, int);
 #endif

Modified: grass/branches/releasebranch_7_2/vector/v.external/main.c
===================================================================
--- grass/branches/releasebranch_7_2/vector/v.external/main.c	2016-10-03 15:47:30 UTC (rev 69651)
+++ grass/branches/releasebranch_7_2/vector/v.external/main.c	2016-10-03 15:52:37 UTC (rev 69652)
@@ -135,100 +135,7 @@
 
     /* 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("%s", error_msg);
-	}
-	else {
-            G_verbose_message(_("Projection of input dataset and current location "
-                                "appear to match"));
-	}
+        check_projection(dsn, ilayer);
     }
     
     /* create new vector map */

Copied: grass/branches/releasebranch_7_2/vector/v.external/proj.c (from rev 69651, grass/trunk/vector/v.external/proj.c)
===================================================================
--- grass/branches/releasebranch_7_2/vector/v.external/proj.c	                        (rev 0)
+++ grass/branches/releasebranch_7_2/vector/v.external/proj.c	2016-10-03 15:52:37 UTC (rev 69652)
@@ -0,0 +1,126 @@
+#include <grass/gis.h>
+#include <grass/gprojects.h>
+#include <grass/glocale.h>
+
+#ifdef HAVE_OGR
+#include "ogr_api.h"
+#endif
+
+void check_projection(const char *dsn, int ilayer)
+{
+#ifdef HAVE_OGR
+    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;
+    
+    OGRDataSourceH Ogr_ds;
+    OGRLayerH Ogr_layer;
+    OGRSpatialReferenceH Ogr_projection;
+    
+    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);
+    
+    Ogr_ds = OGROpen(dsn, FALSE, NULL);
+    if (!Ogr_ds) {
+	G_fatal_error(_("Unable to open data source '%s'"), dsn);
+    }
+    if (ilayer > OGR_DS_GetLayerCount(Ogr_ds))
+        return;
+    Ogr_layer = OGR_DS_GetLayer(Ogr_ds, ilayer);
+    Ogr_projection = OGR_L_GetSpatialRef(Ogr_layer);
+    
+    if (GPJ_osr_to_grass(&cellhd, &proj_info,
+                         &proj_units, Ogr_projection, 0) < 0)
+        G_warning(_("Unable to convert input map projection information to "
+                    "GRASS format for checking"));
+    OGR_DS_Destroy(Ogr_ds);
+    
+    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("%s", error_msg);
+    }
+    else {
+        G_verbose_message(_("Projection of input dataset and current location "
+                            "appear to match"));
+    }
+#endif
+}



More information about the grass-commit mailing list