[GRASS-SVN] r56374 - in grass/trunk: lib/vector/Vlib vector/v.out.postgis

svn_grass at osgeo.org svn_grass at osgeo.org
Thu May 23 03:23:56 PDT 2013


Author: martinl
Date: 2013-05-23 03:23:56 -0700 (Thu, 23 May 2013)
New Revision: 56374

Modified:
   grass/trunk/lib/vector/Vlib/build_pg.c
   grass/trunk/lib/vector/Vlib/copy.c
   grass/trunk/vector/v.out.postgis/main.c
Log:
v.out.postgis: avoid segfault when no features exported
               print warning about number of skipped features


Modified: grass/trunk/lib/vector/Vlib/build_pg.c
===================================================================
--- grass/trunk/lib/vector/Vlib/build_pg.c	2013-05-23 10:05:43 UTC (rev 56373)
+++ grass/trunk/lib/vector/Vlib/build_pg.c	2013-05-23 10:23:56 UTC (rev 56374)
@@ -63,6 +63,9 @@
         return 0;
     pg_info->inTransaction = FALSE;
     
+    if (pg_info->feature_type == SF_UNKNOWN)
+        return 1;
+    
     if (build == plus->built)
         return 1;            /* do nothing */
 

Modified: grass/trunk/lib/vector/Vlib/copy.c
===================================================================
--- grass/trunk/lib/vector/Vlib/copy.c	2013-05-23 10:05:43 UTC (rev 56373)
+++ grass/trunk/lib/vector/Vlib/copy.c	2013-05-23 10:23:56 UTC (rev 56374)
@@ -199,7 +199,7 @@
 */
 int copy_lines_2(struct Map_info *In, int field, int topo, struct Map_info *Out)
 {
-    int i, type, nlines;
+  int i, type, nlines, nskipped;
     int ret, left, rite, centroid;
 
     struct line_pnts *Points, *CPoints;
@@ -225,6 +225,7 @@
     else
         G_message(_("Copying features..."));    
     
+    nskipped = 0;
     for (i = 1; i <= nlines; i++) {
         if (!Vect_line_alive(In, i))
             continue;
@@ -281,8 +282,10 @@
                         continue;
                 }
             }
-            else if (Vect_cat_get(Cats, field, NULL) == 0)
+            else if (Vect_cat_get(Cats, field, NULL) == 0) {
+                nskipped++;
                 continue;   /* different layer */
+            }
         }
         
         if (-1 == Vect_write_line(Out, type, Points, Cats)) {
@@ -291,6 +294,9 @@
         }
     }
 
+    if (nskipped > 0)
+        G_warning(_("%d features without category or from different layer skipped"), nskipped);
+    
     Vect_destroy_line_struct(Points);
     Vect_destroy_line_struct(CPoints);
     Vect_destroy_cats_struct(Cats);

Modified: grass/trunk/vector/v.out.postgis/main.c
===================================================================
--- grass/trunk/vector/v.out.postgis/main.c	2013-05-23 10:05:43 UTC (rev 56373)
+++ grass/trunk/vector/v.out.postgis/main.c	2013-05-23 10:23:56 UTC (rev 56374)
@@ -141,12 +141,16 @@
 
     /* close input map */
     Vect_close(&In);
-    
+
     /* build topology for output map */
     if (Vect_build(&Out) != 1)
         G_fatal_error(_("Building %s topology failed"),
                       flags.topo->answer ? "PostGIS" : "pseudo");
 
+    if (Vect_get_num_lines(&Out) < 1)
+        G_fatal_error(_("No features exported. PostGIS layer <%s> not created."),
+                      Vect_get_name(&Out));
+
     G_done_msg(_("%d features (%s) written to <%s>."),
                Vect_get_num_lines(&Out), Vect_get_finfo_geometry_type(&Out),
                Vect_get_name(&Out));
@@ -194,6 +198,6 @@
         if (!result || PQresultStatus(result) != PGRES_TUPLES_OK) {
             G_warning(_("Unable to drop topology schema <%s>"), pg_info->toposchema_name);
         }
+        PQclear(result);
     }
-    PQclear(result);
 }



More information about the grass-commit mailing list