Commit 48f48bdf authored by Antoine Regimbeau's avatar Antoine Regimbeau

ENH: OpenDataSource can use extended filename

Warning : static member is used, might be a bad design
parent 758194ab
......@@ -552,6 +552,7 @@ private:
private:
ogr::version_proxy::GDALDatasetType *m_DataSource;
FileNameHelperType::Pointer m_FileNameHelper;
static FileNameHelperType::Pointer staticFileNameHelper;
Modes::type m_OpenMode;
int m_FirstModifiableLayerID;
}; // end class DataSource
......
......@@ -71,6 +71,14 @@ public:
/* Set Methods */
void SetExtendedFileName(const char * extFname) override;
GDALOptionType GetGDALOptions( const std::string & type ) const ;
GDALOptionType GetGDALOpenOptions() const ;
GDALOptionType GetGDALCreationOptions() const ;
GDALOptionType GetGDALLayerOptions() const ;
protected:
OGRExtendedFilenameToOptions();
~OGRExtendedFilenameToOptions() override {};
......
......@@ -97,7 +97,7 @@ OTBGdalAdapters_EXPORT bool IsOFTInteger64(OGRFieldType type);
* \return NULL if file could not be open.
*/
OTBGdalAdapters_EXPORT
GDALDatasetType * Open(const char * filename, bool readOnly = true);
GDALDatasetType * Open(const char * filename, bool readOnly = true , std::vector< std::string > const & options = std::vector< std::string >() );
/**
* This function closes a dataset.
......@@ -126,7 +126,7 @@ OTBGdalAdapters_EXPORT bool IsOFTInteger64(OGRFieldType type);
* \return NULL if dataset could not be created.
*/
OTBGdalAdapters_EXPORT
GDALDatasetType * Create(GDALDriverType * driver, const char * name);
GDALDatasetType * Create(GDALDriverType * driver, const char * name , std::vector< std::string > const & options = std::vector< std::string >() );
/**
......
......@@ -41,6 +41,11 @@
/*===========================================================================*/
/*=======================[ construction/destruction ]========================*/
/*===========================================================================*/
otb::ogr::DataSource::FileNameHelperType::Pointer
otb::ogr::DataSource::staticFileNameHelper =
otb::ogr::DataSource::FileNameHelperType::New();
bool otb::ogr::DataSource::Clear()
{
Reset(ITK_NULLPTR);
......@@ -143,8 +148,13 @@ otb::ogr::DataSource::DataSource(otb::ogr::version_proxy::GDALDatasetType * sour
otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string const& datasourceName, Modes::type mode)
{
bool update = (mode != Modes::Read);
staticFileNameHelper->SetExtendedFileName( datasourceName.c_str() );
ogr::version_proxy::GDALDatasetType * source = ogr::version_proxy::Open(datasourceName.c_str(),!update);
std::string simpleFileName = staticFileNameHelper->GetSimpleFileName();
ogr::version_proxy::GDALDatasetType * source =
ogr::version_proxy::Open( simpleFileName.c_str() ,
!update ,
staticFileNameHelper->GetGDALOpenOptions() );
if (!source)
{
// In read mode, this is a failure
......@@ -170,7 +180,10 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c
itkGenericExceptionMacro(<<"Could not create OGR driver "<<driverName<<", check your OGR configuration for available drivers.");
}
source = ogr::version_proxy::Create(d,datasourceName.c_str());
source = ogr::version_proxy::Create(
d ,
simpleFileName.c_str() ,
staticFileNameHelper->GetGDALCreationOptions() );
if (!source) {
itkGenericExceptionMacro(<< "Failed to create GDALDataset <"<<datasourceName
<<"> (driver name: <" << driverName<<">: " << CPLGetLastErrorMsg());
......
......@@ -79,9 +79,42 @@ SetExtendedFileName(const char *extFname)
}
}
}
OGRExtendedFilenameToOptions::
GDALOptionType
OGRExtendedFilenameToOptions::
GetGDALOptions( const std::string & type ) const
{
if ( type == "layer" )
return m_LayerOptions.gdalOptions.second;
else if ( type == "creation" )
return m_CreationOptions.gdalOptions.second;
else if ( type == "open" )
return m_OpenOptions.gdalOptions.second;
else
{
// warn user : wrong option
return GDALOptionType();
}
}
#define GetGDALOptionMacro( Type ) \
OGRExtendedFilenameToOptions:: \
GDALOptionType \
OGRExtendedFilenameToOptions:: \
GetGDAL##Type##Options() const \
{ \
return m_##Type##Options.gdalOptions.second; \
} \
GetGDALOptionMacro( Open )
GetGDALOptionMacro( Creation )
GetGDALOptionMacro( Layer )
} //end namespace otb
......@@ -19,6 +19,7 @@
*/
#include "otbOGRVersionProxy.h"
#include "otbOGRHelpers.h"
#include "itkMacro.h"
......@@ -60,12 +61,17 @@ OTBGdalAdapters_EXPORT bool IsOFTInteger64(OGRFieldType type)
}
GDALDatasetType * Open(const char * filename, bool readOnly)
GDALDatasetType * Open(const char * filename, bool readOnly , std::vector< std::string > const & options )
{
#if GDAL_VERSION_NUM<2000000
return OGRSFDriverRegistrar::Open(filename,!readOnly);
#else
return (GDALDatasetType *)GDALOpenEx(filename, (readOnly? GDAL_OF_READONLY : GDAL_OF_UPDATE) | GDAL_OF_VECTOR,NULL,NULL,NULL);
return (GDALDatasetType *)GDALOpenEx(
filename,
(readOnly? GDAL_OF_READONLY : GDAL_OF_UPDATE) | GDAL_OF_VECTOR,
NULL,
otb::ogr::StringListConverter( options ).to_ogr(),
NULL);
#endif
}
......@@ -78,7 +84,7 @@ void Close(GDALDatasetType * dataset)
#endif
}
GDALDatasetType * Create(GDALDriverType * driver, const char * name)
GDALDatasetType * Create(GDALDriverType * driver, const char * name , std::vector< std::string > const & options )
{
#if GDAL_VERSION_NUM<2000000
GDALDatasetType * ds = driver->CreateDataSource(name);
......@@ -88,7 +94,12 @@ GDALDatasetType * Create(GDALDriverType * driver, const char * name)
return ds;
#else
return driver->Create(name,0,0,0,GDT_Unknown,NULL);
return driver->Create( name ,
0 ,
0 ,
0 ,
GDT_Unknown ,
otb::ogr::StringListConverter( options ).to_ogr() );
#endif
}
......
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