diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h b/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h index bf6d799fd52d88e66a4164d1c50d02aae58e84a7..1af4c225585047b58f222d03f50b679d40d5f089 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h +++ b/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h @@ -46,6 +46,7 @@ #include "otbOGRLayerWrapper.h" #include "otbOGRVersionProxy.h" +#include "otbOGRExtendedFilenameToOptions.h" class OGRLayer; class OGRSpatialReference; @@ -88,6 +89,7 @@ public: typedef itk::SmartPointer<const Self> ConstPointer; //@} + typedef OGRExtendedFilenameToOptions FileNameHelperType; /**\name Standard macros */ //@{ /** Default builder. @@ -549,6 +551,7 @@ private: private: ogr::version_proxy::GDALDatasetType *m_DataSource; + FileNameHelperType::Pointer m_FileNameHelper; Modes::type m_OpenMode; int m_FirstModifiableLayerID; }; // end class DataSource diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToReaderOptions.h b/Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToOptions.h similarity index 53% rename from Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToReaderOptions.h rename to Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToOptions.h index 4aa7b78b315f807717e13c9de0acd0fbd298a049..1d1983eec13c8f2961f5524630e9304295e371b1 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToReaderOptions.h +++ b/Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToOptions.h @@ -18,8 +18,8 @@ * limitations under the License. */ -#ifndef otbOGRExtendedFilenameToReaderOptions_h -#define otbOGRExtendedFilenameToReaderOptions_h +#ifndef otbOGRExtendedFilenameToOptions_h +#define otbOGRExtendedFilenameToOptions_h #include <set> #include "otbExtendedFilenameHelper.h" @@ -27,14 +27,14 @@ namespace otb { -/** \class OGRExtendedFilenameToReaderOptions +/** \class OGRExtendedFilenameToOptions */ -class ITK_EXPORT OGRExtendedFilenameToReaderOptions : public ExtendedFilenameHelper +class ITK_EXPORT OGRExtendedFilenameToOptions : public ExtendedFilenameHelper { public: /** Standard class typedefs. */ - typedef OGRExtendedFilenameToReaderOptions Self; + typedef OGRExtendedFilenameToOptions Self; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; typedef ExtendedFilenameHelper Superclass; @@ -42,31 +42,48 @@ public: typedef Superclass::OptionMapType OptionMapType; typedef OptionMapType::iterator MapIteratorType; - itkTypeMacro(OGRExtendedFilenameToReaderOptions, otb::ExtendedFilenameHelper); + itkTypeMacro(OGRExtendedFilenameToOptions, otb::ExtendedFilenameHelper); itkNewMacro(Self); + typedef std::vector<std::string> GDALOptionType; + /** The creation option structure. */ - struct OptionType + struct OpenOptionType + { + std::pair< bool, std::string > simpleFileName; + std::pair< bool, GDALOptionType > gdalOptions; + std::map< std::string , bool > availableOptions; + }; + + struct CreationOptionType + { + std::pair< bool, std::string > simpleFileName; + std::pair< bool, GDALOptionType > gdalOptions; + std::map< std::string , bool > availableOptions; + }; + + struct LayerOptionType { - std::pair< bool , std::string > simpleFileName; - std::pair< bool , std::string > encoding; - std::set< std::string > availableOptions; + std::pair< bool, GDALOptionType > gdalOptions; + std::map< std::string , bool > availableOptions; }; /* Set Methods */ void SetExtendedFileName(const char * extFname) override; protected: - OGRExtendedFilenameToReaderOptions(); - ~OGRExtendedFilenameToReaderOptions() override {}; + OGRExtendedFilenameToOptions(); + ~OGRExtendedFilenameToOptions() override {}; private: - OGRExtendedFilenameToReaderOptions(const Self &) = delete ; + OGRExtendedFilenameToOptions(const Self &) = delete ; void operator =(const Self&) = delete ; - OptionType m_Options; + OpenOptionType m_OpenOptions; + CreationOptionType m_CreationOptions; + LayerOptionType m_LayerOptions; }; } //end namespace otb -#endif // otbOGRExtendedFilenameToReaderOptions_h +#endif // otbOGRExtendedFilenameToOptions_h diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToWriterOptions.h b/Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToWriterOptions.h deleted file mode 100644 index 8c8422166fceedc5a12c01a8fc1d98f4ef1771dd..0000000000000000000000000000000000000000 --- a/Modules/Adapters/GdalAdapters/include/otbOGRExtendedFilenameToWriterOptions.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef otbOGRExtendedFilenameToWriterOptions_h -#define otbOGRExtendedFilenameToWriterOptions_h - -#include "otbExtendedFilenameHelper.h" - -namespace otb -{ - -/** \class OGRExtendedFilenameToWriterOptions - */ - -class ITK_EXPORT OGRExtendedFilenameToWriterOptions : public ExtendedFilenameHelper -{ -public: -}; - -} //end namespace otb - -#endif // otbOGRExtendedFilenameToWriterOptions_h \ No newline at end of file diff --git a/Modules/Adapters/GdalAdapters/src/CMakeLists.txt b/Modules/Adapters/GdalAdapters/src/CMakeLists.txt index 0cfe725108b158293cba3b56c91e4d7b1f72b2e9..0f73c07a03e044b6c89d6a19b5df6fc6b9ae4851 100644 --- a/Modules/Adapters/GdalAdapters/src/CMakeLists.txt +++ b/Modules/Adapters/GdalAdapters/src/CMakeLists.txt @@ -29,8 +29,7 @@ set(OTBGdalAdapters_SRC otbGeometriesToGeometriesFilter.cxx otbOGRDataSourceWrapper.cxx otbOGRVersionProxy.cxx - otbOGRExtendedFilenameToReaderOptions.cxx - otbOGRExtendedFilenameToWriterOptions.cxx + otbOGRExtendedFilenameToOptions.cxx ) add_library(OTBGdalAdapters ${OTBGdalAdapters_SRC}) diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx index ac43afbb4d837ce66ed40327bb4b8d1664626cc4..1f699174d6c69d03d9f2d624dde700c08d8616c3 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx @@ -117,6 +117,7 @@ char const* DeduceDriverName(std::string filename) otb::ogr::DataSource::DataSource() : m_DataSource(ITK_NULLPTR), + m_FileNameHelper(), m_OpenMode(Modes::Update_LayerUpdate), m_FirstModifiableLayerID(0) { @@ -128,6 +129,7 @@ otb::ogr::DataSource::DataSource() if (!m_DataSource) { itkExceptionMacro(<< "Failed to create OGRMemDataSource: " << CPLGetLastErrorMsg()); } + m_FileNameHelper = FileNameHelperType::New(); } otb::ogr::DataSource::DataSource(otb::ogr::version_proxy::GDALDatasetType * source, Modes::type mode) diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToOptions.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToOptions.cxx new file mode 100644 index 0000000000000000000000000000000000000000..fb51cf4d8ffc2143609f877c36943909b47e62f2 --- /dev/null +++ b/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToOptions.cxx @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES) + * + * This file is part of Orfeo Toolbox + * + * https://www.orfeo-toolbox.org/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "otbOGRExtendedFilenameToOptions.h" +#include "otb_boost_string_header.h" +#include "otb_boost_tokenizer_header.h" + +namespace otb +{ + +OGRExtendedFilenameToOptions:: +OGRExtendedFilenameToOptions() +{ + m_OpenOptions.simpleFileName.first = false; + m_OpenOptions.simpleFileName.second = ""; + + m_CreationOptions.simpleFileName.first = false; + m_CreationOptions.simpleFileName.second = ""; + +} + +void +OGRExtendedFilenameToOptions:: +SetExtendedFileName(const char *extFname) +{ + Superclass::SetExtendedFileName(extFname); + OptionMapType map = GetOptionMap(); + + m_OpenOptions.simpleFileName.first = true; + m_OpenOptions.simpleFileName.second = this->GetSimpleFileName(); + + m_CreationOptions.simpleFileName.first = true; + m_CreationOptions.simpleFileName.second = this->GetSimpleFileName(); + + MapIteratorType it; + for ( it=map.begin(); it != map.end(); it++ ) + { + std::vector<std::string> tmp; + boost::split(tmp, it->first, boost::is_any_of(":"), boost::token_compress_on); + + if (tmp.size()>2 && (tmp[0]=="gdal") ) + { + if ( tmp[1]=="oo" ) + { + m_OpenOptions.gdalOptions.first = true; + m_OpenOptions.gdalOptions.second.push_back(tmp[2] + "=" +it->second); + } + else if ( tmp[1]=="co" ) + { + m_CreationOptions.gdalOptions.first = true; + m_CreationOptions.gdalOptions.second.push_back(tmp[2] + "=" +it->second); + } + else if ( tmp[1]=="lco" ) + { + m_LayerOptions.gdalOptions.first = true; + m_LayerOptions.gdalOptions.second.push_back(tmp[2] + "=" +it->second); + } + else + { + // log a warning + } + } + + } + + +} + + +} //end namespace otb diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToReaderOptions.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToReaderOptions.cxx deleted file mode 100644 index 73fb4b311cc39f276b2b18664816d098db97ebac..0000000000000000000000000000000000000000 --- a/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToReaderOptions.cxx +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "otbOGRExtendedFilenameToReaderOptions.h" - -namespace otb -{ - -OGRExtendedFilenameToReaderOptions:: -OGRExtendedFilenameToReaderOptions() -{ - m_Options.simpleFileName.first = false; - m_Options.simpleFileName.second = ""; - - m_Options.encoding.first = false; - m_Options.encoding.second = ""; - - m_Options.availableOptions.insert("encoding"); -} - -void -OGRExtendedFilenameToReaderOptions:: -SetExtendedFileName(const char *extFname) -{ - Superclass::SetExtendedFileName(extFname); - OptionMapType map = GetOptionMap(); - - m_Options.simpleFileName.first = true; - m_Options.simpleFileName.second = this->GetSimpleFileName(); - - -} - - -} //end namespace otb diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToWriterOptions.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToWriterOptions.cxx deleted file mode 100644 index dc491e3680eaedcbc67909c992feb634c33e0038..0000000000000000000000000000000000000000 --- a/Modules/Adapters/GdalAdapters/src/otbOGRExtendedFilenameToWriterOptions.cxx +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES) - * - * This file is part of Orfeo Toolbox - * - * https://www.orfeo-toolbox.org/ - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "otbOGRExtendedFilenameToReaderOptions.h" - -namespace otb -{ - - -} //end namespace otb \ No newline at end of file diff --git a/Modules/Core/VectorDataBase/include/otbVectorDataIOBase.h b/Modules/Core/VectorDataBase/include/otbVectorDataIOBase.h index de1e241fc20c42e0436288a1bcf247c0b1891bba..e95b2e53aa4f2a2fe7aa42c8984651f26f5af19d 100644 --- a/Modules/Core/VectorDataBase/include/otbVectorDataIOBase.h +++ b/Modules/Core/VectorDataBase/include/otbVectorDataIOBase.h @@ -29,6 +29,7 @@ #include "itkDataObject.h" #include "OTBVectorDataBaseExport.h" +#include "otbOGRExtendedFilenameToOptions.h" namespace otb { @@ -72,6 +73,8 @@ public: typedef itk::Vector<double, VDimension> SpacingType; typedef itk::Point<double, VDimension> PointType; + typedef otb::OGRExtendedFilenameToOptions FileNameHelperType; + /** Set/Get the name of the file to be read. */ itkSetStringMacro(FileName); itkGetStringMacro(FileName); @@ -173,6 +176,8 @@ private: VectorDataIOBase(const Self &); //purposely not implemented void operator =(const Self&); //purposely not implemented + FileNameHelperType m_FileNameHelper; + }; } // end namespace otb