From 06c6cca677915b4182aa074e33633b0a8fa0bd7d Mon Sep 17 00:00:00 2001 From: Guillaume Pasero <guillaume.pasero@c-s.fr> Date: Fri, 17 Aug 2018 10:01:30 +0200 Subject: [PATCH] BUG: #1589: detect the correct metadata on S1 .SAFE --- Modules/IO/IOGDAL/src/otbGDALImageIO.cxx | 20 ++++++++++++++++++- .../IO/ImageIO/include/otbImageFileReader.hxx | 15 +++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx b/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx index 439fd0e106..e800d8f4f0 100644 --- a/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx +++ b/Modules/IO/IOGDAL/src/otbGDALImageIO.cxx @@ -435,7 +435,7 @@ void GDALImageIO::InternalReadImageInformation() // supported gdal format using the m_DatasetNumber value // HDF4_SDS:UNKNOWN:"myfile.hdf":2 // and make m_Dataset point to it. - if (m_Dataset->GetDataSet()->GetRasterCount() == 0) + if (m_Dataset->GetDataSet()->GetRasterCount() == 0 || m_DatasetNumber > 0) { // this happen in the case of a hdf file with SUBDATASETS // Note: we assume that the datasets are in order @@ -659,6 +659,24 @@ void GDALImageIO::InternalReadImageInformation() } } + // get list of other files part of the same dataset + char** datasetFileList = dataset->GetFileList(); + m_AttachedFileNames.clear(); + if (datasetFileList != nullptr) + { + char** currentFile = datasetFileList; + while (*currentFile != nullptr) + { + if (m_FileName.compare(*currentFile) != 0) + { + m_AttachedFileNames.emplace_back(*currentFile); + otbLogMacro(Debug,<<"Found attached file : "<< *currentFile); + } + currentFile++; + } + CSLDestroy(datasetFileList); + } + /*----------------------------------------------------------------------*/ /*-------------------------- METADATA ----------------------------------*/ /*----------------------------------------------------------------------*/ diff --git a/Modules/IO/ImageIO/include/otbImageFileReader.hxx b/Modules/IO/ImageIO/include/otbImageFileReader.hxx index c26730b005..9e3215277e 100644 --- a/Modules/IO/ImageIO/include/otbImageFileReader.hxx +++ b/Modules/IO/ImageIO/include/otbImageFileReader.hxx @@ -433,7 +433,20 @@ ImageFileReader<TOutputImage, ConvertPixelTraits> } else { - otbLogMacro(Info,<< "No kwl metadata found in file "<<lFileNameOssimKeywordlist); + // Try attached files + for (const std::string& path : m_ImageIO->GetAttachedFileNames()) + { + otb_kwl = ReadGeometryFromImage(path,!m_FilenameHelper->GetSkipRpcTag()); + if(!otb_kwl.Empty()) + { + otbLogMacro(Info,<< "Loading kwl metadata in attached file "<<path); + break; + } + } + if (otb_kwl.Empty()) + { + otbLogMacro(Info,<< "No kwl metadata found in file "<<lFileNameOssimKeywordlist); + } } } -- GitLab