[GRASS-SVN] r72693 - grass/trunk/vector/v.out.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 7 05:35:47 PDT 2018


Author: mmetz
Date: 2018-05-07 05:35:46 -0700 (Mon, 07 May 2018)
New Revision: 72693

Modified:
   grass/trunk/vector/v.out.ogr/export_areas.c
   grass/trunk/vector/v.out.ogr/export_lines.c
Log:
v.out.ogr: create and write a new feature only once to avoid duplicate fid's, check return of OGR_L_CreateFeature()

Modified: grass/trunk/vector/v.out.ogr/export_areas.c
===================================================================
--- grass/trunk/vector/v.out.ogr/export_areas.c	2018-05-07 00:13:13 UTC (rev 72692)
+++ grass/trunk/vector/v.out.ogr/export_areas.c	2018-05-07 12:35:46 UTC (rev 72693)
@@ -101,9 +101,6 @@
         /* create polygon from area */
         Ogr_geometry = create_polygon(In, area, Points, outer_ring_ccw);
 
-        /* add feature */
-        Ogr_feature = OGR_F_Create(Ogr_featuredefn);
-        OGR_F_SetGeometry(Ogr_feature, Ogr_geometry);
         
         /* output one feature for each category */
         for (i = -1; i < Cats->n_cats; i++) {
@@ -119,14 +116,21 @@
                     continue;
             }
             
+	    /* add feature */
+	    Ogr_feature = OGR_F_Create(Ogr_featuredefn);
+	    OGR_F_SetGeometry(Ogr_feature, Ogr_geometry);
+
             mk_att(cat, Fi, driver, ncol, colctype, colname, doatt, nocat,
                    Ogr_feature, n_noatt);
-            OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
-            
-            n_exported++;
+            if (OGR_L_CreateFeature(Ogr_layer, Ogr_feature) != OGRERR_NONE ) {
+		G_warning(_("Failed to create OGR feature"));
+	    }
+	    else
+		n_exported++;
+
+	    OGR_F_Destroy(Ogr_feature);
         }
         OGR_G_DestroyGeometry(Ogr_geometry);
-        OGR_F_Destroy(Ogr_feature);
     }
 
     Vect_destroy_line_struct(Points);
@@ -219,11 +223,13 @@
             
             mk_att(cat, Fi, driver, ncol, colctype, colname, doatt, nocat,
                    Ogr_feature, n_noatt);
-            OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
+            if (OGR_L_CreateFeature(Ogr_layer, Ogr_feature) != OGRERR_NONE ) {
+		G_warning(_("Failed to create OGR feature"));
+	    }
+	    else
+		n_exported++;
 
             OGR_F_Destroy(Ogr_feature);
-
-            n_exported++;
         }
         else {
             /* skip empty features */
@@ -268,11 +274,13 @@
         
         mk_att(cat, Fi, driver, ncol, colctype, colname, doatt, nocat,
                Ogr_feature, n_noatt);
-        OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
+	if (OGR_L_CreateFeature(Ogr_layer, Ogr_feature) != OGRERR_NONE ) {
+	    G_warning(_("Failed to create OGR feature"));
+	}
+	else
+	    n_exported++;
 
         OGR_F_Destroy(Ogr_feature);
-        
-        n_exported++;
     }
     else {
         /* skip empty features */

Modified: grass/trunk/vector/v.out.ogr/export_lines.c
===================================================================
--- grass/trunk/vector/v.out.ogr/export_lines.c	2018-05-07 00:13:13 UTC (rev 72692)
+++ grass/trunk/vector/v.out.ogr/export_lines.c	2018-05-07 12:35:46 UTC (rev 72693)
@@ -110,11 +110,7 @@
                 }
             }
         }
-        
-        /* create feature & set geometry */
-        Ogr_feature = OGR_F_Create(Ogr_featuredefn);
-        OGR_F_SetGeometry(Ogr_feature, Ogr_geometry);
-        
+
         /* output one feature for each category, export also features
          * without category (cat = -1) */
         for (j = -1; j < Cats->n_cats; j++) {
@@ -130,14 +126,20 @@
                     continue;
             }
             
+	    /* add feature */
+	    Ogr_feature = OGR_F_Create(Ogr_featuredefn);
+	    OGR_F_SetGeometry(Ogr_feature, Ogr_geometry);
             mk_att(cat, Fi, driver, ncol, colctype, colname, doatt, nocat,
                    Ogr_feature, n_noatt);
-            OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
+            if (OGR_L_CreateFeature(Ogr_layer, Ogr_feature) != OGRERR_NONE ) {
+		G_warning(_("Failed to create OGR feature"));
+	    }
+	    else
+		n_exported++;
+
+	    OGR_F_Destroy(Ogr_feature);
         }
         OGR_G_DestroyGeometry(Ogr_geometry);
-        OGR_F_Destroy(Ogr_feature);
-
-        n_exported++;
     }
 
     Vect_destroy_line_struct(Points);
@@ -225,11 +227,13 @@
             
             mk_att(cat, Fi, driver, ncol, colctype, colname, doatt, nocat,
                    Ogr_feature, n_noatt);
-            OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
+            if (OGR_L_CreateFeature(Ogr_layer, Ogr_feature) != OGRERR_NONE ) {
+		G_warning(_("Failed to create OGR feature"));
+	    }
+	    else
+		n_exported++;
 
             OGR_F_Destroy(Ogr_feature);
-
-            n_exported++;
         }
         else {
             /* skip empty features */
@@ -272,11 +276,13 @@
         
         mk_att(cat, Fi, driver, ncol, colctype, colname, doatt, nocat,
                Ogr_feature, n_noatt);
-        OGR_L_CreateFeature(Ogr_layer, Ogr_feature);
-        
+	if (OGR_L_CreateFeature(Ogr_layer, Ogr_feature) != OGRERR_NONE ) {
+	    G_warning(_("Failed to create OGR feature"));
+	}
+	else
+	    n_exported++;
+
         OGR_F_Destroy(Ogr_feature);
-
-        n_exported++;
     }
     else {
         /* skip empty features */



More information about the grass-commit mailing list