diff --git a/Applications/Segmentation/otbSegmentation.cxx b/Applications/Segmentation/otbSegmentation.cxx index a1604ada0feb5f6d6bc1ab5734247335b544ed4d..f41aea7a45951a0503ca62521c003394278e76ed 100644 --- a/Applications/Segmentation/otbSegmentation.cxx +++ b/Applications/Segmentation/otbSegmentation.cxx @@ -451,13 +451,13 @@ private: if(GetParameterString("mode.vector.outmode") == "ovw") { // Create the datasource - ogrDS = otb::ogr::DataSource::New(dataSourceName, otb::ogr::DataSource::Modes::Update_LayerOverwrite); + ogrDS = otb::ogr::DataSource::New(dataSourceName, otb::ogr::DataSource::Modes::Overwrite); // and create the layer since we are in overwrite mode, the // 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 eff3b3aa62a004360370c01dfc058cba0e4123bf..ae9659f30e64a39b54407d67caad70640b883948 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 9451cc2087f258c4200eb9dec8642c43529b45c9..eb770861cfdb4eb2f26351aafe01ffe4c121ed73 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/Common/otbPersistentImageToOGRDataFilter.txx b/Code/Common/otbPersistentImageToOGRDataFilter.txx index 9c19d6ec65a1574404966876aaad778456a6ae34..e00b887a3879c94ecc1bc1be89edab1a58a3a806 100644 --- a/Code/Common/otbPersistentImageToOGRDataFilter.txx +++ b/Code/Common/otbPersistentImageToOGRDataFilter.txx @@ -129,7 +129,7 @@ PersistentImageToOGRDataFilter<TImage> OGRDataSourcePointerType ogrDS = this->GetOGRDataSource(); - ogrDS->CreateLayer(m_LayerName, oSRS ,m_GeometryType, otb::ogr::StringListConverter(m_OGRLayerCreationOptions).to_ogr()); + ogrDS->CreateLayer(m_LayerName, oSRS ,m_GeometryType, m_OGRLayerCreationOptions); OGRFieldDefn field(m_FieldName.c_str(),OFTInteger); //Handle the case of shapefile. A shapefile is a layer and not a datasource. diff --git a/Code/Segmentation/otbOGRLayerStreamStitchingFilter.txx b/Code/Segmentation/otbOGRLayerStreamStitchingFilter.txx index 69726cb3d8e36da969e818a817a7aafdfded5408..f0615572e92099b88cc27ffe704a390fa782f7a7 100644 --- a/Code/Segmentation/otbOGRLayerStreamStitchingFilter.txx +++ b/Code/Segmentation/otbOGRLayerStreamStitchingFilter.txx @@ -31,7 +31,7 @@ namespace otb template<class TImage> OGRLayerStreamStitchingFilter<TImage> -::OGRLayerStreamStitchingFilter() : m_Radius(2), m_OGRLayer(NULL) +::OGRLayerStreamStitchingFilter() : m_Radius(2), m_OGRLayer(NULL, false) { m_StreamSize.Fill(0); } diff --git a/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.cxx b/Code/UtilitiesAdapters/OGRAdapters/otbGeometriesToGeometriesFilter.cxx index b3f7d35f6462947726f35c92fbde184c4efa6214..7b274240dc12fb40c75456d525a18c561806fce7 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 e20ea7053ed4d33258c60f6dd09b0be40dac17c3..de5f6b99cc5a678ab67bb5c21a334bff129388e9 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 ca8b120a051fc5f6d8e01dbec422ea96c33ab781..832348cf47c2307a54abe3e73f3bbe1b34edc071 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/Code/UtilitiesAdapters/OGRAdapters/otbOGRHelpers.h b/Code/UtilitiesAdapters/OGRAdapters/otbOGRHelpers.h index ab86b5df4d305f7d21cec9769e5213ef838ab92a..26416ecd3b97b6e36aa4af6bd5123fea47bbeb8e 100644 --- a/Code/UtilitiesAdapters/OGRAdapters/otbOGRHelpers.h +++ b/Code/UtilitiesAdapters/OGRAdapters/otbOGRHelpers.h @@ -82,7 +82,9 @@ struct StringListConverter */ char ** to_ogr() const { - return const_cast <char**>(&m_raw[0]); + return m_raw.size() == 1 + ? NULL + : const_cast <char**>(&m_raw[0]); } private: std::vector<char const*> m_raw; diff --git a/Examples/Segmentation/StreamingMeanShiftSegmentation.cxx b/Examples/Segmentation/StreamingMeanShiftSegmentation.cxx index db2b6343f8e974d9081ef6a221b2c190940ca863..d7e8433b5719f2d91dc80c017bf5849e114a588e 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 diff --git a/Testing/Code/Projections/otbGeometriesProjectionFilterFromGeoToMap.cxx b/Testing/Code/Projections/otbGeometriesProjectionFilterFromGeoToMap.cxx index 0e3d8bc63a6325b855a49e9a3e6ef38725146923..ab13aa40c06a5d1441ac9701ecc9f1ff055b028b 100644 --- a/Testing/Code/Projections/otbGeometriesProjectionFilterFromGeoToMap.cxx +++ b/Testing/Code/Projections/otbGeometriesProjectionFilterFromGeoToMap.cxx @@ -40,7 +40,7 @@ int otbGeometriesProjectionFilterFromGeoToMap(int argc, char * argv[]) typedef otb::GeometriesSet InputGeometriesType; typedef otb::GeometriesSet OutputGeometriesType; otb::ogr::DataSource::Pointer input = otb::ogr::DataSource::New( - argv[1], otb::ogr::DataSource::Modes::read); + argv[1], otb::ogr::DataSource::Modes::Read); InputGeometriesType::Pointer in_set = InputGeometriesType::New(input); // Input Keywordlist (from image) @@ -52,7 +52,7 @@ int otbGeometriesProjectionFilterFromGeoToMap(int argc, char * argv[]) // Output Geometries Set otb::ogr::DataSource::Pointer output = otb::ogr::DataSource::New( - argv[3], otb::ogr::DataSource::Modes::write); + argv[3], otb::ogr::DataSource::Modes::Overwrite); OutputGeometriesType::Pointer out_set = OutputGeometriesType::New(output); // Filter diff --git a/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToGeo.cxx b/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToGeo.cxx index 91c927db4f93d28dffcbf843d0ebd3d6d223e103..a25c45224bdf7de7bb6100599876955a73ad77a1 100644 --- a/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToGeo.cxx +++ b/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToGeo.cxx @@ -39,12 +39,12 @@ int otbGeometriesProjectionFilterFromMapToGeo(int argc, char **argv) typedef otb::GeometriesSet InputGeometriesType; typedef otb::GeometriesSet OutputGeometriesType; otb::ogr::DataSource::Pointer input = otb::ogr::DataSource::New( - argv[1], otb::ogr::DataSource::Modes::read); + argv[1], otb::ogr::DataSource::Modes::Read); InputGeometriesType::Pointer in_set = InputGeometriesType::New(input); // Output Geometries Set otb::ogr::DataSource::Pointer output = otb::ogr::DataSource::New( - argv[2], otb::ogr::DataSource::Modes::write); + argv[2], otb::ogr::DataSource::Modes::Overwrite); OutputGeometriesType::Pointer out_set = OutputGeometriesType::New(output); // Filter diff --git a/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToImage.cxx b/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToImage.cxx index d7814d6275d1bdabd266ab096c56f71dd41d3901..61b3cd4079b7a6dd8fd51a9463cc3d820fb2245f 100644 --- a/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToImage.cxx +++ b/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToImage.cxx @@ -40,7 +40,7 @@ int otbGeometriesProjectionFilterFromMapToImage(int argc, char * argv[]) typedef otb::GeometriesSet InputGeometriesType; typedef otb::GeometriesSet OutputGeometriesType; otb::ogr::DataSource::Pointer input = otb::ogr::DataSource::New( - argv[1], otb::ogr::DataSource::Modes::read); + argv[1], otb::ogr::DataSource::Modes::Read); InputGeometriesType::Pointer in_set = InputGeometriesType::New(input); // Input Keywordlist (from image) @@ -52,7 +52,7 @@ int otbGeometriesProjectionFilterFromMapToImage(int argc, char * argv[]) // Output Geometries Set otb::ogr::DataSource::Pointer output = otb::ogr::DataSource::New( - argv[3], otb::ogr::DataSource::Modes::write); + argv[3], otb::ogr::DataSource::Modes::Overwrite); OutputGeometriesType::Pointer out_set = OutputGeometriesType::New(output); // Filter diff --git a/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToSensor.cxx b/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToSensor.cxx index ff578f526cfc21aed17161cdf54cf3bb3f3a43e2..5a3edd847aafe3fc532c072dfd0361ee253f0b24 100644 --- a/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToSensor.cxx +++ b/Testing/Code/Projections/otbGeometriesProjectionFilterFromMapToSensor.cxx @@ -40,7 +40,7 @@ int otbGeometriesProjectionFilterFromMapToSensor(int argc, char * argv[]) typedef otb::GeometriesSet InputGeometriesType; typedef otb::GeometriesSet OutputGeometriesType; otb::ogr::DataSource::Pointer input = otb::ogr::DataSource::New( - argv[1], otb::ogr::DataSource::Modes::read); + argv[1], otb::ogr::DataSource::Modes::Read); InputGeometriesType::Pointer in_set = InputGeometriesType::New(input); // Input Keywordlist (from image) @@ -52,7 +52,7 @@ int otbGeometriesProjectionFilterFromMapToSensor(int argc, char * argv[]) // Output Geometries Set otb::ogr::DataSource::Pointer output = otb::ogr::DataSource::New( - argv[3], otb::ogr::DataSource::Modes::write); + argv[3], otb::ogr::DataSource::Modes::Overwrite); OutputGeometriesType::Pointer out_set = OutputGeometriesType::New(output); // Filter diff --git a/Testing/Code/Segmentation/otbStreamingImageToOGRLayerSegmentationFilter.cxx b/Testing/Code/Segmentation/otbStreamingImageToOGRLayerSegmentationFilter.cxx index dc8f40d2c273808699c44c1d2be79b6fb34cc087..f0325bbb5c651edf007868645763b731d3716390 100644 --- a/Testing/Code/Segmentation/otbStreamingImageToOGRLayerSegmentationFilter.cxx +++ b/Testing/Code/Segmentation/otbStreamingImageToOGRLayerSegmentationFilter.cxx @@ -103,7 +103,7 @@ int otbStreamingImageToOGRLayerSegmentationFilter(int argc, char * argv[]) OGRSpatialReference oSRS(reader->GetOutput()->GetProjectionRef().c_str()); // Create the layer - otb::ogr::Layer oLayer = ogrDS->CreateLayer(layerName,&oSRS,wkbMultiPolygon,NULL); + otb::ogr::Layer oLayer = ogrDS->CreateLayer(layerName,&oSRS,wkbMultiPolygon); // Create the field OGRFieldDefn field(fieldName.c_str(),OFTInteger);