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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Mar 26 09:55:39 EDT 2012


Author: martinl
Date: 2012-03-26 06:55:38 -0700 (Mon, 26 Mar 2012)
New Revision: 51161

Modified:
   grass/trunk/vector/v.external.out/args.c
   grass/trunk/vector/v.external.out/format.c
   grass/trunk/vector/v.external.out/link.c
   grass/trunk/vector/v.external.out/list.c
   grass/trunk/vector/v.external.out/main.c
   grass/trunk/vector/v.external.out/v.external.out.html
Log:
v.external.out: simplify user interface
		GRASS-PostGIS data driver is used by default for `format=PostgreSQL`
		introduce GRASS_VECTOR_OGR env variable to force using OGR also for PostGIS output


Modified: grass/trunk/vector/v.external.out/args.c
===================================================================
--- grass/trunk/vector/v.external.out/args.c	2012-03-26 12:21:10 UTC (rev 51160)
+++ grass/trunk/vector/v.external.out/args.c	2012-03-26 13:55:38 UTC (rev 51161)
@@ -14,25 +14,30 @@
     options->dsn->description = _("Examples:\n"
 				  "\t\tESRI Shapefile: directory containing a shapefile\n"
 				  "\t\tMapInfo File: directory containing a mapinfo file\n"
-				  "\t\tPostGIS: connection string, eg. 'PG:dbname=db user=grass'");
+				  "\t\tPostGIS: connection string, eg. 'PG:dbname=gisdb user=grass'");
 
     options->dsn->required = YES;
     options->dsn->type = TYPE_STRING;
 
     options->format = G_define_option();
     options->format->key = "format";
-    options->format->label = _("Format for output vector data");
-    options->format->description = _("PostGIS is supported via PG ('format=PostGIS') or "
-				     "OGR (format=PostgreSQL) data driver");
+    options->format->description = _("Format for output vector data");
     options->format->required = YES;
     options->format->type = TYPE_STRING;
     options->format->options = format_list();
- 
+#ifdef HAVE_OGR
+    options->format->answer = "ESRI_Shapefile";
+#else
+#ifdef HAVE_POSTGRES
+    options->format->answer = "PostgreSQL";
+#endif /* HAVE_POSTGRES */
+#endif /* HAVE_OGR */
+    
     options->opts = G_define_option();
     options->opts->key = "options";
     options->opts->label = _("Creation options");
     options->opts->description = _("Examples:\n"
-				  "\t\t'SHPT=POINTZ': use 3D point Shapefile data\n"
+				  "\t\t'SHPT=POINTZ': create 3D point Shapefile data\n"
 				  "\t\t'GEOM_TYPE=geography': use geography PostGIS data\n"
 				  "\t\t'SCHEMA=grass': create new PostGIS tables in 'grass' schema");
     options->opts->required = NO;

Modified: grass/trunk/vector/v.external.out/format.c
===================================================================
--- grass/trunk/vector/v.external.out/format.c	2012-03-26 12:21:10 UTC (rev 51160)
+++ grass/trunk/vector/v.external.out/format.c	2012-03-26 13:55:38 UTC (rev 51161)
@@ -1,3 +1,5 @@
+#include <string.h>
+
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
@@ -7,7 +9,7 @@
 
 void check_format(char *format)
 {
-    if(strcmp(format, "PostGIS") == 0)
+    if(strcmp(format, "PostgreSQL") == 0)
 	return;
     
 #ifdef HAVE_OGR

Modified: grass/trunk/vector/v.external.out/link.c
===================================================================
--- grass/trunk/vector/v.external.out/link.c	2012-03-26 12:21:10 UTC (rev 51160)
+++ grass/trunk/vector/v.external.out/link.c	2012-03-26 13:55:38 UTC (rev 51161)
@@ -21,11 +21,39 @@
     key_val = G_create_key_value();
 
     /* use OGR ? */
-    if (strcmp(format, "PostGIS") == 0) {
-	use_ogr  = FALSE;
-	filename = "PG";
-	G_remove("", "OGR");
-    }
+    if (strcmp(format, "PostgreSQL") == 0) {
+#if defined HAVE_OGR && defined HAVE_POSTGRES
+      if (getenv("GRASS_VECTOR_OGR")) {
+	  use_ogr  = TRUE;
+	  filename = "OGR";
+	  G_remove("", "PG");
+      }
+      else {
+	  use_ogr  = FALSE;
+	  filename = "PG";
+	  G_remove("", "OGR");
+	  
+      }
+#else
+#ifdef HAVE_POSTGRES
+      if (getenv("GRASS_VECTOR_OGR"))
+	  G_warning(_("Environment variable GRASS_VECTOR_OGR defined, "
+		      "but GRASS is compiled with OGR support. "
+		      "Using GRASS-PostGIS data driver instead."));
+      use_ogr  = FALSE;
+      filename = "PG";
+      G_remove("", "OGR");
+#else /* -> force using OGR */
+      G_warning(_("GRASS is not compiled with PostgreSQL support. "
+		  "Using OGR-PostgreSQL driver instead of native "
+		  "GRASS-PostGIS data driver."));
+      use_ogr  = TRUE;
+      filename = "OGR";
+      G_remove("", "PG");
+#endif /* HAVE_POSTRESQL */
+	
+#endif /* HAVE_OGR && HAVE_POSTGRES */
+    } /* format=PostgreSQL */
     else {
 	use_ogr  = TRUE;
 	filename = "OGR";

Modified: grass/trunk/vector/v.external.out/list.c
===================================================================
--- grass/trunk/vector/v.external.out/list.c	2012-03-26 12:21:10 UTC (rev 51160)
+++ grass/trunk/vector/v.external.out/list.c	2012-03-26 13:55:38 UTC (rev 51161)
@@ -51,10 +51,10 @@
 
     qsort(list, count, sizeof(char *), cmp);
 #endif
-#ifdef HAVE_POSTGRES
+#if defined HAVE_POSTGRES && !defined HAVE_OGR
     list = G_realloc(list, (count + 1) * sizeof(char *));
-    list[count++] = G_store("PostGIS");
-    len += strlen("PostGIS") + 1;
+    list[count++] = G_store("PostgreSQL");
+    len += strlen("PostgreSQL") + 1;
 #endif 
     if (len > 0) {
 	ret = G_malloc((len + 1) * sizeof(char)); /* \0 */

Modified: grass/trunk/vector/v.external.out/main.c
===================================================================
--- grass/trunk/vector/v.external.out/main.c	2012-03-26 12:21:10 UTC (rev 51160)
+++ grass/trunk/vector/v.external.out/main.c	2012-03-26 13:55:38 UTC (rev 51161)
@@ -16,6 +16,7 @@
  **************************************************************/
 
 #include <stdlib.h>
+#include <string.h>
 
 #include <grass/gis.h>
 #include <grass/vector.h>
@@ -33,6 +34,8 @@
     struct _options options;
     struct _flags   flags;
 
+    char * format;
+    
     G_gisinit(argv[0]);
 
     module = G_define_module();
@@ -60,14 +63,17 @@
 	exit(EXIT_SUCCESS);
     }
 
-    if (options.format->answer)
-	check_format(options.format->answer);
-
+    format = NULL;
+    if (options.format->answer) {
+	format = G_store(options.format->answer);
+	check_format(format);
+    }
+    
     if (options.dsn->answer) {
 	char *dsn;
 	
 	/* be friendly, ignored 'PG:' prefix for PostGIS format */
-	if (strcmp(options.format->answer, "PostGIS") == 0 &&
+	if (strcmp(format, "PostGIS") == 0 &&
 	    G_strncasecmp(options.dsn->answer, "PG:", 3) == 0) {
 	    int i, length;
 	    
@@ -81,7 +87,7 @@
 	    dsn = G_store(options.dsn->answer);
 	}
     
-	make_link(dsn, options.format->answer,
+	make_link(dsn, format,
 		  options.opts->answer, options.opts->answers);
     }
     

Modified: grass/trunk/vector/v.external.out/v.external.out.html
===================================================================
--- grass/trunk/vector/v.external.out/v.external.out.html	2012-03-26 12:21:10 UTC (rev 51160)
+++ grass/trunk/vector/v.external.out/v.external.out.html	2012-03-26 13:55:38 UTC (rev 51161)
@@ -1,18 +1,22 @@
 <h2>DESCRIPTION</h2>
 
-<em>v.external.out</em> instructs GRASS to write vector maps as data
-files (e.g. ESRI Shapefile) using OGR library.
+<em>v.external.out</em> instructs GRASS to write vector maps in
+external data format (e.g. ESRI Shapefile) using <b>OGR
+library</b>. PostGIS data can be also written by native <b>GRASS-PostGIS
+data driver</b>.
 
-<h2>EXAMPLE</h2>
+<h2>EXAMPLES</h2>
 
-The module <em>v.external.out</em> can be used along with
+<h3>ESRI Shapefile</h3>
+
+<em>v.external.out</em> can be used along with
 <em><a href="v.external.html">v.external</a></em> to process external
-geodata in GRASS while writing out the results directly in ESRI
+geodata in GRASS while writing out the results directly eg. in ESRI
 Shapefile format:
 
 <div class="code"><pre>
-# register Shapefile in GRASS database:
-v.external dsn=cities.shp output=cities
+# register Shapefile in GRASS mapset:
+v.external dsn=/path/to/shapefiles layer=cities
 
 # define output directory for GRASS calculation results:
 v.external.out dsn=$HOME/gisoutput
@@ -21,6 +25,43 @@
 v.select ainput=cities atype=point binput=forests btype=area operator=within output=fcities
 </pre></div>
 
+Current settings can be printed using <tt>-p</tt> or <tt>-g</tt> flag.
+
+<div class="code"><pre>
+v.external.out -p
+
+dsn: /path/to/home/gisoutput
+format: ESRI Shapefile
+</pre></div>
+
+<h3>PostGIS</h3>
+
+PostGIS data can be accessed directly using <em>GRASS-PostGIS data
+driver</em> (it requires that GRASS is compiled with PostgreSQL
+support).
+
+<div class="code"><pre>
+# register PostGIS table in GRASS mapset:
+v.external dsn=PG:dbname=gisdb layer=cities
+
+# define output directory for GRASS calculation results:
+v.external.out dsn=PG:dbname=gisdb format=PostgreSQL
+
+# do some processing...
+</pre></div>
+
+<i>Note:</i> If the environment variable <tt>GRASS_VECTOR_OGR</tt> exists, or
+GRASS is compiled without PostgreSQL support then GRASS will use
+OGR-PostgreSQL driver for reading and writing PostGIS data.
+
+<h3>GRASS native format</h3>
+
+To restore original settings, ie. use GRASS native format, type:
+
+<div class="code"><pre>
+v.external.out -r
+</pre></div>
+
 <h2>SEE ALSO</h2>
 
 <em>
@@ -31,10 +72,18 @@
 
 <h2>REFERENCES</h2>
 
-OGR Library website: <a href="http://gdal.osgeo.org/ogr">http://gdal.osgeo.org/ogr</a>
+<a href="http://www.gdal.org/ogr/">OGR vector library</a>
+<br>
+<a href="http://www.gdal.org/ogr/ogr__api_8h.html">OGR vector library C API</a>
+documentation
 
+<p>
+See
+also GRASS <a href="http://grass.osgeo.org/wiki/Working_with_external_data_in_GRASS_7">user wiki page</a> for more examples.
+
 <h2>AUTHOR</h2>
 
-Martin Landa, CTU in Prague, Czech Republic (based on r.external.out code)
+Martin Landa, Czech Technical University in Prague, Czech Republic
 
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>



More information about the grass-commit mailing list