diff --git a/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h b/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h index 6d5bdce6a5257b5f4e23bc8eb762dfcc89922fd5..0c4711fc86dff384012d52e1eeb9d7d5cd939ace 100644 --- a/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h +++ b/Modules/Adapters/GdalAdapters/include/otbOGRVersionProxy.h @@ -64,38 +64,6 @@ namespace version_proxy * See function documentation for details. */ - /** - * 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 - GDALDataset * Open(const char * filename, bool readOnly = true , std::vector< std::string > const & options = std::vector< std::string >() ); - - /** - * 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 - GDALDataset * Create(GDALDriver * driver, const char * name , std::vector< std::string > const & options = std::vector< std::string >() ); - - /** * This function physically deletes an existing dataset. * diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx index 66cabfd6025498cd25ef7be98904bcb0f0a4aedf..78ba720a8ffbda7080bd921f4403b71a1466e9bd 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx @@ -129,7 +129,13 @@ otb::ogr::DataSource::DataSource() 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()); @@ -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); - GDALDataset * 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 @@ -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 @@ -228,9 +239,12 @@ otb::ogr::DataSource::New(std::string const& datasourceName, Modes::type mode) } Drivers::Init(); - GDALDataset * 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); GDALClose(ds); diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy.cxx index 4b4f497b30c398b992ac902bdf1706ccc74366ca..cc9339984b2defba8e1bd9cde0fd48ada9979449 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRVersionProxy.cxx @@ -49,45 +49,16 @@ namespace ogr namespace version_proxy { -GDALDataset * Open(const char * filename, bool readOnly , std::vector< std::string > const & options ) +bool Delete(const char * name) { -#if GDAL_VERSION_NUM<2000000 - (void)options; - return OGRSFDriverRegistrar::Open(filename,!readOnly); -#else - return (GDALDataset *)GDALOpenEx( - filename, - (readOnly? GDAL_OF_READONLY : GDAL_OF_UPDATE) | GDAL_OF_VECTOR, + // Open dataset + GDALDataset * poDS = (GDALDataset *)GDALOpenEx( + name, + GDAL_OF_UPDATE | GDAL_OF_VECTOR, + NULL, NULL, - otb::ogr::StringListConverter( options ).to_ogr(), NULL); -#endif -} - -GDALDataset * Create(GDALDriver * driver, const char * name , std::vector< std::string > const & options ) -{ -#if GDAL_VERSION_NUM<2000000 - (void)options; - GDALDataset * 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 - GDALDataset * poDS = otb::ogr::version_proxy::Open(name,false); GDALDriver * poDriver = NULL; if(poDS) { diff --git a/Modules/IO/IOGDAL/src/otbOGRIOHelper.cxx b/Modules/IO/IOGDAL/src/otbOGRIOHelper.cxx index 724b505c8656876a70e012ef5653a8794bc61045..2f3ddebb4aff8043b7d818e1f89b0e25ede1e62c 100644 --- a/Modules/IO/IOGDAL/src/otbOGRIOHelper.cxx +++ b/Modules/IO/IOGDAL/src/otbOGRIOHelper.cxx @@ -1037,7 +1037,12 @@ std::vector<OGRLayer*> OGRIOHelper { const char * driverName = "Memory"; GDALDriver * ogrDriver = GetGDALDriverManager()->GetDriverByName(driverName); - inMemoryDataSource = ogr::version_proxy::Create(ogrDriver,"tempDataSource"); + 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 90076d51a908b3ad01d7ccb75a844aedce927707..518567088bc8b4f3f8f71e0fbc7e691c76f3f041 100644 --- a/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx +++ b/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx @@ -54,8 +54,12 @@ OGRVectorDataIO::~OGRVectorDataIO() bool OGRVectorDataIO::CanReadFile(const char* filename) const { - GDALDataset * 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; @@ -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); @@ -232,9 +240,12 @@ void OGRVectorDataIO::Write(const itk::DataObject* datag, char ** /** unused */) // 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()); - + m_DataSource = ogrDriver->Create( this->m_FileName.c_str(), + 0, + 0, + 0, + GDT_Unknown, + 0); // check the created data source if (m_DataSource == nullptr) { diff --git a/Modules/IO/TestKernel/src/otbTestHelper.cxx b/Modules/IO/TestKernel/src/otbTestHelper.cxx index 1dd364ac85c55dabf8b68f4bf221e0420d917a63..310d9a10f1accea2db4899878b18fbf869c6b1bd 100644 --- a/Modules/IO/TestKernel/src/otbTestHelper.cxx +++ b/Modules/IO/TestKernel/src/otbTestHelper.cxx @@ -1734,21 +1734,41 @@ int TestHelper::RegressionTestOgrFile(const char *testOgrFilename, const char *b 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)