[GRASS-SVN] r71559 - grass/trunk/vector/v.external
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Oct 15 10:11:46 PDT 2017
Author: mmetz
Date: 2017-10-15 10:11:46 -0700 (Sun, 15 Oct 2017)
New Revision: 71559
Modified:
grass/trunk/vector/v.external/local_proto.h
grass/trunk/vector/v.external/main.c
grass/trunk/vector/v.external/proj.c
Log:
v.external: keep check_projection() identical to v.in.ogr
Modified: grass/trunk/vector/v.external/local_proto.h
===================================================================
--- grass/trunk/vector/v.external/local_proto.h 2017-10-15 16:43:51 UTC (rev 71558)
+++ grass/trunk/vector/v.external/local_proto.h 2017-10-15 17:11:46 UTC (rev 71559)
@@ -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 @@
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
Modified: grass/trunk/vector/v.external/main.c
===================================================================
--- grass/trunk/vector/v.external/main.c 2017-10-15 16:43:51 UTC (rev 71558)
+++ grass/trunk/vector/v.external/main.c 2017-10-15 17:11:46 UTC (rev 71559)
@@ -44,6 +44,7 @@
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 @@
options.output->key, output);
}
+ /* 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);
+
+ 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 */
- G_get_window(&cellhd);
- check_projection(&cellhd, options.dsn->answer, ilayer, NULL, NULL, 0,
+ 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");
Modified: grass/trunk/vector/v.external/proj.c
===================================================================
--- grass/trunk/vector/v.external/proj.c 2017-10-15 16:43:51 UTC (rev 71558)
+++ grass/trunk/vector/v.external/proj.c 2017-10-15 17:11:46 UTC (rev 71559)
@@ -2,23 +2,9 @@
#include <grass/gprojects.h>
#include <grass/glocale.h>
-#include <gdal.h>
-#include <gdal_version.h>
-#include "ogr_api.h"
+#include <ogr_srs_api.h>
+#include "local_proto.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
-
/* get projection info of OGR layer in GRASS format
* return 0 on success (some non-xy SRS)
* return 1 if no SRS available
@@ -129,7 +115,7 @@
}
/* 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 @@
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 @@
}
}
}
- ds_close(hDS);
}
More information about the grass-commit
mailing list