[GRASS-SVN] r55408 - grass/trunk/lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 17 06:41:23 PDT 2013


Author: martinl
Date: 2013-03-17 06:41:22 -0700 (Sun, 17 Mar 2013)
New Revision: 55408

Modified:
   grass/trunk/lib/vector/Vlib/close.c
   grass/trunk/lib/vector/Vlib/copy.c
   grass/trunk/lib/vector/Vlib/open.c
   grass/trunk/lib/vector/Vlib/read_nat.c
Log:
vlib: use temporary maps for OGR output by default
      
      if GRASS_VECTOR_OGR_DIRECT exists, then the features are written to
      output OGR layer directly


Modified: grass/trunk/lib/vector/Vlib/close.c
===================================================================
--- grass/trunk/lib/vector/Vlib/close.c	2013-03-17 10:51:40 UTC (rev 55407)
+++ grass/trunk/lib/vector/Vlib/close.c	2013-03-17 13:41:22 UTC (rev 55408)
@@ -79,6 +79,32 @@
     
     G_debug(1, "Vect_close(): name = %s, mapset = %s, format = %d, level = %d, is_tmp = %d",
 	    Map->name, Map->mapset, Map->format, Map->level, Map->temporary);
+
+    if (Map->temporary &&
+        (Map->fInfo.ogr.dsn || Map->fInfo.pg.db_name)) {
+        /* transfer features for external output format */
+        struct Map_info Out;
+        
+        putenv("GRASS_VECTOR_OGR_DIRECT=1");
+        if (-1 == Vect_open_new(&Out, Vect_get_name(Map), Vect_is_3d(Map))) {
+            G_warning(_("Unable to create vector map <%s>"),
+                      Vect_get_name(Map));
+            return 1;
+        }
+
+        Vect_hist_command(&Out);
+            
+        /* TODO: how to determine field ? */
+        if (0 != Vect_copy_map_lines_field(Map, 1, &Out)) {
+            G_warning(_("Saving OGR data failed"));
+            return -1;
+        }
+        
+        Vect_build(&Out);
+        
+        Vect_close(&Out);
+        putenv("GRASS_VECTOR_OGR_DIRECT="); /* unset variable */
+    }
     
     /* check for external formats whether to create a link */
     create_link = TRUE;

Modified: grass/trunk/lib/vector/Vlib/copy.c
===================================================================
--- grass/trunk/lib/vector/Vlib/copy.c	2013-03-17 10:51:40 UTC (rev 55407)
+++ grass/trunk/lib/vector/Vlib/copy.c	2013-03-17 13:41:22 UTC (rev 55408)
@@ -191,9 +191,16 @@
     
     ret = 0;
     nlines = Vect_get_num_lines(In);
-    if (topo == TOPO_NONE)
-        G_message(_("Copying features (%s)..."),
-                      Vect_get_finfo_geometry_type(Out));
+    if (topo == TOPO_NONE) {
+        const char *ftype;
+
+        ftype = Vect_get_finfo_geometry_type(Out);
+        G_debug(2, "feature type: %s", ftype ? ftype : "?");
+        if (!ftype)
+            G_message(_("Copying features..."));
+        else 
+            G_message(_("Copying features (%s)..."), ftype);
+    }
     else
         G_message(_("Copying features..."));    
     
@@ -334,7 +341,7 @@
     struct line_pnts *Points, **IPoints;
     struct line_cats *Cats;
     
-    ogr = Vect_maptype(Out) == GV_FORMAT_OGR_DIRECT;
+    ogr = Vect_maptype(Out) == (GV_FORMAT_OGR || GV_FORMAT_OGR_DIRECT);
     
     IPoints = NULL;
     nisles_alloc = 0;

Modified: grass/trunk/lib/vector/Vlib/open.c
===================================================================
--- grass/trunk/lib/vector/Vlib/open.c	2013-03-17 10:51:40 UTC (rev 55407)
+++ grass/trunk/lib/vector/Vlib/open.c	2013-03-17 13:41:22 UTC (rev 55408)
@@ -1183,8 +1183,14 @@
 /* check for external formats definition */
 int map_format(struct Map_info *Map)
 {
+    int format;
     char *def_file;
     
+    format = GV_FORMAT_NATIVE;
+    /* temporary maps can be stored only in native format */
+    if (Map->temporary)
+        return format;
+    
     if (G_find_file2("", "OGR", G_mapset())) {
         /* OGR */
         FILE *fp;
@@ -1194,7 +1200,17 @@
         struct Format_info_ogr *ogr_info;
         
         G_debug(2, " using OGR format");
-        Map->format = GV_FORMAT_OGR_DIRECT;
+        if (getenv("GRASS_VECTOR_OGR_DIRECT")) {
+            /* vector features are written directly to OGR layer */
+            format = GV_FORMAT_OGR;
+        }
+        else {
+            /* vector features are written to the temporary vector map
+             * in the native format and when closing the map
+             * transfered to output OGR layer */
+            format = GV_FORMAT_NATIVE;
+            Map->temporary = TRUE;
+        }
         fp = G_fopen_old("", "OGR", G_mapset());
         if (!fp) {
             G_fatal_error(_("Unable to open OGR file"));
@@ -1233,7 +1249,7 @@
             struct Format_info_pg *pg_info;
             
             G_debug(2, " using PostGIS format");
-            Map->format = GV_FORMAT_POSTGIS;
+            format = GV_FORMAT_POSTGIS;
             fp = G_fopen_old("", def_file ? def_file : "PG", G_mapset());
             if (!fp) {
                 G_fatal_error(_("Unable to open PG file"));
@@ -1288,8 +1304,8 @@
         }
     }
     
-    G_debug(2, "map_format = %d", Map->format);
-    return Map->format;
+    G_debug(2, "map_format = %d", format);
+    return format;
 }
 
 /*!

Modified: grass/trunk/lib/vector/Vlib/read_nat.c
===================================================================
--- grass/trunk/lib/vector/Vlib/read_nat.c	2013-03-17 10:51:40 UTC (rev 55407)
+++ grass/trunk/lib/vector/Vlib/read_nat.c	2013-03-17 13:41:22 UTC (rev 55408)
@@ -140,7 +140,6 @@
 
     G_debug(3, "V2_read_line_nat(): line = %d", line);
 
-
     Line = Map->plus.Line[line];
 
     if (Line == NULL) {



More information about the grass-commit mailing list