Commit 758194ab authored by Antoine Regimbeau's avatar Antoine Regimbeau

ENH: include class ExtendedFilename as member of OGRDataSource

parent cdaf666c
......@@ -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
......
......@@ -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
/*
* 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
......@@ -29,8 +29,7 @@ set(OTBGdalAdapters_SRC
otbGeometriesToGeometriesFilter.cxx
otbOGRDataSourceWrapper.cxx
otbOGRVersionProxy.cxx
otbOGRExtendedFilenameToReaderOptions.cxx
otbOGRExtendedFilenameToWriterOptions.cxx
otbOGRExtendedFilenameToOptions.cxx
)
add_library(OTBGdalAdapters ${OTBGdalAdapters_SRC})
......
......@@ -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)
......
......@@ -18,32 +18,67 @@
* limitations under the License.
*/
#include "otbOGRExtendedFilenameToReaderOptions.h"
#include "otbOGRExtendedFilenameToOptions.h"
#include "otb_boost_string_header.h"
#include "otb_boost_tokenizer_header.h"
namespace otb
{
OGRExtendedFilenameToReaderOptions::
OGRExtendedFilenameToReaderOptions()
OGRExtendedFilenameToOptions::
OGRExtendedFilenameToOptions()
{
m_Options.simpleFileName.first = false;
m_Options.simpleFileName.second = "";
m_OpenOptions.simpleFileName.first = false;
m_OpenOptions.simpleFileName.second = "";
m_Options.encoding.first = false;
m_Options.encoding.second = "";
m_CreationOptions.simpleFileName.first = false;
m_CreationOptions.simpleFileName.second = "";
m_Options.availableOptions.insert("encoding");
}
void
OGRExtendedFilenameToReaderOptions::
OGRExtendedFilenameToOptions::
SetExtendedFileName(const char *extFname)
{
Superclass::SetExtendedFileName(extFname);
OptionMapType map = GetOptionMap();
m_Options.simpleFileName.first = true;
m_Options.simpleFileName.second = this->GetSimpleFileName();
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
}
}
}
}
......
/*
* 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
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment