Commit 09151663 authored by Cédric Traizet's avatar Cédric Traizet

Merge branch '1769_drop_support_gdal_1' into 'develop'

Drop support for gdal 1.X

See merge request !334
parents 5ef33657 5a6307ad
...@@ -86,7 +86,7 @@ See table \ref{tab:otb-dependencies} for the full list of dependencies. ...@@ -86,7 +86,7 @@ See table \ref{tab:otb-dependencies} for the full list of dependencies.
\hline \hline
\textbf{ITK} & \url{http://www.itk.org} & yes & 4.6.0 \\ \textbf{ITK} & \url{http://www.itk.org} & yes & 4.6.0 \\
\hline \hline
\textbf{GDAL} & \url{http://www.gdal.org} & yes & 1.10 (2.x also supported) \\ \textbf{GDAL} & \url{http://www.gdal.org} & yes & 2.0 \\
\hline \hline
\textbf{OSSIM} & \url{http://www.ossim.org} & yes & 1.8.20-3 \\ \textbf{OSSIM} & \url{http://www.ossim.org} & yes & 1.8.20-3 \\
\hline \hline
......
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
#include "itkObjectFactory.h" // that should have been included by itkMacro.h #include "itkObjectFactory.h" // that should have been included by itkMacro.h
#include "otbOGRLayerWrapper.h" #include "otbOGRLayerWrapper.h"
#include "otbOGRVersionProxy.h"
#include "otbOGRExtendedFilenameToOptions.h" #include "otbOGRExtendedFilenameToOptions.h"
class OGRLayer; class OGRLayer;
...@@ -164,7 +163,7 @@ public: ...@@ -164,7 +163,7 @@ public:
* \note No condition is assumed on the non-nullity of \c source. * \note No condition is assumed on the non-nullity of \c source.
* \see \c DataSource(GDALDataset *) * \see \c DataSource(GDALDataset *)
*/ */
static Pointer New(ogr::version_proxy::GDALDatasetType * sourcemode, Modes::type mode = Modes::Read , const std::vector< std::string > & layerOptions = std::vector< std::string >() ); static Pointer New(GDALDataset * sourcemode, Modes::type mode = Modes::Read , const std::vector< std::string > & layerOptions = std::vector< std::string >() );
//@} //@}
/**\name Projection Reference property */ /**\name Projection Reference property */
...@@ -301,7 +300,7 @@ public: ...@@ -301,7 +300,7 @@ public:
* \throw None * \throw None
* \post Assumes ownership of the \c source. * \post Assumes ownership of the \c source.
*/ */
void Reset(ogr::version_proxy::GDALDatasetType * source); void Reset(GDALDataset * source);
/**\name Layers modification */ /**\name Layers modification */
//@{ //@{
...@@ -477,8 +476,6 @@ public: ...@@ -477,8 +476,6 @@ public:
} }
/** Flushes all changes to disk. /** Flushes all changes to disk.
* \throw itd::ExceptionObject in case the flush operation failed.
* \sa \c GDALDataset::SyncToDisk()
*/ */
void SyncToDisk(); void SyncToDisk();
...@@ -497,7 +494,7 @@ public: ...@@ -497,7 +494,7 @@ public:
* \warning You must under no circumstance try to delete the \c GDALDataset * \warning You must under no circumstance try to delete the \c GDALDataset
* obtained this way. * obtained this way.
*/ */
ogr::version_proxy::GDALDatasetType & ogr(); GDALDataset & ogr();
void SetLayerCreationOptions( const std::vector< std::string > & options ); void SetLayerCreationOptions( const std::vector< std::string > & options );
void AddLayerCreationOptions( std::vector< std::string > options ); void AddLayerCreationOptions( std::vector< std::string > options );
...@@ -517,7 +514,7 @@ protected: ...@@ -517,7 +514,7 @@ protected:
/** Init constructor. /** Init constructor.
* \post The newly constructed object owns the \c source parameter. * \post The newly constructed object owns the \c source parameter.
*/ */
DataSource(ogr::version_proxy::GDALDatasetType * source, Modes::type mode , const std::vector< std::string > & layerOption = std::vector< std::string >() ); DataSource(GDALDataset * source, Modes::type mode , const std::vector< std::string > & layerOption = std::vector< std::string >() );
/** Destructor. /** Destructor.
* \post The \c GDALDataset owned is released (if not null). * \post The \c GDALDataset owned is released (if not null).
*/ */
...@@ -554,7 +551,7 @@ private: ...@@ -554,7 +551,7 @@ private:
std::string GetDatasetDescription() const; std::string GetDatasetDescription() const;
private: private:
ogr::version_proxy::GDALDatasetType *m_DataSource; GDALDataset *m_DataSource;
std::vector< std::string > m_LayerOptions; std::vector< std::string > m_LayerOptions;
Modes::type m_OpenMode; Modes::type m_OpenMode;
int m_FirstModifiableLayerID; int m_FirstModifiableLayerID;
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
// to the compilation mode of the client code. // to the compilation mode of the client code.
inline inline
otb::ogr::version_proxy::GDALDatasetType & otb::ogr::DataSource::ogr() GDALDataset & otb::ogr::DataSource::ogr()
{ {
assert(m_DataSource && "GDALDataset not initialized"); assert(m_DataSource && "GDALDataset not initialized");
return *m_DataSource; return *m_DataSource;
......
...@@ -97,10 +97,9 @@ typedef mpl::map ...@@ -97,10 +97,9 @@ typedef mpl::map
, mpl::pair<char* , mpl::int_<OFTString> > , mpl::pair<char* , mpl::int_<OFTString> >
, mpl::pair<char const* , mpl::int_<OFTString> > , mpl::pair<char const* , mpl::int_<OFTString> >
, mpl::pair<std::vector<std::string>, mpl::int_<OFTStringList> > , mpl::pair<std::vector<std::string>, mpl::int_<OFTStringList> >
#ifdef OTB_USE_GDAL_20 , mpl::pair<GIntBig, mpl::int_<OFTInteger64> >
, mpl::pair<GIntBig, mpl::int_<OFTInteger64> > , mpl::pair<std::vector<GIntBig>, mpl::int_<OFTInteger64List> >
, mpl::pair<std::vector<GIntBig>, mpl::int_<OFTInteger64List> >
#endif
// OFTBinary // OFTBinary
// OFTDate // OFTDate
// OFTTime // OFTTime
...@@ -341,10 +340,8 @@ typedef mpl::map ...@@ -341,10 +340,8 @@ typedef mpl::map
, mpl::pair<mpl::int_<OFTRealList>, MemberContainerGetterPtr<double, &OGRFeature::GetFieldAsDoubleList> > , mpl::pair<mpl::int_<OFTRealList>, MemberContainerGetterPtr<double, &OGRFeature::GetFieldAsDoubleList> >
, mpl::pair<mpl::int_<OFTString>, MemberGetterPtr<char const*, &OGRFeature::GetFieldAsString, std::string> > , mpl::pair<mpl::int_<OFTString>, MemberGetterPtr<char const*, &OGRFeature::GetFieldAsString, std::string> >
, mpl::pair<mpl::int_<OFTStringList>, StringListMemberGetterPtr<std::vector<std::string> > > , mpl::pair<mpl::int_<OFTStringList>, StringListMemberGetterPtr<std::vector<std::string> > >
#ifdef OTB_USE_GDAL_20
, mpl::pair<mpl::int_<OFTInteger64>, MemberGetterPtr<GIntBig, &OGRFeature::GetFieldAsInteger64> > , mpl::pair<mpl::int_<OFTInteger64>, MemberGetterPtr<GIntBig, &OGRFeature::GetFieldAsInteger64> >
, mpl::pair<mpl::int_<OFTInteger64List>, MemberContainerGetterPtr<GIntBig, &OGRFeature::GetFieldAsInteger64List> > , mpl::pair<mpl::int_<OFTInteger64List>, MemberContainerGetterPtr<GIntBig, &OGRFeature::GetFieldAsInteger64List> >
#endif
> FieldGetters_Map; > FieldGetters_Map;
/**\ingroup GeometryInternals /**\ingroup GeometryInternals
...@@ -360,10 +357,8 @@ typedef mpl::map ...@@ -360,10 +357,8 @@ typedef mpl::map
, mpl::pair<mpl::int_<OFTRealList>, MemberContainerSetterPtr<double, &OGRFeature::SetField> > , mpl::pair<mpl::int_<OFTRealList>, MemberContainerSetterPtr<double, &OGRFeature::SetField> >
, mpl::pair<mpl::int_<OFTString>, MemberSetterPtr<char const*, &OGRFeature::SetField/*, std::string*/> > , mpl::pair<mpl::int_<OFTString>, MemberSetterPtr<char const*, &OGRFeature::SetField/*, std::string*/> >
, mpl::pair<mpl::int_<OFTStringList>, StringListMemberSetterPtr<std::vector<std::string> > > , mpl::pair<mpl::int_<OFTStringList>, StringListMemberSetterPtr<std::vector<std::string> > >
#ifdef OTB_USE_GDAL_20
, mpl::pair<mpl::int_<OFTInteger64>, MemberSetterPtr<GIntBig, &OGRFeature::SetField> > , mpl::pair<mpl::int_<OFTInteger64>, MemberSetterPtr<GIntBig, &OGRFeature::SetField> >
, mpl::pair<mpl::int_<OFTInteger64List>, MemberContainerSetterPtr<const GIntBig, &OGRFeature::SetField> > , mpl::pair<mpl::int_<OFTInteger64List>, MemberContainerSetterPtr<const GIntBig, &OGRFeature::SetField> >
#endif
> FieldSetters_Map; > FieldSetters_Map;
/**\ingroup GeometryInternals /**\ingroup GeometryInternals
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <cassert> #include <cassert>
#include <boost/range/begin.hpp> #include <boost/range/begin.hpp>
#include <boost/range/end.hpp> #include <boost/range/end.hpp>
#include "ogr_feature.h"
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-local-typedefs" #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
...@@ -43,6 +44,8 @@ ...@@ -43,6 +44,8 @@
#include "OTBGdalAdaptersExport.h" #include "OTBGdalAdaptersExport.h"
class GDALDataset;
namespace otb namespace otb
{ {
namespace ogr namespace ogr
...@@ -105,6 +108,35 @@ private: ...@@ -105,6 +108,35 @@ private:
std::vector<char const*> m_raw; std::vector<char const*> m_raw;
}; };
/**
* Return the list of available drivers.
*
* \return A vector of string containing the list of available drivers.
*/
OTBGdalAdapters_EXPORT
std::vector<std::string> GetAvailableDriversAsStringVector();
/**
* Return the list of files composing the dataset.
*
* \param dataset Pointer to the dataset to get the file list from. Will not be
* checked for null pointer.
*
* \return A vector of string containing the list of files.
*/
OTBGdalAdapters_EXPORT
std::vector<std::string> GetFileListAsStringVector(GDALDataset * dataset);
/**
* Returns true if the field 'index' is set and not-null in the given feature
*
* Before gdal 2.2, it calls OGRFeature::IsFieldSet().
* After gdal 2.2, it calls OGRFeature::IsFieldSetAndNotNull()
*/
OTBGdalAdapters_EXPORT
bool IsFieldSetAndNotNull(OGRFeature *feat, int index);
} // ogr namespace } // ogr namespace
} // end namespace otb } // end namespace otb
......
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#endif #endif
// #include "itkIndent.h", included from field // #include "itkIndent.h", included from field
#include "otbOGRFeatureWrapper.h" #include "otbOGRFeatureWrapper.h"
#include "otbOGRVersionProxy.h"
#include <string> #include <string>
// #include "ogr_core.h" // OGRwkbGeometryType, included from feature -> field // #include "ogr_core.h" // OGRwkbGeometryType, included from feature -> field
...@@ -119,7 +118,7 @@ public: ...@@ -119,7 +118,7 @@ public:
* OGRDataSource::ExecuteSQL(). It's actually the constructor called by \c * OGRDataSource::ExecuteSQL(). It's actually the constructor called by \c
* DataSource::ExecuteSQL(). * DataSource::ExecuteSQL().
*/ */
Layer(OGRLayer* layer, otb::ogr::version_proxy::GDALDatasetType& sourceInChargeOfLifeTime, bool modifiable); Layer(OGRLayer* layer, GDALDataset& sourceInChargeOfLifeTime, bool modifiable);
//@} //@}
/**\name Features collection */ /**\name Features collection */
......
/*
* 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 otbOGRVersionProxy_h
#define otbOGRVersionProxy_h
#include <string>
#include <vector>
#include "otbConfigure.h"
#include "itkMacro.h"
#if defined(_MSC_VER)
#pragma warning ( push )
#pragma warning ( disable: 4251 )
#include "ogr_core.h" // OGR enums
#pragma warning ( pop )
#else
#include "ogr_core.h" // OGR enums
#endif
#ifdef OTB_USE_GDAL_20
class GDALDataset;
class GDALDriver;
#else
class OGRDataSource;
class OGRSFDriver;
#endif
class OGRFeature;
#include "OTBGdalAdaptersExport.h"
namespace otb
{
namespace ogr
{
namespace version_proxy
{
/**
* With Gdal >= 2.0, this function will test equality between type and
* OFTInteger64 enum. Otherwise, it returns false.
*/
OTBGdalAdapters_EXPORT bool IsOFTInteger64(OGRFieldType type);
/**
* This namespace holds proxy functions hiding interface changes in gdal 2.0
*
* This namespace holds proxy functions hiding interface changes in OGR
* dataset between gdal 1.x (x>10) and gdal 2.x. It defines a common
* interface that should be used in place of calling directly the
* wrapped gdal functions.
*
* Whenever GDALDataset and GDALDriver have to be used to open a
* vector dataset (or OGRDataSource an OGRSFDriver for gdal 1.x), one
* should use ogr::version_proxy types GDALDatasetType and
* GDALDriverType.
*
* See function documentation for details.
*/
#ifdef OTB_USE_GDAL_20
typedef GDALDataset GDALDatasetType;
typedef GDALDriver GDALDriverType;
#else
typedef OGRDataSource GDALDatasetType;
typedef OGRSFDriver GDALDriverType;
#endif
/**
* This function opens a file, possibly in read-only mode, and returns
* a dataset.
*
* Calls OGRSFDriverRegistrar::Open for gdal 1.x implementation and GDALopenEx for
* gdal 2.x implementation.
* \param filename Filename of the file to open
* \param readOnly: If true, dataset is open in read-only mode.
* \return NULL if file could not be open.
*/
OTBGdalAdapters_EXPORT
GDALDatasetType * Open(const char * filename, bool readOnly = true , std::vector< std::string > const & options = std::vector< std::string >() );
/**
* This function closes a dataset.
*
* Calls OGRDataSource::DestroyDataSource for gdal 1.x
* implementation and GDALClose for gdal 2.x implementation.
*
* \param dataset Pointer to the dataset to close. Will not be
* checked for null pointer.
*/
OTBGdalAdapters_EXPORT
void Close(GDALDatasetType * dataset);
/**
* This function creates a new dataset.
*
* Calls OGRSFDriver::CreateDataSource for gdal 1.x implementation
* and GDALDriver::Create with (0,0) raster size for gdal 2.x
* implementation
*
* \param driver Pointer to the driver used for creation. Will not
* be checked for null pointer.
*
* \param name Name of the dataset to create.
*
* \return NULL if dataset could not be created.
*/
OTBGdalAdapters_EXPORT
GDALDatasetType * Create(GDALDriverType * driver, const char * name , std::vector< std::string > const & options = std::vector< std::string >() );
/**
* This function physically deletes an existing dataset.
*
* Calls OGRDataSource::DeleteDataSource for gdal 1.x implementation
* and GDALDriver::Delete for gdal 2.x implementation.
*
* \param name Name of the dataset to destroy.
*/
OTBGdalAdapters_EXPORT
bool Delete(const char * name);
/**
* This function returns a pointer to the driver from its name.
*
* Calls OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName() for
* gdal 1.x implementation and
* GetGDALDriverManager()->GetDriverByName() for gdal 2.x
* implementation.
*
* \param name Name of the driver to retrieve
*
* \return NULL if no driver could be retrieved.
*/
OTBGdalAdapters_EXPORT
GDALDriverType * GetDriverByName(const char * name);
OTBGdalAdapters_EXPORT
std::string GetDriverNameFromDataSource(const GDALDatasetType * ds);
/**
* Sync dataset to disk.
*
* Calls OGRDataSource::SyncToDisk() for gdal 1.x implementation and
* GDALDataset::FlushCache() for gdal 2.x implementation.
*
* \param dataset Pointer to the dataset to sync. Will not be
* checked for null pointer.
*
* \return True if sync went on without any error.
*/
OTBGdalAdapters_EXPORT
bool SyncToDisk(GDALDatasetType * dataset);
/**
* \return The name of the dataset class behind the implementation
* (OGRDataSource for gdal 1.x and GdalDataset for gdal 2.x)
*/
OTBGdalAdapters_EXPORT
std::string GetDatasetClassName();
/**
* \return The name of the driver class behind the implementation
* (OGRSFDriver for gdal 1.x and GDALDriver for gdal 2.x)
*/
OTBGdalAdapters_EXPORT
std::string GetDriverClassName();
/**
* Return the list of files composing the dataset.
*
* Calls OGRDataSource::GetName() and wrap in string vector for gdal
* 1.x implementation, and GDALDataset::GetFileList and wrap in
* string vector for gdal 2.x implementation.
*
* \param dataset Pointer to the dataset to get the file list from. Will not be
* checked for null pointer.
*
* \return A vector of string containing the list of files.
*/
OTBGdalAdapters_EXPORT
std::vector<std::string> GetFileListAsStringVector(GDALDatasetType * dataset);
/**
* Return the list of available drivers.
*
* Calls OGRSFDriverRegistrar::GetRegistrar() for gdal 1.x
* implementation and GetGDALDriverManager() for gdal 2.x
* implementation.
*
* \return A vector of string containing the list of available drivers.
*/
OTBGdalAdapters_EXPORT
std::vector<std::string> GetAvailableDriversAsStringVector();
/**
* Returns true if the field 'index' is set and not-null in the given feature
*
* Before gdal 2.2, it calls OGRFeature::IsFieldSet().
* After gdal 2.2, it calls OGRFeature::IsFieldSetAndNotNull()
*/
OTBGdalAdapters_EXPORT
bool IsFieldSetAndNotNull(OGRFeature *feat, int index);
}
}
} // end namespace otb
#endif
...@@ -28,8 +28,8 @@ set(OTBGdalAdapters_SRC ...@@ -28,8 +28,8 @@ set(OTBGdalAdapters_SRC
otbOGRDriversInit.cxx otbOGRDriversInit.cxx
otbGeometriesToGeometriesFilter.cxx otbGeometriesToGeometriesFilter.cxx
otbOGRDataSourceWrapper.cxx otbOGRDataSourceWrapper.cxx
otbOGRVersionProxy.cxx
otbOGRExtendedFilenameToOptions.cxx otbOGRExtendedFilenameToOptions.cxx
otbOGRHelpers.cxx
) )
add_library(OTBGdalAdapters ${OTBGdalAdapters_SRC}) add_library(OTBGdalAdapters ${OTBGdalAdapters_SRC})
......
...@@ -48,13 +48,13 @@ bool otb::ogr::DataSource::Clear() ...@@ -48,13 +48,13 @@ bool otb::ogr::DataSource::Clear()
return true; return true;
} }
void otb::ogr::DataSource::Reset(otb::ogr::version_proxy::GDALDatasetType * source) void otb::ogr::DataSource::Reset(GDALDataset * source)
{ {
if (m_DataSource) { if (m_DataSource) {
// OGR makes a pointless check for non-nullity in // OGR makes a pointless check for non-nullity in
// GDALDataset::DestroyDataSource (pointless because "delete 0" is // GDALDataset::DestroyDataSource (pointless because "delete 0" is
// perfectly valid -> it's a no-op) // perfectly valid -> it's a no-op)
ogr::version_proxy::Close(m_DataSource); // void, noexcept GDALClose(m_DataSource); // void, noexcept
} }
m_DataSource = source; m_DataSource = source;
} }
...@@ -108,7 +108,7 @@ char const* DeduceDriverName(std::string filename) ...@@ -108,7 +108,7 @@ char const* DeduceDriverName(std::string filename)
ExtensionDriverAssociation const* whichIt = ExtensionDriverAssociation const* whichIt =
std::find_if( std::find_if(
boost::begin(k_ExtensionDriverMap), boost::end(k_ExtensionDriverMap), boost::begin(k_ExtensionDriverMap), boost::end(k_ExtensionDriverMap),
boost::bind(&ExtensionDriverAssociation::Matches, _1, extension)); [&](auto const & x) { return x.Matches(extension); } );
if (whichIt == boost::end(k_ExtensionDriverMap)) if (whichIt == boost::end(k_ExtensionDriverMap))
{ {
return nullptr; // nothing found return nullptr; // nothing found
...@@ -126,10 +126,16 @@ otb::ogr::DataSource::DataSource() ...@@ -126,10 +126,16 @@ otb::ogr::DataSource::DataSource()
{ {
Drivers::Init(); Drivers::Init();
ogr::version_proxy::GDALDriverType * d = GDALDriver * d =
ogr::version_proxy::GetDriverByName("Memory"); GetGDALDriverManager()->GetDriverByName("Memory");
assert(d && "OGR Memory driver not found"); assert(d && "OGR Memory driver not found");
m_DataSource = ogr::version_proxy::Create(d,"in-memory"); m_DataSource = d->Create( "in-memory" ,
0 ,
0 ,
0 ,
GDT_Unknown ,
0 );
if (!m_DataSource) { if (!m_DataSource) {
itkExceptionMacro(<< "Failed to create OGRMemDataSource: " itkExceptionMacro(<< "Failed to create OGRMemDataSource: "
<< CPLGetLastErrorMsg()); << CPLGetLastErrorMsg());
...@@ -137,7 +143,7 @@ otb::ogr::DataSource::DataSource() ...@@ -137,7 +143,7 @@ otb::ogr::DataSource::DataSource()
} }
otb::ogr::DataSource::DataSource( otb::ogr::DataSource::DataSource(
otb::ogr::version_proxy::GDALDatasetType * source , GDALDataset * source ,
Modes::type mode , Modes::type mode ,
const std::vector< std::string > & options /*NULL*/ ) const std::vector< std::string > & options /*NULL*/ )
: m_DataSource(source) , : m_DataSource(source) ,
...@@ -155,10 +161,12 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c ...@@ -155,10 +161,12 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c
std::string simpleFileName = fileNameHelper->GetSimpleFileName(); std::string simpleFileName = fileNameHelper->GetSimpleFileName();
bool update = (mode != Modes::Read); bool update = (mode != Modes::Read);
ogr::version_proxy::GDALDatasetType * source = GDALDataset * source = (GDALDataset *)GDALOpenEx(
ogr::version_proxy::Open( simpleFileName.c_str() , simpleFileName.c_str(),
!update , (update? GDAL_OF_UPDATE: GDAL_OF_READONLY) | GDAL_OF_VECTOR,
fileNameHelper->GetGDALOpenOptions() ); NULL,
otb::ogr::StringListConverter( fileNameHelper->GetGDALOpenOptions() ).to_ogr(),
NULL);
if (!source) if (!source)
{ {
// In read mode, this is a failure // In read mode, this is a failure
...@@ -178,8 +186,8 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c ...@@ -178,8 +186,8 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c
<<simpleFileName<<">."); <<simpleFileName<<">.");
} }
ogr::version_proxy::GDALDriverType * d = GDALDriver * d =
ogr::version_proxy::GetDriverByName( driverName ); GetGDALDriverManager()->GetDriverByName( driverName );
if(!d) if(!d)
{ {
...@@ -187,10 +195,13 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c ...@@ -187,10 +195,13 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c
<< ", check your OGR configuration for available drivers." ); << ", check your OGR configuration for available drivers." );
} }
source = ogr::version_proxy::Create( source = d->Create( simpleFileName.c_str() ,
d , 0 ,
simpleFileName.c_str() , 0 ,
fileNameHelper->GetGDALCreationOptions() ); 0 ,
GDT_Unknown ,
otb::ogr::StringListConverter(
fileNameHelper->GetGDALCreationOptions() ).to_ogr() );
if (!source) { if (!source) {
itkGenericExceptionMacro(<< "Failed to create GDALDataset <" itkGenericExceptionMacro(<< "Failed to create GDALDataset <"
<< simpleFileName << "> (driver name: <" << driverName << simpleFileName << "> (driver name: <" << driverName
...@@ -207,12 +218,41 @@ void DeleteDataSource(std::string const& datasourceName) ...@@ -207,12 +218,41 @@ void DeleteDataSource(std::string const& datasourceName)
fileNameHelper->SetExtendedFileName( datasourceName.c_str() ); fileNameHelper->SetExtendedFileName( datasourceName.c_str() );
std::string simpleFileName = fileNameHelper->GetSimpleFileName(); std::string simpleFileName = fileNameHelper->GetSimpleFileName();
bool ret = otb::ogr::version_proxy::Delete(simpleFileName.c_str()); // Open dataset
if (!ret) GDALDataset * poDS = (GDALDataset *)GDALOpenEx(
simpleFileName.c_str(),
GDAL_OF_UPDATE | GDAL_OF_VECTOR,
NULL,
NULL,
NULL);
GDALDriver * poDriver = NULL;
bool success =1;
if(poDS)
{
poDriver = poDS->GetDriver();
GDALClose(poDS);
}
else
{
itkGenericExceptionMacro(<< "Cannot open data source " << simpleFileName
<< ": " << CPLGetLastErrorMsg());
}
if(poDriver)
{ {
itkGenericExceptionMacro(<< "Deletion of data source " << simpleFileName OGRErr ret = poDriver->Delete(simpleFileName.c_str());
if (ret != OGRERR_NONE)
{
itkGenericExceptionMacro(<< "Deletion of data source " << simpleFileName
<< " failed: " << CPLGetLastErrorMsg()); << " failed: " << CPLGetLastErrorMsg());
}
}
else
{
itkGenericExceptionMacro(<< "Cannot get driver associated with data source " << simpleFileName
<< ": " << CPLGetLastErrorMsg());
} }
} }