Browse Source

v.external: keep check_projection() identical to v.in.ogr

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@71559 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 7 years ago
parent
commit
f59fe520cb
3 changed files with 55 additions and 34 deletions
  1. 18 1
      vector/v.external/local_proto.h
  2. 34 2
      vector/v.external/main.c
  3. 3 31
      vector/v.external/proj.c

+ 18 - 1
vector/v.external/local_proto.h

@@ -1,6 +1,23 @@
 #ifndef V_EXTERNAL_LOCAL_PROTO_H
 #define V_EXTERNAL_LOCAL_PROTO_H
 
+#include <gdal.h>
+#include <gdal_version.h>
+#include <ogr_api.h>
+
+/* define type of input datasource
+ * as of GDAL 2.2, all functions having as argument a GDAL/OGR dataset 
+ * must use the GDAL version, not the OGR version */
+#if GDAL_VERSION_NUM >= 2020000
+typedef GDALDatasetH ds_t;
+#define ds_getlayerbyindex(ds, i)	GDALDatasetGetLayer((ds), (i))
+#define ds_close(ds)			GDALClose(ds)
+#else
+typedef OGRDataSourceH ds_t;
+#define ds_getlayerbyindex(ds, i)	OGR_DS_GetLayer((ds), (i))
+#define ds_close(ds)			OGR_DS_Destroy(ds)
+#endif
+
 struct _options {
     struct Option *dsn, *output, *layer, *where;
 };
@@ -22,6 +39,6 @@ int list_layers(FILE *, const char *, char **, int, int);
 void get_table_name(const char *, char **, char **);
 
 /* proj.c */
-void check_projection(struct Cell_head *, const char *, int, char *,
+void check_projection(struct Cell_head *, ds_t, int, char *,
                       char *, int, int, int);
 #endif

+ 34 - 2
vector/v.external/main.c

@@ -44,6 +44,7 @@ int main(int argc, char *argv[])
     char buf[GPATH_MAX], *dsn, *layer;
     const char *output;
     struct Cell_head cellhd;
+    ds_t Ogr_ds;
     
     G_gisinit(argv[0]);
     
@@ -137,10 +138,41 @@ int main(int argc, char *argv[])
                       options.output->key, output);
     }
 
-    /* check projection match */
+    /* open OGR DSN */
+    Ogr_ds = NULL;
+    if (strlen(options.dsn->answer) > 0) {
+#if GDAL_VERSION_NUM >= 2020000
+	Ogr_ds = GDALOpenEx(options.dsn->answer, GDAL_OF_VECTOR, NULL, NULL, NULL);
+#else
+	Ogr_ds = OGROpen(dsn, FALSE, NULL);
+#endif
+    }
+    if (Ogr_ds == NULL)
+	G_fatal_error(_("Unable to open data source <%s>"), dsn);
+
     G_get_window(&cellhd);
-    check_projection(&cellhd, options.dsn->answer, ilayer, NULL, NULL, 0,
+
+    cellhd.north = 1.;
+    cellhd.south = 0.;
+    cellhd.west = 0.;
+    cellhd.east = 1.;
+    cellhd.top = 1.;
+    cellhd.bottom = 0.;
+    cellhd.rows = 1;
+    cellhd.rows3 = 1;
+    cellhd.cols = 1;
+    cellhd.cols3 = 1;
+    cellhd.depths = 1;
+    cellhd.ns_res = 1.;
+    cellhd.ns_res3 = 1.;
+    cellhd.ew_res = 1.;
+    cellhd.ew_res3 = 1.;
+    cellhd.tb_res = 1.;
+
+    /* check projection match */
+    check_projection(&cellhd, Ogr_ds, ilayer, NULL, NULL, 0,
                      flags.override->answer, flags.proj->answer);
+    ds_close(Ogr_ds);
     
     /* create new vector map */
     putenv("GRASS_VECTOR_EXTERNAL_IGNORE=1");

+ 3 - 31
vector/v.external/proj.c

@@ -2,22 +2,8 @@
 #include <grass/gprojects.h>
 #include <grass/glocale.h>
 
-#include <gdal.h>
-#include <gdal_version.h>
-#include "ogr_api.h"
-
-/* define type of input datasource
- * as of GDAL 2.2, all functions having as argument a GDAL/OGR dataset 
- * must use the GDAL version, not the OGR version */
-#if GDAL_VERSION_NUM >= 2020000
-typedef GDALDatasetH ds_t;
-#define ds_getlayerbyindex(ds, i)	GDALDatasetGetLayer((ds), (i))
-#define ds_close(ds)			GDALClose(ds)
-#else
-typedef OGRDataSourceH ds_t;
-#define ds_getlayerbyindex(ds, i)	OGR_DS_GetLayer((ds), (i))
-#define ds_close(ds)			OGR_DS_Destroy(ds)
-#endif
+#include <ogr_srs_api.h>
+#include "local_proto.h"
 
 /* get projection info of OGR layer in GRASS format
  * return 0 on success (some non-xy SRS)
@@ -129,7 +115,7 @@ int get_layer_proj(OGRLayerH Ogr_layer, struct Cell_head *cellhd,
 }
 
 /* keep in sync with r.in.gdal, r.external, v.in.ogr */
-void check_projection(struct Cell_head *cellhd, char *dsn, int layer, char *geom_col,
+void check_projection(struct Cell_head *cellhd, ds_t hDS, int layer, char *geom_col,
                       char *outloc, int create_only, int override,
 		      int check_only)
 {
@@ -138,21 +124,8 @@ void check_projection(struct Cell_head *cellhd, char *dsn, int layer, char *geom
     struct Key_Value *loc_proj_info = NULL, *loc_proj_units = NULL;
     char error_msg[8096];
     int proj_trouble;
-    ds_t hDS;
     OGRLayerH Ogr_layer;
 
-    /* open OGR DSN (v.external does not open the datasource itself */
-    hDS = NULL;
-    if (strlen(dsn) > 0) {
-#if GDAL_VERSION_NUM >= 2020000
-	hDS = GDALOpenEx(dsn, GDAL_OF_VECTOR, NULL, NULL, NULL);
-#else
-	hDS = OGROpen(dsn, FALSE, NULL);
-#endif
-    }
-    if (hDS == NULL)
-	G_fatal_error(_("Unable to open data source <%s>"), dsn);
-
     /* Get first layer to be imported to use for projection check */
     Ogr_layer = ds_getlayerbyindex(hDS, layer);
 
@@ -377,5 +350,4 @@ void check_projection(struct Cell_head *cellhd, char *dsn, int layer, char *geom
 	    }
 	}
     }
-    ds_close(hDS);
 }