diff --git a/Documentation/SoftwareGuide/Latex/Installation.tex b/Documentation/SoftwareGuide/Latex/Installation.tex index 8ccfa9df9a6088ba295fd4b910c173a3af70f16c..b4ad2a3145da54529041519df2f1632c8fe07d50 100644 --- a/Documentation/SoftwareGuide/Latex/Installation.tex +++ b/Documentation/SoftwareGuide/Latex/Installation.tex @@ -86,7 +86,7 @@ See table \ref{tab:otb-dependencies} for the full list of dependencies. \hline \textbf{ITK} & \url{http://www.itk.org} & yes & 4.6.0 \\ \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 \textbf{OSSIM} & \url{http://www.ossim.org} & yes & 1.8.20-3 \\ \hline diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h b/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h index f75d86e7847099a0c757f3e0b239f48fa47ad51b..f3a149a974367e652a821ada687d731096bca4cb 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h +++ b/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.h @@ -45,7 +45,6 @@ #include "itkObjectFactory.h" // that should have been included by itkMacro.h #include "otbOGRLayerWrapper.h" -#include "otbOGRVersionProxy.h" #include "otbOGRExtendedFilenameToOptions.h" class OGRLayer; @@ -164,7 +163,7 @@ public: * \note No condition is assumed on the non-nullity of \c source. * \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 */ @@ -301,7 +300,7 @@ public: * \throw None * \post Assumes ownership of the \c source. */ - void Reset(ogr::version_proxy::GDALDatasetType * source); + void Reset(GDALDataset * source); /**\name Layers modification */ //@{ @@ -477,8 +476,6 @@ public: } /** Flushes all changes to disk. - * \throw itd::ExceptionObject in case the flush operation failed. - * \sa \c GDALDataset::SyncToDisk() */ void SyncToDisk(); @@ -497,7 +494,7 @@ public: * \warning You must under no circumstance try to delete the \c GDALDataset * obtained this way. */ - ogr::version_proxy::GDALDatasetType & ogr(); + GDALDataset & ogr(); void SetLayerCreationOptions( const std::vector< std::string > & options ); void AddLayerCreationOptions( std::vector< std::string > options ); @@ -517,7 +514,7 @@ protected: /** Init constructor. * \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. * \post The \c GDALDataset owned is released (if not null). */ @@ -554,7 +551,7 @@ private: std::string GetDatasetDescription() const; private: - ogr::version_proxy::GDALDatasetType *m_DataSource; + GDALDataset *m_DataSource; std::vector< std::string > m_LayerOptions; Modes::type m_OpenMode; int m_FirstModifiableLayerID; diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.hxx b/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.hxx index e2990958c6d871df3e433ca66732cd5e77c0b760..acfea3a977c90c7c4738f1716e7a7c4be5cd37ef 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.hxx +++ b/Modules/Adapters/GdalAdapters/include/otbOGRDataSourceWrapper.hxx @@ -43,7 +43,7 @@ // to the compilation mode of the client code. inline -otb::ogr::version_proxy::GDALDatasetType & otb::ogr::DataSource::ogr() +GDALDataset & otb::ogr::DataSource::ogr() { assert(m_DataSource && "GDALDataset not initialized"); return *m_DataSource; diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRFieldWrapper.hxx b/Modules/Adapters/GdalAdapters/include/otbOGRFieldWrapper.hxx index 258db5172ef7632fa454444bababb233abae9129..2ac3137985b80832f7db3ba60b7d0f1d68d059af 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRFieldWrapper.hxx +++ b/Modules/Adapters/GdalAdapters/include/otbOGRFieldWrapper.hxx @@ -97,10 +97,9 @@ typedef mpl::map , mpl::pair<char* , mpl::int_<OFTString> > , mpl::pair<char const* , mpl::int_<OFTString> > , mpl::pair<std::vector<std::string>, mpl::int_<OFTStringList> > - #ifdef OTB_USE_GDAL_20 - , mpl::pair<GIntBig, mpl::int_<OFTInteger64> > - , mpl::pair<std::vector<GIntBig>, mpl::int_<OFTInteger64List> > - #endif + , mpl::pair<GIntBig, mpl::int_<OFTInteger64> > + , mpl::pair<std::vector<GIntBig>, mpl::int_<OFTInteger64List> > + // OFTBinary // OFTDate // OFTTime @@ -341,10 +340,8 @@ typedef mpl::map , 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_<OFTStringList>, StringListMemberGetterPtr<std::vector<std::string> > > - #ifdef OTB_USE_GDAL_20 , mpl::pair<mpl::int_<OFTInteger64>, MemberGetterPtr<GIntBig, &OGRFeature::GetFieldAsInteger64> > , mpl::pair<mpl::int_<OFTInteger64List>, MemberContainerGetterPtr<GIntBig, &OGRFeature::GetFieldAsInteger64List> > - #endif > FieldGetters_Map; /**\ingroup GeometryInternals @@ -360,10 +357,8 @@ typedef mpl::map , 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_<OFTStringList>, StringListMemberSetterPtr<std::vector<std::string> > > - #ifdef OTB_USE_GDAL_20 , mpl::pair<mpl::int_<OFTInteger64>, MemberSetterPtr<GIntBig, &OGRFeature::SetField> > , mpl::pair<mpl::int_<OFTInteger64List>, MemberContainerSetterPtr<const GIntBig, &OGRFeature::SetField> > - #endif > FieldSetters_Map; /**\ingroup GeometryInternals diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRHelpers.h b/Modules/Adapters/GdalAdapters/include/otbOGRHelpers.h index e693c942805efa8abfaed49e6cf12c77240e86a2..c490e9ce62204b80440594294c129ccaf5a9691b 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRHelpers.h +++ b/Modules/Adapters/GdalAdapters/include/otbOGRHelpers.h @@ -27,6 +27,7 @@ #include <cassert> #include <boost/range/begin.hpp> #include <boost/range/end.hpp> +#include "ogr_feature.h" #if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-local-typedefs" @@ -43,6 +44,8 @@ #include "OTBGdalAdaptersExport.h" +class GDALDataset; + namespace otb { namespace ogr @@ -105,6 +108,35 @@ private: 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 } // end namespace otb diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRLayerWrapper.h b/Modules/Adapters/GdalAdapters/include/otbOGRLayerWrapper.h index 880832a3dace41a2eb827857479fa9c23517d1da..7cce53313186f56794aef3ccec545542dbba5722 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRLayerWrapper.h +++ b/Modules/Adapters/GdalAdapters/include/otbOGRLayerWrapper.h @@ -36,7 +36,6 @@ #endif // #include "itkIndent.h", included from field #include "otbOGRFeatureWrapper.h" -#include "otbOGRVersionProxy.h" #include <string> // #include "ogr_core.h" // OGRwkbGeometryType, included from feature -> field @@ -119,7 +118,7 @@ public: * OGRDataSource::ExecuteSQL(). It's actually the constructor called by \c * DataSource::ExecuteSQL(). */ - Layer(OGRLayer* layer, otb::ogr::version_proxy::GDALDatasetType& sourceInChargeOfLifeTime, bool modifiable); + Layer(OGRLayer* layer, GDALDataset& sourceInChargeOfLifeTime, bool modifiable); //@} /**\name Features collection */ diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h b/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h deleted file mode 100644 index 7cae3f6dba4cf94203bfcb7e3cd52f431a5309c9..0000000000000000000000000000000000000000 --- a/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h +++ /dev/null @@ -1,230 +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 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 diff --git a/Modules/Adapters/GdalAdapters/src/CMakeLists.txt b/Modules/Adapters/GdalAdapters/src/CMakeLists.txt index 0f73c07a03e044b6c89d6a19b5df6fc6b9ae4851..b5d09907dbcbf31712526d4547566d76496c2595 100644 --- a/Modules/Adapters/GdalAdapters/src/CMakeLists.txt +++ b/Modules/Adapters/GdalAdapters/src/CMakeLists.txt @@ -28,8 +28,8 @@ set(OTBGdalAdapters_SRC otbOGRDriversInit.cxx otbGeometriesToGeometriesFilter.cxx otbOGRDataSourceWrapper.cxx - otbOGRVersionProxy.cxx otbOGRExtendedFilenameToOptions.cxx + otbOGRHelpers.cxx ) add_library(OTBGdalAdapters ${OTBGdalAdapters_SRC}) diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx index ea65a5c2c577a97ed2f967418816ac2b1a17a6d0..b415ed076f8191211200d0f3552da1f3f230d4c1 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx @@ -48,13 +48,13 @@ bool otb::ogr::DataSource::Clear() return true; } -void otb::ogr::DataSource::Reset(otb::ogr::version_proxy::GDALDatasetType * source) +void otb::ogr::DataSource::Reset(GDALDataset * source) { if (m_DataSource) { // OGR makes a pointless check for non-nullity in // GDALDataset::DestroyDataSource (pointless because "delete 0" is // perfectly valid -> it's a no-op) - ogr::version_proxy::Close(m_DataSource); // void, noexcept + GDALClose(m_DataSource); // void, noexcept } m_DataSource = source; } @@ -108,7 +108,7 @@ char const* DeduceDriverName(std::string filename) ExtensionDriverAssociation const* whichIt = std::find_if( 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)) { return nullptr; // nothing found @@ -126,10 +126,16 @@ otb::ogr::DataSource::DataSource() { Drivers::Init(); - ogr::version_proxy::GDALDriverType * d = - ogr::version_proxy::GetDriverByName("Memory"); + GDALDriver * d = + GetGDALDriverManager()->GetDriverByName("Memory"); 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) { itkExceptionMacro(<< "Failed to create OGRMemDataSource: " << CPLGetLastErrorMsg()); @@ -137,7 +143,7 @@ otb::ogr::DataSource::DataSource() } otb::ogr::DataSource::DataSource( - otb::ogr::version_proxy::GDALDatasetType * source , + GDALDataset * source , Modes::type mode , const std::vector< std::string > & options /*NULL*/ ) : m_DataSource(source) , @@ -155,10 +161,12 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c std::string simpleFileName = fileNameHelper->GetSimpleFileName(); bool update = (mode != Modes::Read); - ogr::version_proxy::GDALDatasetType * source = - ogr::version_proxy::Open( simpleFileName.c_str() , - !update , - fileNameHelper->GetGDALOpenOptions() ); + GDALDataset * source = (GDALDataset *)GDALOpenEx( + simpleFileName.c_str(), + (update? GDAL_OF_UPDATE: GDAL_OF_READONLY) | GDAL_OF_VECTOR, + NULL, + otb::ogr::StringListConverter( fileNameHelper->GetGDALOpenOptions() ).to_ogr(), + NULL); if (!source) { // In read mode, this is a failure @@ -178,8 +186,8 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c <<simpleFileName<<">."); } - ogr::version_proxy::GDALDriverType * d = - ogr::version_proxy::GetDriverByName( driverName ); + GDALDriver * d = + GetGDALDriverManager()->GetDriverByName( driverName ); if(!d) { @@ -187,10 +195,13 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c << ", check your OGR configuration for available drivers." ); } - source = ogr::version_proxy::Create( - d , - simpleFileName.c_str() , - fileNameHelper->GetGDALCreationOptions() ); + source = d->Create( simpleFileName.c_str() , + 0 , + 0 , + 0 , + GDT_Unknown , + otb::ogr::StringListConverter( + fileNameHelper->GetGDALCreationOptions() ).to_ogr() ); if (!source) { itkGenericExceptionMacro(<< "Failed to create GDALDataset <" << simpleFileName << "> (driver name: <" << driverName @@ -207,12 +218,41 @@ void DeleteDataSource(std::string const& datasourceName) fileNameHelper->SetExtendedFileName( datasourceName.c_str() ); std::string simpleFileName = fileNameHelper->GetSimpleFileName(); - bool ret = otb::ogr::version_proxy::Delete(simpleFileName.c_str()); - if (!ret) + // Open dataset + 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()); + } + } + else + { + itkGenericExceptionMacro(<< "Cannot get driver associated with data source " << simpleFileName + << ": " << CPLGetLastErrorMsg()); } + } otb::ogr::DataSource::Pointer @@ -228,12 +268,15 @@ otb::ogr::DataSource::New(std::string const& datasourceName, Modes::type mode) } Drivers::Init(); - ogr::version_proxy::GDALDatasetType * ds = - ogr::version_proxy::Open( simpleFileName.c_str() , true ); - + GDALDataset * ds = (GDALDataset *)GDALOpenEx( + simpleFileName.c_str(), + GDAL_OF_READONLY | GDAL_OF_VECTOR, + NULL, + NULL, + NULL); bool ds_exists = (ds!=nullptr); - ogr::version_proxy::Close(ds); + GDALClose(ds); if (ds_exists && mode == Modes::Overwrite) @@ -246,7 +289,7 @@ otb::ogr::DataSource::New(std::string const& datasourceName, Modes::type mode) /*static*/ otb::ogr::DataSource::Pointer -otb::ogr::DataSource::New(otb::ogr::version_proxy::GDALDatasetType * source , Modes::type mode , const std::vector< std::string > & layerOptions ) +otb::ogr::DataSource::New(GDALDataset * source , Modes::type mode , const std::vector< std::string > & layerOptions ) { Pointer res = new DataSource( source , mode , layerOptions ); res->UnRegister(); @@ -727,12 +770,7 @@ OGREnvelope otb::ogr::DataSource::GetGlobalExtent(bool force/* = false */, std:: cExtent.MaxX = real_maxx; cExtent.MaxY = real_maxy; -#if GDAL_VERSION_NUM >= 1700 OGRCoordinateTransformation::DestroyCT(coordTransformation); -#else -#warning the following resource release may crash, please update your version of GDAL - delete coordTransformation; // note there is no garanty -#endif } // else: If srs are invalid, we assume that extent are coherent @@ -785,20 +823,14 @@ bool otb::ogr::DataSource::HasCapability(std::string const& capabilityName) cons void otb::ogr::DataSource::SyncToDisk() { assert(m_DataSource && "Datasource not initialized"); - bool ret = otb::ogr::version_proxy::SyncToDisk(m_DataSource); - - if(!ret) - { - itkExceptionMacro( << "Cannot flush the pending of the OGRDataSource <" - << GetDatasetDescription() << ">: " << CPLGetLastErrorMsg()); - } + m_DataSource->FlushCache(); } std::string otb::ogr::DataSource::GetDatasetDescription() const { std::vector<std::string> files = - otb::ogr::version_proxy::GetFileListAsStringVector( m_DataSource ); + otb::ogr::GetFileListAsStringVector( m_DataSource ); std::string description = ""; for( std::vector<std::string>::const_iterator it = files.begin() ; it!=files.end() ; ++it ) diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRFeatureWrapper.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRFeatureWrapper.cxx index 8c4abc16a33d819ed4c700221fd8007972eb887e..20cb96ce876236d6b1384daf42a7b9659ddd7c47 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRFeatureWrapper.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRFeatureWrapper.cxx @@ -43,7 +43,7 @@ otb::ogr::Feature::Feature(OGRFeatureDefn & definition) : m_Feature( OGRFeature::CreateFeature(&definition), - boost::bind(&OGRFeature::DestroyFeature, _1)) + [&](auto const & x) {return OGRFeature::DestroyFeature(x);}) { CheckInvariants(); } @@ -52,7 +52,7 @@ otb::ogr::Feature::Feature(OGRFeature * feature) { if (feature) { - m_Feature.reset(feature, boost::bind(&OGRFeature::DestroyFeature, _1)); + m_Feature.reset(feature, [&](auto const & x) {return OGRFeature::DestroyFeature(x);}); } // else default is perfect -> delete null } @@ -78,16 +78,11 @@ void otb::ogr::Feature::UncheckedSetFrom(Feature const& rhs, bool mustForgive) void otb::ogr::Feature::UncheckedSetFrom(Feature const& rhs, int * map, bool mustForgive) { -#if GDAL_VERSION_NUM >= 1900 const OGRErr res = m_Feature->SetFrom(&rhs.ogr(), map, mustForgive); if (res != OGRERR_NONE) { itkGenericExceptionMacro(<<"Cannot assign from another feature: " << CPLGetLastErrorMsg()); } -#else - itkGenericExceptionMacro("OGRLayer::SetFrom(feature, fieldmap, forgive) is not supported by OGR v" - << GDAL_VERSION_NUM << ". Upgrade to a version >= 1.9.0, and recompile OTB.") -#endif } /*===========================================================================*/ diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRFieldWrapper.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRFieldWrapper.cxx index 49f95f053546c6f59190ef88ae6d28cee0f19110..7bf292e9015bb3de1c4d51f109840300014a0acc 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRFieldWrapper.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRFieldWrapper.cxx @@ -37,7 +37,6 @@ #endif #include "otbOGRFeatureWrapper.h" #include "otbJoinContainer.h" -#include "otbOGRVersionProxy.h" #include <boost/array.hpp> /*===========================================================================*/ /*===========================[ Static Assertions ]===========================*/ @@ -167,7 +166,7 @@ std::ostream & otb::ogr::Field::UncheckedPrintSelf( bool otb::ogr::Field::UncheckedHasBeenSet() const { - return otb::ogr::version_proxy::IsFieldSetAndNotNull(m_Feature.get(), m_index); + return otb::ogr::IsFieldSetAndNotNull(m_Feature.get(), m_index); } void otb::ogr::Field::UncheckedUnset() const diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRGeometryWrapper.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRGeometryWrapper.cxx index 740aaa766a3f496fde86fc59d33a780d089494a9..ad03e5a2be515641a45ee6c0e1c247d55bebd8e8 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRGeometryWrapper.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRGeometryWrapper.cxx @@ -25,10 +25,6 @@ #include "otbOGRGeometryWrapper.h" #include "ogr_geometry.h" -#if GDAL_VERSION_NUM < 1900 -# include "itkMacro.h" -#endif - #ifdef _MSC_VER // warning conversion int -> bool #pragma warning ( disable : 4800 ) @@ -105,12 +101,7 @@ otb::ogr::UniqueGeometryPtr otb::ogr::Union(OGRGeometry const& lhs, OGRGeometry otb::ogr::UniqueGeometryPtr otb::ogr::UnionCascaded(OGRGeometry const& this_) { -#if GDAL_VERSION_NUM >= 1800 return UniqueGeometryPtr(this_.UnionCascaded()); -#else - itkGenericExceptionMacro("OGRGeometry::UnionCascaded is not supported by OGR v" - << GDAL_VERSION_NUM << ". Upgrade to a version >= 1.8.0, and recompile OTB."); -#endif } otb::ogr::UniqueGeometryPtr otb::ogr::Difference(OGRGeometry const& lhs, OGRGeometry const& rhs) @@ -120,41 +111,20 @@ otb::ogr::UniqueGeometryPtr otb::ogr::Difference(OGRGeometry const& lhs, OGRGeom otb::ogr::UniqueGeometryPtr otb::ogr::SymDifference(OGRGeometry const& lhs, OGRGeometry const& rhs) { -#if GDAL_VERSION_NUM >= 1800 return UniqueGeometryPtr(lhs.SymDifference(&rhs)); -#else - return UniqueGeometryPtr(lhs.SymmetricDifference(&rhs)); -#endif } otb::ogr::UniqueGeometryPtr otb::ogr::SimplifyDontPreserveTopology(OGRGeometry const& g, double tolerance) { -#if GDAL_VERSION_NUM >= 1800 return UniqueGeometryPtr(g.Simplify(tolerance)); -#else - itkGenericExceptionMacro("OGRGeometry::Simplify is not supported by OGR v" - << GDAL_VERSION_NUM << ". Upgrade to a version >= 1.8.0, and recompile OTB."); -#endif } otb::ogr::UniqueGeometryPtr otb::ogr::SimplifyPreserveTopology(OGRGeometry const& g, double tolerance) { -#if GDAL_VERSION_NUM >= 1900 return UniqueGeometryPtr(g.SimplifyPreserveTopology(tolerance)); -#else - itkGenericExceptionMacro("OGRGeometry::Simplify is not supported by OGR v" - << GDAL_VERSION_NUM << ". Upgrade to a version >= 1.9.0, and recompile OTB."); -#endif } otb::ogr::UniqueGeometryPtr otb::ogr::Simplify(OGRGeometry const& g, double tolerance) { -#if GDAL_VERSION_NUM >= 1900 return UniqueGeometryPtr(g.SimplifyPreserveTopology(tolerance)); -#elif GDAL_VERSION_NUM >= 1800 - return UniqueGeometryPtr(g.Simplify(tolerance)); -#else - itkGenericExceptionMacro("OGRGeometry::Simplify(PreserveTopology) is not supported by OGR v" - << GDAL_VERSION_NUM << ". Upgrade to a version >= 1.9.0, and recompile OTB."); -#endif } diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRHelpers.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRHelpers.cxx new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e064520c19b355cf76f6f4d787b0ff5e8031 --- /dev/null +++ b/Modules/Adapters/GdalAdapters/src/otbOGRHelpers.cxx @@ -0,0 +1,108 @@ +/* + * 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 "otbOGRHelpers.h" + +#if defined(__GNUC__) || defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wshadow" +#include "gdal_priv.h" +#include "ogr_feature.h" +#pragma GCC diagnostic pop +#else +#include "gdal_priv.h" +#include "ogr_feature.h" +#endif // __GNUC__ || __clang__ + +namespace otb +{ +namespace ogr +{ + +std::vector<std::string> GetAvailableDriversAsStringVector() +{ + std::vector<std::string> ret; + + int nbDrivers = GetGDALDriverManager()->GetDriverCount(); + + for(int i = 0; i < nbDrivers;++i) + { + ret.push_back(GDALGetDriverShortName(GetGDALDriverManager()->GetDriver(i))); + } + return ret; +} + +namespace raii +{ +// This class is used in the next function, so as to prevent any +// resource leak on char ** returned by dataset->GetFileList() +class CharPPCapsule +{ +public: + CharPPCapsule(char ** in) + : m_P(in) + {} + + const char ** P() const + { + return const_cast<const char **>(m_P); + } + + ~CharPPCapsule() + { + if(m_P) + CSLDestroy(m_P); + } + +private: + char ** m_P; +}; +} + +std::vector<std::string> GetFileListAsStringVector(GDALDataset * dataset) +{ + std::vector<std::string> ret; + raii::CharPPCapsule capsule(dataset->GetFileList()); + std::string files_str=""; + + if(capsule.P()) + { + unsigned int i = 0; + while(capsule.P()[i]!=NULL) + { + ret.push_back(std::string(capsule.P()[i])); + ++i; + } + } + return ret; +} + +/*----------------------[GDAL 2.2 change on IsFieldSet()]---------------------*/ +bool IsFieldSetAndNotNull(OGRFeature *feat, int index) +{ +#if GDAL_VERSION_NUM<2020000 + return feat->IsFieldSet(index); +#else + return feat->IsFieldSetAndNotNull(index); +#endif +} + +} +} // end namespaces \ No newline at end of file diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRLayerWrapper.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRLayerWrapper.cxx index 4a9596a021a1fc4eb876508084a13a77e2a3722b..ff0d528171aceda6bb2164576e62ab7316d0437e 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRLayerWrapper.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRLayerWrapper.cxx @@ -69,8 +69,8 @@ otb::ogr::Layer::Layer(OGRLayer* layer, bool modifiable) { } -otb::ogr::Layer::Layer(OGRLayer* layer, otb::ogr::version_proxy::GDALDatasetType& sourceInChargeOfLifeTime, bool modifiable) -: m_Layer(layer, boost::bind(&otb::ogr::version_proxy::GDALDatasetType::ReleaseResultSet, boost::ref(sourceInChargeOfLifeTime), _1)) +otb::ogr::Layer::Layer(OGRLayer* layer, GDALDataset& sourceInChargeOfLifeTime, bool modifiable) +: m_Layer(layer, [&](auto const& x) { return sourceInChargeOfLifeTime.ReleaseResultSet(x); }) , m_Modifiable(modifiable) { assert(layer && "A null OGRlayer cannot belong to an OGRDataSource" ); @@ -192,11 +192,7 @@ void otb::ogr::Layer::SetFeature(Feature feature) std::string otb::ogr::Layer::GetName() const { assert(m_Layer && "null layer"); -#if GDAL_VERSION_NUM >= 1800 return m_Layer->GetName(); -#else - return GetLayerDefn().GetName(); -#endif } OGREnvelope otb::ogr::Layer::GetExtent(bool force/* = false */) const @@ -339,17 +335,12 @@ void otb::ogr::Layer::DeleteField(int fieldIndex) <<GetName()<<">: layer is not modifiable"); } -#if GDAL_VERSION_NUM < 1900 - itkGenericExceptionMacro("OGRLayer::DeleteField is not supported by OGR v" - << GDAL_VERSION_NUM << ". Upgrade to a version >= 1.9.0, and recompile OTB.") -#else const OGRErr res = m_Layer->DeleteField(fieldIndex); if (res != OGRERR_NONE) { itkGenericExceptionMacro(<< "Cannot delete the "<<fieldIndex << "th field in the layer <" <<GetName() <<">: " << CPLGetLastErrorMsg()); } -#endif } void otb::ogr::Layer::AlterFieldDefn( @@ -363,10 +354,6 @@ void otb::ogr::Layer::AlterFieldDefn( <<GetName()<<">: layer is not modifiable"); } -#if GDAL_VERSION_NUM < 1900 - itkGenericExceptionMacro("OGRLayer::AlterFieldDefn is not supported by OGR v" - << GDAL_VERSION_NUM << ". Upgrade to a version >= 1.9.0, and recompile OTB.") -#else const OGRErr res = m_Layer->AlterFieldDefn( int(fieldIndex), &newFieldDefn.ogr(), @@ -376,7 +363,6 @@ void otb::ogr::Layer::AlterFieldDefn( itkGenericExceptionMacro(<< "Cannot alter the "<<fieldIndex << "th field in the layer <" <<GetName() <<">: " << CPLGetLastErrorMsg()); } -#endif } void otb::ogr::Layer::ReorderField(size_t oldPos, size_t newPos) @@ -389,17 +375,12 @@ void otb::ogr::Layer::ReorderField(size_t oldPos, size_t newPos) <<GetName()<<">: layer is not modifiable"); } -#if GDAL_VERSION_NUM < 1900 - itkGenericExceptionMacro("OGRLayer::ReorderField is not supported by OGR v" - << GDAL_VERSION_NUM << ". Upgrade to a version >= 1.9.0, and recompile OTB.") -#else const OGRErr res = m_Layer->ReorderField(int(oldPos), int(newPos)); if (res != OGRERR_NONE) { itkGenericExceptionMacro(<< "Cannot move the "<<oldPos << "th field to the " << newPos << "th position in the layer <" <<GetName() <<">: " << CPLGetLastErrorMsg()); } -#endif } void otb::ogr::Layer::ReorderFields(int * map) @@ -412,42 +393,28 @@ void otb::ogr::Layer::ReorderFields(int * map) <<GetName()<<">: layer is not modifiable"); } -#if GDAL_VERSION_NUM < 1900 - itkGenericExceptionMacro("OGRLayer::ReorderField is not supported by OGR v" - << GDAL_VERSION_NUM << ". Upgrade to a version >= 1.9.0, and recompile OTB.") -#else const OGRErr res = m_Layer->ReorderFields(map); if (res != OGRERR_NONE) { itkGenericExceptionMacro(<< "Cannot reorder the fields of the layer <" <<GetName() <<">: " << CPLGetLastErrorMsg()); } -#endif } void otb::ogr::Layer::SetIgnoredFields(char const** fieldNames) { assert(m_Layer && "OGRLayer not initialized"); -#if GDAL_VERSION_NUM >= 1900 const OGRErr res = m_Layer->SetIgnoredFields(fieldNames); if (res != OGRERR_NONE) { itkGenericExceptionMacro(<< "Cannot set fields to ignore on the layer <" <<GetName() <<">: " << CPLGetLastErrorMsg()); } -#else - itkGenericExceptionMacro("OGRLayer::SetIgnoredFields is not supported by OGR v" - << GDAL_VERSION_NUM << ". Upgrade to a version >= 1.9.0, and recompile OTB.") -#endif } OGRwkbGeometryType otb::ogr::Layer::GetGeomType() const { assert(m_Layer && "OGRLayer not initialized"); -#if GDAL_VERSION_NUM < 1800 - return GetLayerDefn().GetGeomType(); -#else return m_Layer->GetGeomType(); -#endif } diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy.cxx deleted file mode 100644 index b616fe752698e68c3731b5ef6bf822802468a33c..0000000000000000000000000000000000000000 --- a/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy.cxx +++ /dev/null @@ -1,267 +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 "otbOGRVersionProxy.h" -#include "otbOGRHelpers.h" - -#include "itkMacro.h" - -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wshadow" -#if GDAL_VERSION_NUM<2000000 -#include "ogrsf_frmts.h" -#else -#include "gdal_priv.h" -#endif -#include "ogr_feature.h" -#pragma GCC diagnostic pop -#else -#if GDAL_VERSION_NUM<2000000 -#include "ogrsf_frmts.h" -#else -#include "gdal_priv.h" -#endif -#include "ogr_feature.h" -#endif // __GNUC__ || __clang__ - -namespace otb -{ -namespace ogr -{ -namespace version_proxy -{ - -/*-------------------------[GDAL v2 API change]-------------------------------*/ -OTBGdalAdapters_EXPORT bool IsOFTInteger64(OGRFieldType type) -{ -#if GDAL_VERSION_NUM<2000000 - (void)type; - return false; -#else - return type == OFTInteger64; -#endif -} - - -GDALDatasetType * Open(const char * filename, bool readOnly , std::vector< std::string > const & options ) -{ -#if GDAL_VERSION_NUM<2000000 - (void)options; - return OGRSFDriverRegistrar::Open(filename,!readOnly); -#else - return (GDALDatasetType *)GDALOpenEx( - filename, - (readOnly? GDAL_OF_READONLY : GDAL_OF_UPDATE) | GDAL_OF_VECTOR, - NULL, - otb::ogr::StringListConverter( options ).to_ogr(), - NULL); -#endif -} - -void Close(GDALDatasetType * dataset) -{ -#if GDAL_VERSION_NUM<2000000 - OGRDataSource::DestroyDataSource(dataset); -#else - GDALClose(dataset); -#endif -} - -GDALDatasetType * Create(GDALDriverType * driver, const char * name , std::vector< std::string > const & options ) -{ -#if GDAL_VERSION_NUM<2000000 - (void)options; - GDALDatasetType * ds = driver->CreateDataSource(name); - - if(ds) - ds->SetDriver(driver); - - return ds; -#else - return driver->Create( name , - 0 , - 0 , - 0 , - GDT_Unknown , - otb::ogr::StringListConverter( options ).to_ogr() ); -#endif -} - -bool Delete(const char * name) -{ - // Open dataset - GDALDatasetType * poDS = otb::ogr::version_proxy::Open(name,false); - GDALDriverType * poDriver = NULL; - if(poDS) - { - poDriver = poDS->GetDriver(); - Close(poDS); - } -#if GDAL_VERSION_NUM<2000000 - if(poDriver && poDriver->TestCapability(ODrCDeleteDataSource)) - { - OGRErr ret = poDriver->DeleteDataSource(name); - return (ret == OGRERR_NONE); - } -#else - if(poDriver) - { - OGRErr ret = poDriver->Delete(name); - return (ret == OGRERR_NONE); - } -#endif - return false; -} - -GDALDriverType * GetDriverByName(const char * name) -{ -#if GDAL_VERSION_NUM<2000000 - return OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName(name); -#else - return GetGDALDriverManager()->GetDriverByName(name); -#endif -} - -std::string GetDatasetClassName() -{ -#if GDAL_VERSION_NUM<2000000 - return std::string("OGRDataSource"); -#else - return std::string("GDALDataset"); -#endif -} - -std::string GetDriverClassName() -{ -#if GDAL_VERSION_NUM<2000000 - return std::string("OGRSFDriver"); -#else - return std::string("GDALDriver"); -#endif -} - -#if GDAL_VERSION_NUM>=2000000 -namespace raii -{ -// This class is used in the next function, so as to prevent any -// resource leak on char ** returned by dataset->GetFileList() -class CharPPCapsule -{ -public: - CharPPCapsule(char ** in) - : m_P(in) - {} - - const char ** P() const - { - return const_cast<const char **>(m_P); - } - - ~CharPPCapsule() - { - if(m_P) - CSLDestroy(m_P); - } - -private: - char ** m_P; -}; -} -#endif - -std::vector<std::string> GetFileListAsStringVector(GDALDatasetType * dataset) -{ - std::vector<std::string> ret; -#if GDAL_VERSION_NUM<2000000 - ret.push_back(std::string(dataset->GetName())); -#else - raii::CharPPCapsule capsule(dataset->GetFileList()); - - std::string files_str=""; - - if(capsule.P()) - { - unsigned int i = 0; - while(capsule.P()[i]!=NULL) - { - ret.push_back(std::string(capsule.P()[i])); - ++i; - } - } -#endif - return ret; -} - -bool SyncToDisk(GDALDatasetType * dataset) -{ -#if GDAL_VERSION_NUM<2000000 - const OGRErr res= dataset->SyncToDisk(); - return (res == OGRERR_NONE); -#else - dataset->FlushCache(); - return true; -#endif -} - -std::vector<std::string> GetAvailableDriversAsStringVector() -{ - std::vector<std::string> ret; -#if GDAL_VERSION_NUM<2000000 - int nbDrivers = OGRSFDriverRegistrar::GetRegistrar()->GetDriverCount(); - - for(int i = 0; i < nbDrivers;++i) - { - ret.push_back(OGRSFDriverRegistrar::GetRegistrar()->GetDriver(i)->GetName()); - } -#else - int nbDrivers = GetGDALDriverManager()->GetDriverCount(); - - for(int i = 0; i < nbDrivers;++i) - { - ret.push_back(GDALGetDriverShortName(GetGDALDriverManager()->GetDriver(i))); - } -#endif - return ret; -} - -std::string GetDriverNameFromDataSource(const GDALDatasetType * ds) -{ -#if GDAL_VERSION_NUM<2000000 - return std::string(const_cast<GDALDatasetType *>(ds)->GetDriver()->GetName()); -#else - return std::string(const_cast<GDALDatasetType *>(ds)->GetDriverName()); -#endif -} - -/*----------------------[GDAL 2.2 change on IsFieldSet()]---------------------*/ -bool IsFieldSetAndNotNull(OGRFeature *feat, int index) -{ -#if GDAL_VERSION_NUM<2020000 - return feat->IsFieldSet(index); -#else - return feat->IsFieldSetAndNotNull(index); -#endif -} - -} -} -} // end namespace - diff --git a/Modules/Adapters/GdalAdapters/test/otbOGRDataSourceWrapperNew.cxx b/Modules/Adapters/GdalAdapters/test/otbOGRDataSourceWrapperNew.cxx index 791733d41d40d2e558831a4b04b3c18d91d4badc..4dccbdd0b96d0a43c18937b8af73785ca6595f98 100644 --- a/Modules/Adapters/GdalAdapters/test/otbOGRDataSourceWrapperNew.cxx +++ b/Modules/Adapters/GdalAdapters/test/otbOGRDataSourceWrapperNew.cxx @@ -681,7 +681,6 @@ BOOST_AUTO_TEST_CASE(Add_n_Del_Fields) BOOST_CHECK_EQUAL(defn.GetFieldDefn(6), (void*)nullptr); } -#if GDAL_VERSION_NUM >= 1900 l.DeleteField(1); BOOST_CHECK_EQUAL(defn.GetFieldCount(), 5); @@ -697,7 +696,6 @@ BOOST_AUTO_TEST_CASE(Add_n_Del_Fields) ogr::FieldDefn f4(*defn.GetFieldDefn(4)); BOOST_CHECK_EQUAL(f4, k_f5); } -#endif // todo: add reoder tests } @@ -725,9 +723,7 @@ BOOST_AUTO_TEST_CASE(Add_n_Read_Fields) // ----[ int ogr::Field f0 = g0[0]; -#if GDAL_VERSION_NUM >= 1800 BOOST_CHECK_EQUAL(f0.GetName(), k_f0.GetName()); -#endif f0.SetValue(42); BOOST_ASSERT(f0.HasBeenSet()); BOOST_CHECK_EQUAL(f0.GetValue<int>(), 42); @@ -737,9 +733,7 @@ BOOST_AUTO_TEST_CASE(Add_n_Read_Fields) // ----[ double ogr::Field f1 = g0["OFTReal"]; -#if GDAL_VERSION_NUM >= 1800 BOOST_CHECK_EQUAL(f1.GetName(), k_f1.GetName()); -#endif // f1.SetValue(42); // need to support types promotion f1.SetValue(42.0); // need to support types promotion BOOST_ASSERT(f1.HasBeenSet()); @@ -747,9 +741,7 @@ BOOST_AUTO_TEST_CASE(Add_n_Read_Fields) // ----[ string ogr::Field f2 = g0["OFTString"]; -#if GDAL_VERSION_NUM >= 1800 BOOST_CHECK_EQUAL(f2.GetName(), k_f2.GetName()); -#endif f2.SetValue(("foobar")); // need to support types promotion BOOST_ASSERT(f2.HasBeenSet()); BOOST_CHECK_EQUAL(f2.GetValue<std::string>(), "foobar"); diff --git a/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx b/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx index da9a2e3c48c9d2f36d40fdca08f05bcb26dd27f5..f2a87a11617a8d47812153f7285047b133eb7094 100644 --- a/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx +++ b/Modules/Applications/AppClassification/app/otbComputeConfusionMatrix.cxx @@ -204,7 +204,7 @@ private: OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); - if(fieldType == OFTString || fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64(fieldType)) + if(fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64) { std::string tmpKey="ref.vector.field."+key.substr(0, end - key.begin()); AddChoice(tmpKey,item); diff --git a/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx b/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx index 4dd494df258f41328bd48fa0b959a40923670fb9..2134db123a5fbff6425004aec2bb19aba0722dca 100644 --- a/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx +++ b/Modules/Applications/AppClassification/app/otbPolygonClassStatistics.cxx @@ -148,7 +148,7 @@ private: OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); - if(fieldType == OFTString || fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64(fieldType)) + if(fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64) { std::string tmpKey="field."+key.substr(0, end - key.begin()); AddChoice(tmpKey,item); diff --git a/Modules/Applications/AppClassification/app/otbSampleAugmentation.cxx b/Modules/Applications/AppClassification/app/otbSampleAugmentation.cxx index e36e22b8b2e97f0291559ef5a1a2d6b7a2fcaafb..dd6e4b67a9fe04dab5679965cde7b6df5a42d4aa 100644 --- a/Modules/Applications/AppClassification/app/otbSampleAugmentation.cxx +++ b/Modules/Applications/AppClassification/app/otbSampleAugmentation.cxx @@ -167,7 +167,7 @@ private: OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); - if(fieldType == OFTString || fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64(fieldType)) + if(fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64) { std::string tmpKey="field."+key.substr(0, end - key.begin()); AddChoice(tmpKey,item); diff --git a/Modules/Applications/AppClassification/app/otbSampleExtraction.cxx b/Modules/Applications/AppClassification/app/otbSampleExtraction.cxx index 2c48308344b02b27744c3c362a07603ceb348c47..9a0741d46cbc81ed060d9d8a06d3dad85a32a6c9 100644 --- a/Modules/Applications/AppClassification/app/otbSampleExtraction.cxx +++ b/Modules/Applications/AppClassification/app/otbSampleExtraction.cxx @@ -140,7 +140,7 @@ private: OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); - if(fieldType == OFTString || fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64(fieldType)) + if(fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64) { std::string tmpKey="field."+key.substr(0, end - key.begin()); AddChoice(tmpKey,item); diff --git a/Modules/Applications/AppClassification/app/otbSampleSelection.cxx b/Modules/Applications/AppClassification/app/otbSampleSelection.cxx index 531203f01ad2bb64c651c860831728e496193bdd..823a95d70eba2ba067437e777bafe420eaefa946 100644 --- a/Modules/Applications/AppClassification/app/otbSampleSelection.cxx +++ b/Modules/Applications/AppClassification/app/otbSampleSelection.cxx @@ -248,7 +248,7 @@ private: OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(iField)->GetType(); - if(fieldType == OFTString || fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64(fieldType)) + if(fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64) { std::string tmpKey="field."+key.substr(0, end - key.begin()); AddChoice(tmpKey,item); diff --git a/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx b/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx index 286b6b0dd7d6cf89f55e9c942d73df988dbe7114..d101d983de3410bb1d347e9f03888ff30fe995dd 100644 --- a/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx +++ b/Modules/Applications/AppClassification/app/otbVectorClassifier.cxx @@ -183,7 +183,7 @@ private: std::transform(key.begin(), key.end(), key.begin(), tolower); OGRFieldType fieldType = layerDefn.GetFieldDefn(iField)->GetType(); - if(fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64(fieldType) || fieldType == OFTReal) + if(fieldType == OFTInteger || fieldType == OFTInteger64 || fieldType == OFTReal) { std::string tmpKey="feat."+key; AddChoice(tmpKey,item); diff --git a/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx b/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx index 588e07ae8a51d609aedd7f9834ca10ff029c26a5..3b4fcd115491e0ffd231e0f809cc624cbea949c7 100644 --- a/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx +++ b/Modules/Applications/AppClassification/include/otbTrainVectorBase.hxx @@ -131,12 +131,12 @@ void TrainVectorBase::DoUpdateParameters() OGRFieldType fieldType = feature.ogr().GetFieldDefnRef( iField )->GetType(); - if( fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64( fieldType ) || fieldType == OFTReal ) + if( fieldType == OFTInteger || fieldType == OFTInteger64 || fieldType == OFTReal ) { std::string tmpKey = "feat." + key.substr( 0, static_cast<unsigned long>( end - key.begin() ) ); AddChoice( tmpKey, item ); } - if( fieldType == OFTString || fieldType == OFTInteger || ogr::version_proxy::IsOFTInteger64( fieldType ) ) + if( fieldType == OFTString || fieldType == OFTInteger || fieldType == OFTInteger64 ) { std::string tmpKey = "cfield." + key.substr( 0, static_cast<unsigned long>( end - key.begin() ) ); AddChoice( tmpKey, item ); diff --git a/Modules/Applications/AppSegmentation/app/otbSegmentation.cxx b/Modules/Applications/AppSegmentation/app/otbSegmentation.cxx index cbb87ed79d6194b36da369c69a8d7f7548088026..b49467c19ba962aa1c5d97730bd75600084cbf91 100644 --- a/Modules/Applications/AppSegmentation/app/otbSegmentation.cxx +++ b/Modules/Applications/AppSegmentation/app/otbSegmentation.cxx @@ -689,7 +689,7 @@ private: //Note : the GetDriver() Method has not been encapsulated in otb::ogr::DataSource, //so we must access the OGR pointer by using .ogr() - std::string driverName(otb::ogr::version_proxy::GetDriverNameFromDataSource(&ogrDS->ogr())); + std::string driverName(ogrDS->ogr().GetDriverName()); if ( driverName.find("ESRI Shapefile") != std::string::npos) { otbAppLogINFO(<<"REPACK the Shapefile ..."<<std::endl); diff --git a/Modules/Core/Common/otb-module.cmake b/Modules/Core/Common/otb-module.cmake index b3276d69422b566872290eba6a5d817cb2b45be1..7f1468126675bea77c61e159711239a1a7be2f2d 100644 --- a/Modules/Core/Common/otb-module.cmake +++ b/Modules/Core/Common/otb-module.cmake @@ -25,7 +25,6 @@ ENABLE_SHARED DEPENDS OTBBoost OTBITK - #Add dependency to OTBGDAL as GDAL module need to set OTB_USE_GDAL_20 before configuring otbConfigure.h OTBGDAL #Add dependency for extended filename helper class OTBBoostAdapters diff --git a/Modules/Core/Common/src/otbConfigure.h.in b/Modules/Core/Common/src/otbConfigure.h.in index 2146cf15bffa6fdb90e30c766a9f3f483263944e..f93fa266c56946791f42aa09e7d8bb63a14fe62a 100644 --- a/Modules/Core/Common/src/otbConfigure.h.in +++ b/Modules/Core/Common/src/otbConfigure.h.in @@ -27,8 +27,6 @@ #cmakedefine OTB_BUILD_SHARED_LIBS -#cmakedefine OTB_USE_GDAL_20 - #cmakedefine OTB_USE_OPENMP #cmakedefine OTB_USE_SSE_FLAGS diff --git a/Modules/Core/VectorDataBase/src/otbVectorDataKeywordlist.cxx b/Modules/Core/VectorDataBase/src/otbVectorDataKeywordlist.cxx index 39c3623e1a122bb187ab1f8b7c198af3d8098610..c14f3dda5a992d70dc68e4bfa6a62a56103cdf88 100644 --- a/Modules/Core/VectorDataBase/src/otbVectorDataKeywordlist.cxx +++ b/Modules/Core/VectorDataBase/src/otbVectorDataKeywordlist.cxx @@ -106,14 +106,12 @@ VectorDataKeywordlist ss << std::setprecision(15) << m_FieldList[i].second.Integer; return ss.str(); } -#ifdef OTB_USE_GDAL_20 case OFTInteger64: { std::ostringstream ss; ss << std::setprecision(15) << m_FieldList[i].second.Integer64; return ss.str(); } -#endif case OFTReal: { std::ostringstream ss; @@ -183,7 +181,6 @@ VectorDataKeywordlist { return (int)(m_FieldList[i].second.Integer); } -#ifdef OTB_USE_GDAL_20 // Some fields that were OFTInteger with gdal 1.x are now // exposed as OFTInteger64. So as to make the old code still // work with the same data, here we downcast to Integer (if @@ -197,7 +194,6 @@ VectorDataKeywordlist return static_cast<int>(m_FieldList[i].second.Integer64); } -#endif case OFTReal: { return (int)(m_FieldList[i].second.Real); @@ -483,13 +479,11 @@ VectorDataKeywordlist << field.second.Date.Hour << field.second.Date.Minute << field.second.Date.Second; break; } -#ifdef OTB_USE_GDAL_20 case OFTInteger64: { output << std::setprecision(15)<<field.second.Integer64; break; } -#endif default: output << "Type not handled for printing"; break; @@ -511,13 +505,11 @@ VectorDataKeywordlist outField.second.Integer = field.second.Integer; break; } -#ifdef OTB_USE_GDAL_20 case OFTInteger64: { outField.second.Integer64 = field.second.Integer64; break; } -#endif case OFTReal: { outField.second.Real = field.second.Real; diff --git a/Modules/IO/IOGDAL/include/otbOGRIOHelper.h b/Modules/IO/IOGDAL/include/otbOGRIOHelper.h index 67b5e19778378afc4ed1a95e26a809f13c84358a..5427f030c6cbd786a3cd283635852e176dbed1fa 100644 --- a/Modules/IO/IOGDAL/include/otbOGRIOHelper.h +++ b/Modules/IO/IOGDAL/include/otbOGRIOHelper.h @@ -24,7 +24,6 @@ #include <vector> #include "otbVectorData.h" -#include "otbOGRVersionProxy.h" #include "OTBIOGDALExport.h" @@ -74,14 +73,14 @@ public: unsigned int ProcessNodeWrite(InternalTreeNodeType * source, - ogr::version_proxy::GDALDatasetType * m_DataSource, + GDALDataset * m_DataSource, OGRGeometryCollection * ogrCollection, OGRLayer * ogrCurrentLayer, OGRSpatialReference * oSRS); /** Return a list of OGRLayer * */ std::vector<OGRLayer*> ConvertDataTreeNodeToOGRLayers(InternalTreeNodeType * source, - ogr::version_proxy::GDALDatasetType * dummyDatasource, + GDALDataset * dummyDatasource, OGRLayer* ogrCurrentLayer, OGRSpatialReference * oSRS); diff --git a/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h b/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h index dbff89e1b3dd6448dd2d7ad57950c2e9e2f190ca..d743bfa2b5e3b0736edcfaac8ae9b70b1801f786 100644 --- a/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h +++ b/Modules/IO/IOGDAL/include/otbOGRVectorDataIO.h @@ -26,7 +26,6 @@ #include "otbVectorDataIOBase.h" #include "otbVectorData.h" -#include "otbOGRVersionProxy.h" #include "OTBIOGDALExport.h" @@ -123,7 +122,7 @@ private: void CloseInternalDataSource(); - ogr::version_proxy::GDALDatasetType * m_DataSource; + GDALDataset * m_DataSource; }; diff --git a/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx b/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx index 22cdc92cd695dbba7937858a4d994bc9ea0ceba5..5a8f62ce70387bd3b372b02747aca18c056663d0 100644 --- a/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx +++ b/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx @@ -1508,7 +1508,6 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer) /* -------------------------------------------------------------------- */ /* Set the RPC coeffs if no projection available (since GDAL 1.10.0) */ /* -------------------------------------------------------------------- */ -#if GDAL_VERSION_NUM >= 1100000 ImageKeywordlist otb_kwl; itk::ExposeMetaData<ImageKeywordlist>(dict, MetaDataKey::OSSIMKeywordlistKey, @@ -1523,7 +1522,6 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer) CSLDestroy( rpcMetadata ); } } -#endif } /* -------------------------------------------------------------------- */ diff --git a/Modules/IO/IOGDAL/src/otbOGRIOHelper.cxx b/Modules/IO/IOGDAL/src/otbOGRIOHelper.cxx index c27c1525025ef3f118cfac387e636e60ad55d584..0bf6f0644d9536a302cc54d191e4de4bf27d90fa 100644 --- a/Modules/IO/IOGDAL/src/otbOGRIOHelper.cxx +++ b/Modules/IO/IOGDAL/src/otbOGRIOHelper.cxx @@ -209,7 +209,7 @@ void OGRIOHelper otb::VectorDataKeywordlist kwl; for (int fieldNum = 0; fieldNum < feature->GetFieldCount(); ++fieldNum) { - if (ogr::version_proxy::IsFieldSetAndNotNull(feature, fieldNum)) + if (ogr::IsFieldSetAndNotNull(feature, fieldNum)) { kwl.AddField(feature->GetFieldDefnRef(fieldNum), feature->GetRawFieldRef(fieldNum)); } @@ -651,7 +651,7 @@ void OGRIOHelper unsigned int OGRIOHelper ::ProcessNodeWrite(InternalTreeNodeType * source, - ogr::version_proxy::GDALDatasetType * m_DataSource, + GDALDataset * m_DataSource, OGRGeometryCollection * ogrCollection, OGRLayer * ogrCurrentLayer, OGRSpatialReference * oSRS) @@ -1027,7 +1027,7 @@ unsigned int OGRIOHelper **/ std::vector<OGRLayer*> OGRIOHelper ::ConvertDataTreeNodeToOGRLayers(InternalTreeNodeType * source, - ogr::version_proxy::GDALDatasetType * inMemoryDataSource, + GDALDataset * inMemoryDataSource, OGRLayer* ogrCurrentLayer, OGRSpatialReference * oSRS) { @@ -1036,8 +1036,13 @@ std::vector<OGRLayer*> OGRIOHelper if (inMemoryDataSource == nullptr) { const char * driverName = "Memory"; - ogr::version_proxy::GDALDriverType * ogrDriver = ogr::version_proxy::GetDriverByName(driverName); - inMemoryDataSource = ogr::version_proxy::Create(ogrDriver,"tempDataSource"); + GDALDriver * ogrDriver = GetGDALDriverManager()->GetDriverByName(driverName); + inMemoryDataSource = ogrDriver->Create( "tempDataSource", + 0, + 0, + 0, + GDT_Unknown, + 0); } std::vector<OGRLayer*> ogrLayerVector; diff --git a/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx b/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx index f47b192d7ea916632d00f880722f7d7304f1a1b4..2d280b1af1d253995429407f559406cac20e142c 100644 --- a/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx +++ b/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx @@ -54,15 +54,19 @@ OGRVectorDataIO::~OGRVectorDataIO() bool OGRVectorDataIO::CanReadFile(const char* filename) const { - otb::ogr::version_proxy::GDALDatasetType * poDS = ogr::version_proxy::Open(filename, true); - + GDALDataset * poDS = (GDALDataset *)GDALOpenEx( + filename, + GDAL_OF_READONLY | GDAL_OF_VECTOR, + NULL, + NULL, + NULL); if (poDS == nullptr) { std::cerr<<"Can not read file "<<filename<<" with GDALOpen"<<std::endl; return false; } // std::cout << poDS->GetDriver()->GetName() << std::endl; - ogr::version_proxy::Close(poDS); + GDALClose(poDS); return true; } @@ -93,8 +97,12 @@ OGRVectorDataIO this->CloseInternalDataSource(); } - m_DataSource = ogr::version_proxy::Open(this->m_FileName.c_str(),true); - + m_DataSource = (GDALDataset *)GDALOpenEx( + this->m_FileName.c_str(), + GDAL_OF_READONLY | GDAL_OF_VECTOR, + NULL, + NULL, + NULL); if (m_DataSource == nullptr) { itkExceptionMacro(<< "Failed to open data file " << this->m_FileName); @@ -184,7 +192,7 @@ OGRVectorDataIO void OGRVectorDataIO::CloseInternalDataSource() { assert(m_DataSource != NULL && "m_DataSource cannot be NULL"); - ogr::version_proxy::Close(m_DataSource); + GDALClose(m_DataSource); m_DataSource = nullptr; } @@ -215,8 +223,8 @@ void OGRVectorDataIO::Write(const itk::DataObject* datag, char ** /** unused */) //Find first the OGR driver - ogr::version_proxy::GDALDriverType * ogrDriver = - ogr::version_proxy::GetDriverByName(this->GetOGRDriverName(this->m_FileName).data()); + GDALDriver * ogrDriver = + GetGDALDriverManager()->GetDriverByName(this->GetOGRDriverName(this->m_FileName).data()); if (ogrDriver == nullptr) { @@ -226,15 +234,34 @@ void OGRVectorDataIO::Write(const itk::DataObject* datag, char ** /** unused */) // free an existing previous data source, if any if (m_DataSource != nullptr) { - ogr::version_proxy::Close(m_DataSource); + GDALClose(m_DataSource); } // Erase the dataSource if already exist - ogr::version_proxy::Delete(this->m_FileName.c_str()); - - // m_DataSource = OGRSFDriverRegistrar::Open(this->m_FileName.c_str(), TRUE); - m_DataSource = ogr::version_proxy::Create(ogrDriver,this->m_FileName.c_str()); + GDALDataset * poDS = (GDALDataset *)GDALOpenEx( + this->m_FileName.c_str(), + GDAL_OF_UPDATE | GDAL_OF_VECTOR, + NULL, + NULL, + NULL); + + GDALDriver * poDriver = NULL; + if(poDS) + { + poDriver = poDS->GetDriver(); + GDALClose(poDS); + } + if(poDriver) + { + poDriver->Delete(this->m_FileName.c_str()); + } + m_DataSource = ogrDriver->Create( this->m_FileName.c_str(), + 0, + 0, + 0, + GDT_Unknown, + 0); // check the created data source if (m_DataSource == nullptr) { @@ -288,7 +315,7 @@ void OGRVectorDataIO::Write(const itk::DataObject* datag, char ** /** unused */) otbMsgDevMacro( << "layerKept " << layerKept ); (void)layerKept; // keep compiler happy - otb::ogr::version_proxy::Close(m_DataSource); + GDALClose(m_DataSource); m_DataSource = nullptr; if (oSRS != nullptr) diff --git a/Modules/IO/TestKernel/src/otbTestHelper.cxx b/Modules/IO/TestKernel/src/otbTestHelper.cxx index fae2a40dfe64a70447af91c8ade41eb539f20fb5..e849b0129510644ac3d9c856d570f7931b5cbb04 100644 --- a/Modules/IO/TestKernel/src/otbTestHelper.cxx +++ b/Modules/IO/TestKernel/src/otbTestHelper.cxx @@ -48,7 +48,7 @@ #include "otbDifferenceImageFilter.h" #include "otbPrintableImageFilter.h" #include "otbStreamingShrinkImageFilter.h" -#include "otbOGRVersionProxy.h" +#include "otbOGRHelpers.h" #include "otbConfigure.h" @@ -1727,28 +1727,48 @@ int TestHelper::RegressionTestOgrFile(const char *testOgrFilename, const char *b /* -------------------------------------------------------------------- */ /* Open data source. */ /* -------------------------------------------------------------------- */ - otb::ogr::version_proxy::GDALDatasetType *ref_poDS = nullptr; - otb::ogr::version_proxy::GDALDriverType * ref_poDriver = nullptr; + GDALDataset *ref_poDS = nullptr; + GDALDriver * ref_poDriver = nullptr; //OGRGeometry * ref_poSpatialFilter = NULL; - otb::ogr::version_proxy::GDALDatasetType *test_poDS = nullptr; - otb::ogr::version_proxy::GDALDriverType * test_poDriver = nullptr; + GDALDataset *test_poDS = nullptr; + GDALDriver * test_poDriver = nullptr; //OGRGeometry * test_poSpatialFilter = NULL; - ref_poDS = otb::ogr::version_proxy::Open(ref_pszDataSource, false); + ref_poDS = (GDALDataset *)GDALOpenEx( + ref_pszDataSource, + GDAL_OF_UPDATE | GDAL_OF_VECTOR, + NULL, + NULL, + NULL); + if (ref_poDS == nullptr && !bReadOnly) { - ref_poDS = otb::ogr::version_proxy::Open(ref_pszDataSource, true); + ref_poDS = (GDALDataset *)GDALOpenEx( + ref_pszDataSource, + GDAL_OF_READONLY | GDAL_OF_VECTOR, + NULL, + NULL, + NULL); bReadOnly = TRUE; if (ref_poDS != nullptr && m_ReportErrors) { std::cout << "Had to open REF data source read-only."<<std::endl; } } - test_poDS = otb::ogr::version_proxy::Open(ref_pszDataSource, bReadOnly); + test_poDS = (GDALDataset *)GDALOpenEx( + ref_pszDataSource, + (bReadOnly? GDAL_OF_READONLY : GDAL_OF_UPDATE) | GDAL_OF_VECTOR, + NULL, + NULL, + NULL); if (test_poDS == nullptr && !bReadOnly) { - test_poDS = otb::ogr::version_proxy::Open(ref_pszDataSource, bReadOnly); - + test_poDS = (GDALDataset *)GDALOpenEx( + ref_pszDataSource, + (bReadOnly? GDAL_OF_READONLY : GDAL_OF_UPDATE) | GDAL_OF_VECTOR, + NULL, + NULL, + NULL); bReadOnly = TRUE; if (test_poDS != nullptr && m_ReportErrors) @@ -1766,7 +1786,7 @@ int TestHelper::RegressionTestOgrFile(const char *testOgrFilename, const char *b { std::cout << "FAILURE:\n" "Unable to open REF datasource `" << ref_pszDataSource << "' with the following drivers." << std::endl; - std::vector<std::string> drivers = ogr::version_proxy::GetAvailableDriversAsStringVector(); + std::vector<std::string> drivers = ogr::GetAvailableDriversAsStringVector(); for (std::vector<std::string>::const_iterator it = drivers.begin();it!=drivers.end();++it) { @@ -1784,7 +1804,7 @@ int TestHelper::RegressionTestOgrFile(const char *testOgrFilename, const char *b { std::cout << "FAILURE:\n""Unable to open TEST datasource `" << test_pszDataSource << "' with the following drivers." << std::endl; - std::vector<std::string> drivers = ogr::version_proxy::GetAvailableDriversAsStringVector(); + std::vector<std::string> drivers = ogr::GetAvailableDriversAsStringVector(); for (std::vector<std::string>::const_iterator it = drivers.begin();it!=drivers.end();++it) { @@ -1803,8 +1823,8 @@ int TestHelper::RegressionTestOgrFile(const char *testOgrFilename, const char *b // TODO: Improve this check as it will stop as soon as one of the // list ends (i.e. it does not guarantee that all files are present) - std::vector<std::string> refFileList = otb::ogr::version_proxy::GetFileListAsStringVector(ref_poDS); - std::vector<std::string> testFileList = otb::ogr::version_proxy::GetFileListAsStringVector(test_poDS); + std::vector<std::string> refFileList = otb::ogr::GetFileListAsStringVector(ref_poDS); + std::vector<std::string> testFileList = otb::ogr::GetFileListAsStringVector(test_poDS); unsigned int fileId = 0; @@ -1941,7 +1961,7 @@ void TestHelper::DumpOGRFeature(FILE* fpOut, OGRFeature* feature, char** papszOp poFDefn->GetNameRef(), OGRFieldDefn::GetFieldTypeName(poFDefn->GetType())); - if (ogr::version_proxy::IsFieldSetAndNotNull(feature, iField)) fprintf(fpOut, "%s\n", feature->GetFieldAsString(iField)); + if (ogr::IsFieldSetAndNotNull(feature, iField)) fprintf(fpOut, "%s\n", feature->GetFieldAsString(iField)); else fprintf(fpOut, "(null)\n"); } diff --git a/Modules/Learning/Sampling/src/otbSampleAugmentationFilter.cxx b/Modules/Learning/Sampling/src/otbSampleAugmentationFilter.cxx index 5778de0d9324b7a022cab8569c3b25a48260cfc8..1ff5bb8043539fa4f45dc7c90f0f52535e86f1c3 100644 --- a/Modules/Learning/Sampling/src/otbSampleAugmentationFilter.cxx +++ b/Modules/Learning/Sampling/src/otbSampleAugmentationFilter.cxx @@ -247,7 +247,7 @@ SampleAugmentationFilter { OGRFieldType fieldType = feature.ogr().GetFieldDefnRef(idx)->GetType(); return (fieldType == OFTInteger - || ogr::version_proxy::IsOFTInteger64( fieldType ) + || fieldType == OFTInteger64 || fieldType == OFTReal); } diff --git a/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.h b/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.h index d719606ae3492d9589f49fa15429bbb00b32d640..f7fbf00ff58fe49e17d28c672ad982426fb3badc 100644 --- a/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.h +++ b/Modules/Segmentation/Conversion/include/otbRasterizeVectorDataFilter.h @@ -31,7 +31,6 @@ #include "gdal.h" #include "gdal_alg.h" #include "ogr_srs_api.h" -#include "otbOGRVersionProxy.h" namespace otb { @@ -148,7 +147,7 @@ protected: { if (m_OGRDataSourcePointer != nullptr) { - ogr::version_proxy::Close(m_OGRDataSourcePointer); + GDALClose(m_OGRDataSourcePointer); } } @@ -160,7 +159,7 @@ private: RasterizeVectorDataFilter(const Self&) = delete; void operator=(const Self&) = delete; - ogr::version_proxy::GDALDatasetType * m_OGRDataSourcePointer; + GDALDataset * m_OGRDataSourcePointer; // Vector Of LayersH std::vector< OGRLayerH > m_SrcDataSetLayers; diff --git a/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.h b/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.h index 6cdbabc3974e38da1993b092a130ea042879fffc..d67617fc170887bdc864770ba7655131c1e9f14e 100644 --- a/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.h +++ b/Modules/Segmentation/Conversion/include/otbVectorDataToLabelImageFilter.h @@ -29,7 +29,6 @@ #include "gdal.h" #include "ogr_api.h" -#include "otbOGRVersionProxy.h" #include <string> namespace otb { @@ -151,7 +150,7 @@ protected: if (m_OGRDataSourcePointer != nullptr) { - ogr::version_proxy::Close(m_OGRDataSourcePointer); + GDALClose(m_OGRDataSourcePointer); } } @@ -163,7 +162,7 @@ private: VectorDataToLabelImageFilter(const Self&) = delete; void operator=(const Self&) = delete; - ogr::version_proxy::GDALDatasetType * m_OGRDataSourcePointer; + GDALDataset * m_OGRDataSourcePointer; // Vector Of OGRGeometyH std::vector< OGRGeometryH > m_SrcDataSetGeometries; diff --git a/Modules/Segmentation/OGRProcessing/include/otbOGRLayerStreamStitchingFilter.h b/Modules/Segmentation/OGRProcessing/include/otbOGRLayerStreamStitchingFilter.h index b3702ad155522de6e79a96f313059dee0b38d472..43750ae207e7cf346d96561050656b005b1d18ba 100644 --- a/Modules/Segmentation/OGRProcessing/include/otbOGRLayerStreamStitchingFilter.h +++ b/Modules/Segmentation/OGRProcessing/include/otbOGRLayerStreamStitchingFilter.h @@ -24,10 +24,6 @@ #include "otbOGRDataSourceWrapper.h" #include "otbMacro.h" -//#if(GDAL_VERSION_NUM < 1800) -//#error OGRLayerStreamStitchingFilter requires GDAL version >= 1.8.0 -//#endif - #include "itkProgressReporter.h" #include <algorithm> diff --git a/Modules/Segmentation/OGRProcessing/include/otbOGRLayerStreamStitchingFilter.hxx b/Modules/Segmentation/OGRProcessing/include/otbOGRLayerStreamStitchingFilter.hxx index 5359e967bfb7224311aa9d452965ea4cc9c4315c..a3c72bb38bdfad22e828baa0e041b102549658c1 100644 --- a/Modules/Segmentation/OGRProcessing/include/otbOGRLayerStreamStitchingFilter.hxx +++ b/Modules/Segmentation/OGRProcessing/include/otbOGRLayerStreamStitchingFilter.hxx @@ -291,12 +291,8 @@ OGRLayerStreamStitchingFilter<TInputImage> } else if (intersection->getGeometryType() == wkbMultiLineString) { - #if(GDAL_VERSION_NUM < 1800) - fusion.overlap = GetLengthOGRGeometryCollection(dynamic_cast<OGRGeometryCollection *> (intersection.get())); - #else fusion.overlap = dynamic_cast<OGRMultiLineString *>(intersection.get())->get_Length(); - #endif - } + } /** -Wunused-variable long upperFID = upper.feat.GetFID(); @@ -325,9 +321,6 @@ OGRLayerStreamStitchingFilter<TInputImage> ogr::Field field = upper.feat[0]; try { - #ifdef OTB_USE_GDAL_20 - // In this case, the feature id can be either - // OFTInteger64 or OFTInteger switch(field.GetType()) { case OFTInteger64: @@ -340,10 +333,6 @@ OGRLayerStreamStitchingFilter<TInputImage> fusionFeature[0].SetValue(field.GetValue<int>()); } } - #else - // Only OFTInteger supported in this case - fusionFeature[0].SetValue(field.GetValue<int>()); - #endif m_OGRLayer.CreateFeature(fusionFeature); m_OGRLayer.DeleteFeature(lower.feat.GetFID()); m_OGRLayer.DeleteFeature(upper.feat.GetFID()); diff --git a/Modules/ThirdParty/GDAL/otb-module-init.cmake b/Modules/ThirdParty/GDAL/otb-module-init.cmake index b13104318f0de04de73b78aaeb59d1aafd203e3c..68bdd5597c3258a8fd27c27a2b1d38814e0a99b2 100644 --- a/Modules/ThirdParty/GDAL/otb-module-init.cmake +++ b/Modules/ThirdParty/GDAL/otb-module-init.cmake @@ -35,8 +35,8 @@ if(NOT GDAL_CONFIG_CHECKING) return() endif() -set(MIN_MAJOR_VERSION 1) -set(MIN_MINOR_VERSION 10) +set(MIN_MAJOR_VERSION 2) +set(MIN_MINOR_VERSION 0) # Ensure that the temporary dir always exists before starting tests if(NOT EXISTS ${TEMP}) @@ -95,11 +95,6 @@ if(EXISTS "${TEMP}/gdalVersion.txt") file(READ "${TEMP}/gdalVersion.txt" _GDAL_VERSION_STRING) #can't we use GDAL_VERSION_NUM ? string(SUBSTRING ${_GDAL_VERSION_STRING} 0 2 VER2) - if("${VER2}" STREQUAL "2.") - set(OTB_USE_GDAL_20 true CACHE INTERNAL "True if GDAL >= 2.0.0 has been detected" FORCE ) - else() - set(OTB_USE_GDAL_20 false CACHE INTERNAL "True if GDAL >= 2.0.0 has been detected" FORCE ) - endif() set(GDAL_VERSION_STRING "${_GDAL_VERSION_STRING}" CACHE INTERNAL "" FORCE) else() error_message( "${TEMP}/gdalVersion.txt does not exist. Cannot continue.")