[GRASS-SVN] r73117 - in grass/trunk: raster/r.in.gdal vector/v.in.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 17 07:44:41 PDT 2018


Author: mmetz
Date: 2018-08-17 07:44:41 -0700 (Fri, 17 Aug 2018)
New Revision: 73117

Modified:
   grass/trunk/raster/r.in.gdal/main.c
   grass/trunk/vector/v.in.ogr/main.c
Log:
r.in.gdal/v.in.ogr: +GDAL config and dataset open options (#3413)

Modified: grass/trunk/raster/r.in.gdal/main.c
===================================================================
--- grass/trunk/raster/r.in.gdal/main.c	2018-08-17 13:02:23 UTC (rev 73116)
+++ grass/trunk/raster/r.in.gdal/main.c	2018-08-17 14:44:41 UTC (rev 73117)
@@ -74,6 +74,7 @@
     int num_digits = 0;
     int croptoregion, *rowmapall, *colmapall, *rowmap, *colmap, col_offset;
     int roff, coff;
+    char **doo;
 
     struct GModule *module;
     struct
@@ -80,7 +81,7 @@
     {
 	struct Option *input, *output, *target, *title, *outloc, *band,
 	              *memory, *offset, *num_digits, *map_names_file,
-	              *rat;
+	              *rat, *cfg, *doo;
     } parm;
     struct Flag *flag_o, *flag_e, *flag_k, *flag_f, *flag_l, *flag_c, *flag_p,
         *flag_j, *flag_a, *flag_r;
@@ -181,6 +182,20 @@
     parm.rat->description = _("The band number and \".csv\" will be appended to the file prefix");
     parm.rat->key_desc = "file";
 
+    parm.cfg = G_define_option();
+    parm.cfg->key = "gdal_config";
+    parm.cfg->type = TYPE_STRING;
+    parm.cfg->required = NO;
+    parm.cfg->label = _("GDAL configuration options");
+    parm.cfg->description = _("Comma-separated list of key=value pairs");
+
+    parm.doo = G_define_option();
+    parm.doo->key = "gdal_doo";
+    parm.doo->type = TYPE_STRING;
+    parm.doo->required = NO;
+    parm.doo->label = _("GDAL dataset open options");
+    parm.doo->description = _("Comma-separated list of key=value pairs");
+
     flag_o = G_define_flag();
     flag_o->key = 'o';
     flag_o->label =
@@ -348,10 +363,56 @@
 	CPLSetConfigOption("GDAL_CACHEMAX", parm.memory->answer);
     }
 
+    /* GDAL configuration options */
+    if (parm.cfg->answer) {
+	char **tokens, *tok, *key, *value;
+	int i, ntokens;
+
+	tokens = G_tokenize(parm.cfg->answer, ",");
+	ntokens = G_number_of_tokens(tokens);
+	for (i = 0; i < ntokens; i++) {
+	    G_debug(1, "%d=[%s]", i, tokens[i]);
+	    tok = G_store(tokens[i]);
+	    G_squeeze(tok);
+	    key = tok;
+	    value = strstr(tok, "=");
+	    if (value) {
+		*value = '\0';
+		value++;
+		CPLSetConfigOption(key, value);
+	    }
+	    G_free(tok);
+	}
+	G_free_tokens(tokens);
+    }
+
+    /* GDAL dataset open options */
+    doo = NULL;
+    if (parm.doo->answer) {
+	char **tokens;
+	int i, ntokens;
+
+	tokens = G_tokenize(parm.doo->answer, ",");
+	ntokens = G_number_of_tokens(tokens);
+	doo = G_malloc(sizeof(char *) * (ntokens + 1));
+	for (i = 0; i < ntokens; i++) {
+	    G_debug(1, "%d=[%s]", i, tokens[i]);
+	    doo[i] = G_store(tokens[i]);
+	}
+	G_free_tokens(tokens);
+	doo[ntokens] = NULL;
+    }
+
     /* -------------------------------------------------------------------- */
-    /*      Open the file.                                                  */
+    /*      Open the dataset.                                               */
     /* -------------------------------------------------------------------- */
+
+#if GDAL_VERSION_NUM >= 2000000
+    hDS = GDALOpenEx(input, GDAL_OF_RASTER | GDAL_OF_READONLY, NULL,
+                     (const char **) doo, NULL);
+#else
     hDS = GDALOpen(input, GA_ReadOnly);
+#endif
     if (hDS == NULL)
         G_fatal_error(_("Unable to open datasource <%s>"), input);
     G_add_error_handler(error_handler_ds, hDS);

Modified: grass/trunk/vector/v.in.ogr/main.c
===================================================================
--- grass/trunk/vector/v.in.ogr/main.c	2018-08-17 13:02:23 UTC (rev 73116)
+++ grass/trunk/vector/v.in.ogr/main.c	2018-08-17 14:44:41 UTC (rev 73117)
@@ -113,7 +113,7 @@
     struct GModule *module;
     struct _param {
 	struct Option *dsn, *out, *layer, *spat, *where,
-	    *min_area;
+	    *min_area, *cfg, *doo;
         struct Option *snap, *type, *outloc, *cnames, *encoding, *key, *geom;
     } param;
     struct _flag {
@@ -162,7 +162,7 @@
 
     int OFTIntegerListlength;
 
-    char *dsn;
+    char *dsn, **doo;
     const char *driver_name;
     const char *datetime_type;
     char *output;
@@ -211,6 +211,20 @@
 				   "\t\tMapInfo File: directory containing mapinfo files");
     param.dsn->gisprompt = "old,datasource,datasource";
     
+    param.cfg = G_define_option();
+    param.cfg->key = "gdal_config";
+    param.cfg->type = TYPE_STRING;
+    param.cfg->required = NO;
+    param.cfg->label = _("GDAL configuration options");
+    param.cfg->description = _("Comma-separated list of key=value pairs");
+
+    param.doo = G_define_option();
+    param.doo->key = "gdal_doo";
+    param.doo->type = TYPE_STRING;
+    param.doo->required = NO;
+    param.doo->label = _("GDAL dataset open options");
+    param.doo->description = _("Comma-separated list of key=value pairs");
+
     param.layer = G_define_option();
     param.layer->key = "layer";
     param.layer->type = TYPE_STRING;
@@ -492,11 +506,52 @@
 	G_free(encbuf);
     }
 
+    /* GDAL configuration options */
+    if (param.cfg->answer) {
+	char **tokens, *tok, *key, *value;
+	int ntokens;
+
+	tokens = G_tokenize(param.cfg->answer, ",");
+	ntokens = G_number_of_tokens(tokens);
+	for (i = 0; i < ntokens; i++) {
+	    G_debug(1, "%d=[%s]", i, tokens[i]);
+	    tok = G_store(tokens[i]);
+	    G_squeeze(tok);
+	    key = tok;
+	    value = strstr(tok, "=");
+	    if (value) {
+		*value = '\0';
+		value++;
+		CPLSetConfigOption(key, value);
+	    }
+	    G_free(tok);
+	}
+	G_free_tokens(tokens);
+    }
+
+    /* GDAL dataset open options */
+    doo = NULL;
+    if (param.doo->answer) {
+	char **tokens;
+	int ntokens;
+
+	tokens = G_tokenize(param.doo->answer, ",");
+	ntokens = G_number_of_tokens(tokens);
+	doo = G_malloc(sizeof(char *) * (ntokens + 1));
+	for (i = 0; i < ntokens; i++) {
+	    G_debug(1, "%d=[%s]", i, tokens[i]);
+	    doo[i] = G_store(tokens[i]);
+	}
+	G_free_tokens(tokens);
+	doo[ntokens] = NULL;
+    }
+
     /* open OGR DSN */
     Ogr_ds = NULL;
     if (strlen(dsn) > 0) {
 #if GDAL_VERSION_NUM >= 2020000
-	Ogr_ds = GDALOpenEx(dsn, GDAL_OF_VECTOR, NULL, NULL, NULL);
+	Ogr_ds = GDALOpenEx(dsn, GDAL_OF_VECTOR, NULL,
+	                    (const char **) doo, NULL);
 #else
 	Ogr_ds = OGROpen(dsn, FALSE, NULL);
 #endif



More information about the grass-commit mailing list