From 89792dedbb7692bdda3be43c006198e3e7d5708e Mon Sep 17 00:00:00 2001 From: Cedric <cedric.traizet@c-s.fr> Date: Fri, 4 Jan 2019 11:44:17 +0100 Subject: [PATCH] ENH: remove versionproxy::Delete function --- .../GdalAdapters/include/otbOGRVersionProxy.h | 11 ------- .../src/otbOGRDataSourceWrapper.cxx | 32 +++++++++++++++++-- .../GdalAdapters/src/otbOGRVersionProxy.cxx | 32 ------------------- Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx | 18 ++++++++++- 4 files changed, 47 insertions(+), 46 deletions(-) diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h b/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h index 0c4711fc86..d26689c360 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h +++ b/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h @@ -64,17 +64,6 @@ namespace version_proxy * See function documentation for details. */ - /** - * 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); - /** * Return the list of files composing the dataset. * diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx index 78ba720a8f..966d975634 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx @@ -218,8 +218,36 @@ 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 + { + success = false; + } + if(poDriver) + { + OGRErr ret = poDriver->Delete(simpleFileName.c_str()); + success = ret == OGRERR_NONE; + } + else + { + success = false; + } + + if (!success) { itkGenericExceptionMacro(<< "Deletion of data source " << simpleFileName << " failed: " << CPLGetLastErrorMsg()); diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy.cxx index cc9339984b..7c4b1e44e2 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy.cxx @@ -49,38 +49,6 @@ namespace ogr namespace version_proxy { -bool Delete(const char * name) -{ - // Open dataset - GDALDataset * poDS = (GDALDataset *)GDALOpenEx( - name, - GDAL_OF_UPDATE | GDAL_OF_VECTOR, - NULL, - NULL, - NULL); - - GDALDriver * poDriver = NULL; - if(poDS) - { - poDriver = poDS->GetDriver(); - GDALClose(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; -} - #if GDAL_VERSION_NUM>=2000000 namespace raii { diff --git a/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx b/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx index 518567088b..2d280b1af1 100644 --- a/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx +++ b/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx @@ -238,7 +238,23 @@ void OGRVectorDataIO::Write(const itk::DataObject* datag, char ** /** unused */) } // Erase the dataSource if already exist - ogr::version_proxy::Delete(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, -- GitLab