From 1c53a1316773adf2a416927938cea11e45f17a0e Mon Sep 17 00:00:00 2001 From: Julien Michel <julien.michel@orfeo-toolbox.org> Date: Tue, 29 Sep 2015 16:25:40 +0200 Subject: [PATCH] BUG: GdalOpenEx should be used to open vector data --- .../Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx | 4 ++-- Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx | 7 ++++--- Modules/IO/TestKernel/src/otbTestHelper.cxx | 8 ++++---- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx index f0943171d6..565abffff3 100644 --- a/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx +++ b/Modules/Adapters/GdalAdapters/src/otbOGRDataSourceWrapper.cxx @@ -141,7 +141,7 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c { bool update = (mode != Modes::Read); - GDALDataset * source = (GDALDataset *)GDALOpen(datasourceName.c_str(), (update?GA_Update:GA_ReadOnly)); + GDALDataset * source = (GDALDataset *)GDALOpenEx(datasourceName.c_str(), (update? GDAL_OF_UPDATE : GDAL_OF_READONLY) | GDAL_OF_VECTOR,NULL,NULL,NULL); if (!source) { // In read mode, this is a failure @@ -179,7 +179,7 @@ otb::ogr::DataSource::Pointer otb::ogr::DataSource::OpenDataSource(std::string c void DeleteDataSource(std::string const& datasourceName) { // Attempt to delete the datasource if it already exists - GDALDataset * poDS = (GDALDataset *)GDALOpen(datasourceName.c_str(), GA_Update); + GDALDataset * poDS = (GDALDataset *)GDALOpenEx(datasourceName.c_str(), GDAL_OF_UPDATE | GDAL_OF_VECTOR,NULL,NULL,NULL); if (poDS != NULL) { diff --git a/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx b/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx index 2be24e9b78..2e8146f179 100644 --- a/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx +++ b/Modules/IO/IOGDAL/src/otbOGRVectorDataIO.cxx @@ -56,10 +56,11 @@ OGRVectorDataIO::CanReadFile(const char* filename) const { - GDALDataset * poDS = (GDALDataset *)GDALOpen(filename, GA_ReadOnly); + GDALDataset * poDS = (GDALDataset *)GDALOpenEx(filename, GDAL_OF_READONLY | GDAL_OF_VECTOR, NULL, NULL,NULL); if (poDS == NULL) { + std::cerr<<"Can not read file "<<filename<<" with GDALOpen"<<std::endl; return false; } // std::cout << poDS->GetDriver()->GetName() << std::endl; @@ -94,7 +95,7 @@ OGRVectorDataIO GDALClose(m_DataSource); } - m_DataSource = (GDALDataset *)GDALOpen(this->m_FileName.c_str(), GA_ReadOnly); + m_DataSource = (GDALDataset *)GDALOpenEx(this->m_FileName.c_str(), GA_ReadOnly| GDAL_OF_VECTOR,NULL,NULL,NULL); if (m_DataSource == NULL) { @@ -227,7 +228,7 @@ void OGRVectorDataIO::Write(const itk::DataObject* datag, char ** papszOptions) // Erase the dataSource if already exist //TODO investigate the possibility of giving the option OVERWRITE=YES to the CreateDataSource method - GDALDataset * poDS = (GDALDataset *)GDALOpen(this->m_FileName.c_str(), GA_Update); + GDALDataset * poDS = (GDALDataset *)GDALOpenEx(this->m_FileName.c_str(), GDAL_OF_UPDATE | GDAL_OF_VECTOR,NULL,NULL,NULL); if (poDS != NULL) { //Erase the data if possible diff --git a/Modules/IO/TestKernel/src/otbTestHelper.cxx b/Modules/IO/TestKernel/src/otbTestHelper.cxx index 62b83b4f79..85a1bc9d08 100644 --- a/Modules/IO/TestKernel/src/otbTestHelper.cxx +++ b/Modules/IO/TestKernel/src/otbTestHelper.cxx @@ -1081,20 +1081,20 @@ int TestHelper::RegressionTestOgrFile(const char *testOgrFilename, const char *b GDALDriver * test_poDriver = NULL; //OGRGeometry * test_poSpatialFilter = NULL; - ref_poDS = (GDALDataset*)GDALOpen(ref_pszDataSource, GA_Update); + ref_poDS = (GDALDataset*)GDALOpenEx(ref_pszDataSource, GDAL_OF_UPDATE | GDAL_OF_VECTOR,NULL,NULL,NULL); if (ref_poDS == NULL && !bReadOnly) { - ref_poDS = (GDALDataset*)GDALOpen(ref_pszDataSource, GA_ReadOnly); + ref_poDS = (GDALDataset*)GDALOpenEx(ref_pszDataSource, GDAL_OF_READONLY | GDAL_OF_VECTOR,NULL,NULL,NULL); if (ref_poDS != NULL && m_ReportErrors) { std::cout << "Had to open REF data source read-only.\n"; bReadOnly = TRUE; } } - test_poDS = (GDALDataset*)GDALOpen(test_pszDataSource, (bReadOnly?GA_ReadOnly:GA_Update)); + test_poDS = (GDALDataset*)GDALOpenEx(test_pszDataSource, (bReadOnly? GDAL_OF_READONLY : GDAL_OF_UPDATE) | GDAL_OF_VECTOR,NULL,NULL,NULL); if (test_poDS == NULL && !bReadOnly) { - test_poDS = (GDALDataset*)GDALOpen(test_pszDataSource, GA_ReadOnly); + test_poDS = (GDALDataset*)GDALOpenEx(test_pszDataSource, GDAL_OF_READONLY | GDAL_OF_VECTOR,NULL,NULL,NULL); if (test_poDS != NULL && m_ReportErrors) { std::cout << "Had to open REF data source read-only.\n"; -- GitLab