From db9588143bfe4f4971d2ef90ae5366876f8405dc Mon Sep 17 00:00:00 2001
From: Guillaume Pasero <guillaume.pasero@c-s.fr>
Date: Mon, 21 Jan 2019 15:36:58 +0100
Subject: [PATCH] ENH: use Start/Commit Transaction for faster OGR output

---
 .../Sampling/src/otbSampleAugmentationFilter.cxx     | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Modules/Learning/Sampling/src/otbSampleAugmentationFilter.cxx b/Modules/Learning/Sampling/src/otbSampleAugmentationFilter.cxx
index 5778de0d93..46e37ebe31 100644
--- a/Modules/Learning/Sampling/src/otbSampleAugmentationFilter.cxx
+++ b/Modules/Learning/Sampling/src/otbSampleAugmentationFilter.cxx
@@ -204,6 +204,13 @@ SampleAugmentationFilter
 
   auto featureCount = outputLayer.GetFeatureCount(false);
   auto templateFeature = this->SelectTemplateFeature(inputLayer, classField, label);
+
+  OGRErr err = outputLayer.ogr().StartTransaction();
+  if (err != OGRERR_NONE)
+    {
+    itkExceptionMacro(<< "Unable to start transaction for OGR layer " << outputLayer.ogr().GetName() << ".");
+    }
+
   for(const auto& sample : samples)
     {
     ogr::Feature dstFeature(outputLayer.GetLayerDefn());
@@ -220,6 +227,11 @@ SampleAugmentationFilter
       }
     outputLayer.CreateFeature( dstFeature );
     }
+  err = outputLayer.ogr().CommitTransaction();
+  if (err != OGRERR_NONE)
+    {
+    itkExceptionMacro(<< "Unable to commit transaction for OGR layer " << outputLayer.ogr().GetName() << ".");
+    }
 }
 
 std::set<size_t> 
-- 
GitLab