From 3921bdcdd0aff1c092885949f31b0f7684e9a6ba Mon Sep 17 00:00:00 2001
From: Julien Malik <julien.malik@c-s.fr>
Date: Sun, 9 Oct 2011 11:01:43 +0200
Subject: [PATCH] ENH: automatically close the GDAL dataset when the last pixel
 is written

---
 Code/IO/otbGDALImageIO.cxx | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Code/IO/otbGDALImageIO.cxx b/Code/IO/otbGDALImageIO.cxx
index c1d77c81b2..fbd6768cfa 100644
--- a/Code/IO/otbGDALImageIO.cxx
+++ b/Code/IO/otbGDALImageIO.cxx
@@ -1235,6 +1235,15 @@ void GDALImageIO::Write(const void* buffer)
                                                  option, NULL, NULL );
     GDALClose(hOutputDS);
     }
+
+
+  if (lFirstLine + lNbLines == m_Dimensions[1]
+      && lFirstColumn + lNbColumns == m_Dimensions[0])
+    {
+    // Last pixel written
+    // Reinitialize to close the file
+    m_Dataset = GDALDatasetWrapperPointer();
+    }
 }
 
 /** TODO : Methode WriteImageInformation non implementee */
-- 
GitLab