From 1ad221bc381f87a91e151ac6b4cd9055cda6fd51 Mon Sep 17 00:00:00 2001
From: Julien Malik <julien.malik@c-s.fr>
Date: Fri, 22 Jun 2012 18:26:26 +0200
Subject: [PATCH] ENH: change protoype of OGRDataSource::CreateLayer

---
 Applications/Segmentation/otbSegmentation.cxx        |  2 +-
 Code/Common/otbLabelImageToOGRDataSourceFilter.txx   |  2 +-
 Code/Common/otbLabelImageToVectorDataFilter.txx      |  2 +-
 .../OGRAdapters/otbGeometriesToGeometriesFilter.cxx  |  2 +-
 .../OGRAdapters/otbOGRDataSourceWrapper.cxx          | 12 ++++++++++--
 .../OGRAdapters/otbOGRDataSourceWrapper.h            |  2 +-
 .../Segmentation/StreamingMeanShiftSegmentation.cxx  |  2 +-
 7 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/Applications/Segmentation/otbSegmentation.cxx b/Applications/Segmentation/otbSegmentation.cxx
index a1604ada0f..5d3f370869 100644
--- a/Applications/Segmentation/otbSegmentation.cxx
+++ b/Applications/Segmentation/otbSegmentation.cxx
@@ -457,7 +457,7 @@ private:
         // datasource is blank
         layer = ogrDS->CreateLayer(GetParameterString("mode.vector.layername"),
                                    &oSRS,wkbMultiPolygon,
-                                   otb::ogr::StringListConverter(GetParameterStringList("mode.vector.ogroptions")).to_ogr());
+                                   GetParameterStringList("mode.vector.ogroptions"));
         // And create the field
         OGRFieldDefn field(this->GetParameterString("mode.vector.fieldname").c_str(),OFTInteger);
         layer.CreateField(field,true);
diff --git a/Code/Common/otbLabelImageToOGRDataSourceFilter.txx b/Code/Common/otbLabelImageToOGRDataSourceFilter.txx
index eff3b3aa62..ae9659f30e 100644
--- a/Code/Common/otbLabelImageToOGRDataSourceFilter.txx
+++ b/Code/Common/otbLabelImageToOGRDataSourceFilter.txx
@@ -206,7 +206,7 @@ LabelImageToOGRDataSourceFilter<TInputImage>
     //Create the output layer for GDALPolygonize().
     ogr::DataSource::Pointer ogrDS = ogr::DataSource::New();
     
-    OGRLayerType outputLayer = ogrDS->CreateLayer("layer",NULL,wkbPolygon,NULL);
+    OGRLayerType outputLayer = ogrDS->CreateLayer("layer",NULL,wkbPolygon);
     
     OGRFieldDefn field(m_FieldName.c_str(),OFTInteger);
     outputLayer.CreateField(field, true);
diff --git a/Code/Common/otbLabelImageToVectorDataFilter.txx b/Code/Common/otbLabelImageToVectorDataFilter.txx
index 9451cc2087..eb770861cf 100644
--- a/Code/Common/otbLabelImageToVectorDataFilter.txx
+++ b/Code/Common/otbLabelImageToVectorDataFilter.txx
@@ -184,7 +184,7 @@ LabelImageToVectorDataFilter<TInputImage, TPrecision>
     //Create the output layer for GDALPolygonize().
     ogr::DataSource::Pointer ogrDS = ogr::DataSource::New();
     
-    OGRLayerType outputLayer = ogrDS->CreateLayer("layer",NULL,wkbPolygon,NULL);
+    OGRLayerType outputLayer = ogrDS->CreateLayer("layer",NULL,wkbPolygon);
     
     OGRFieldDefn field(m_FieldName.c_str(),OFTInteger);
     outputLayer.CreateField(field, true);
diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.cxx b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.cxx
index da141bb8e3..517a1a7703 100644
--- a/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.cxx
+++ b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.cxx
@@ -59,7 +59,7 @@ struct ProcessVisitor : boost::static_visitor<>
         sourceLayer.GetName(),
         m_filter.DoDefineNewLayerSpatialReference(sourceLayer),
         m_filter.DoDefineNewLayerGeometryType(sourceLayer),
-        otb::ogr::StringListConverter(m_filter.DoDefineNewLayerOptions(sourceLayer)).to_ogr()
+        m_filter.DoDefineNewLayerOptions(sourceLayer)
       );
       m_filter.DoDefineNewLayerFields(sourceLayer, destLayer);
       m_filter.DoProcessLayer(sourceLayer, destLayer);
diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbOGRDataSourceWrapper.cxx b/Code/UtilitiesAdapters/OGRAdapters/otbOGRDataSourceWrapper.cxx
index e20ea7053e..de5f6b99cc 100644
--- a/Code/UtilitiesAdapters/OGRAdapters/otbOGRDataSourceWrapper.cxx
+++ b/Code/UtilitiesAdapters/OGRAdapters/otbOGRDataSourceWrapper.cxx
@@ -345,7 +345,7 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer(
   std::string const& name,
   OGRSpatialReference * poSpatialRef/* = NULL */,
   OGRwkbGeometryType eGType/* = wkbUnknown */,
-  char ** papszOptions/* = NULL */)
+  std::vector<std::string> const& papszOptions/* = NULL */)
 {
   assert(m_DataSource && "Datasource not initialized");
 
@@ -362,8 +362,16 @@ otb::ogr::Layer otb::ogr::DataSource::CreateLayer(
       break;
   }
 
+  // Make a local copy
+  std::vector<std::string> options(papszOptions);
+  if (m_OpenMode == Modes::Update_LayerOverwrite)
+    {
+    options.push_back("OVERWRITE=YES");
+    }
+  char** papszOptionsChar = otb::ogr::StringListConverter(options).to_ogr();
+
   OGRLayer * ol = m_DataSource->CreateLayer(
-    name.c_str(), poSpatialRef, eGType, papszOptions);
+    name.c_str(), poSpatialRef, eGType, papszOptionsChar);
   if (!ol)
     {
     itkGenericExceptionMacro(<< "Failed to create the layer <"<<name
diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbOGRDataSourceWrapper.h b/Code/UtilitiesAdapters/OGRAdapters/otbOGRDataSourceWrapper.h
index ca8b120a05..832348cf47 100644
--- a/Code/UtilitiesAdapters/OGRAdapters/otbOGRDataSourceWrapper.h
+++ b/Code/UtilitiesAdapters/OGRAdapters/otbOGRDataSourceWrapper.h
@@ -311,7 +311,7 @@ public:
     std::string        const& name,
     OGRSpatialReference     * poSpatialRef = NULL,
     OGRwkbGeometryType        eGType = wkbUnknown,
-    char                   ** papszOptions = NULL);
+    std::vector<std::string> const& papszOptions = std::vector<std::string>());
 
   /**
    * Deletes the i-th layer from the data source.
diff --git a/Examples/Segmentation/StreamingMeanShiftSegmentation.cxx b/Examples/Segmentation/StreamingMeanShiftSegmentation.cxx
index db2b6343f8..d7e8433b57 100644
--- a/Examples/Segmentation/StreamingMeanShiftSegmentation.cxx
+++ b/Examples/Segmentation/StreamingMeanShiftSegmentation.cxx
@@ -158,7 +158,7 @@ int main(int argc, char *argv[])
   // Software Guide : EndLatex
 
   // Software Guide : BeginCodeSnippet
-  otb::ogr::Layer ogrLayer = ogrDS->CreateLayer(layerName,&oSRS,wkbMultiPolygon,NULL);
+  otb::ogr::Layer ogrLayer = ogrDS->CreateLayer(layerName,&oSRS,wkbMultiPolygon);
   // Software Guide : EndCodeSnippet
   
   // Software Guide : BeginLatex
-- 
GitLab