[GRASS-SVN] r72695 - grass/branches/releasebranch_7_2/vector/v.out.ogr

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 7 05:50:22 PDT 2018


Author: mmetz
Date: 2018-05-07 05:50:22 -0700 (Mon, 07 May 2018)
New Revision: 72695

Modified:
   grass/branches/releasebranch_7_2/vector/v.out.ogr/export_areas.c
   grass/branches/releasebranch_7_2/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() (backport trunk r72693)

Modified: grass/branches/releasebranch_7_2/vector/v.out.ogr/export_areas.c
===================================================================
--- grass/branches/releasebranch_7_2/vector/v.out.ogr/export_areas.c	2018-05-07 12:40:16 UTC (rev 72694)
+++ grass/branches/releasebranch_7_2/vector/v.out.ogr/export_areas.c	2018-05-07 12:50:22 UTC (rev 72695)
@@ -78,9 +78,6 @@
         /* create polygon from area */
         Ogr_geometry = create_polygon(In, area, Points);
 
-        /* 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++) {
@@ -96,14 +93,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);
@@ -196,11 +200,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 */
@@ -245,11 +251,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/branches/releasebranch_7_2/vector/v.out.ogr/export_lines.c
===================================================================
--- grass/branches/releasebranch_7_2/vector/v.out.ogr/export_lines.c	2018-05-07 12:40:16 UTC (rev 72694)
+++ grass/branches/releasebranch_7_2/vector/v.out.ogr/export_lines.c	2018-05-07 12:50:22 UTC (rev 72695)
@@ -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