Commit 424d7781 authored by Julien Michel's avatar Julien Michel

Merge branch 'gdal_derived_sds_support' into develop

parents b9b08091 77d91841
......@@ -179,6 +179,9 @@ private:
*/
bool GetGdalReadImageFileName(const std::string& filename, std::string& GdalFileName);
// Retrieve the real source file name if derived dataset */
std::string GetDerivedDatasetSourceFileName(const std::string& filename) const;
ImageFileReader(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
......
......@@ -24,6 +24,7 @@
#include "otbSystem.h"
#include <itksys/SystemTools.hxx>
#include <fstream>
#include <string>
#include "itkImageIOFactory.h"
#include "itkPixelTraits.h"
......@@ -40,6 +41,9 @@
namespace otb
{
static const char DerivedSubdatasetPrefix[] = "DERIVED_SUBDATASET:";
static const size_t DerivedSubdatasetPrefixLength = sizeof(DerivedSubdatasetPrefix);
template<class T>
bool PixelIsComplex(const std::complex<T>& /*dummy*/)
{
......@@ -258,8 +262,8 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
}
// Update FileName
this->m_FileName = lFileName;
std::string lFileNameOssimKeywordlist = this->m_FileName;
std::string lFileNameOssimKeywordlist = GetDerivedDatasetSourceFileName(m_FileName);
// Test if the file exists and if it can be opened.
// An exception will be thrown otherwise.
......@@ -524,6 +528,27 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
}
template <class TOutputImage, class ConvertPixelTraits>
std::string
ImageFileReader<TOutputImage, ConvertPixelTraits>
::GetDerivedDatasetSourceFileName(const std::string & filename) const
{
const size_t dsds_pos = filename.find(DerivedSubdatasetPrefix);
if(dsds_pos != std::string::npos)
{
// Derived subdataset from gdal
const size_t alg_pos = filename.find(":",dsds_pos+DerivedSubdatasetPrefixLength);
if (alg_pos != std::string::npos)
{
std::string sourceFilename = filename.substr(alg_pos+1,filename.size() - alg_pos);
return sourceFilename;
}
}
return filename;
}
template <class TOutputImage, class ConvertPixelTraits>
void
ImageFileReader<TOutputImage, ConvertPixelTraits>
......@@ -536,13 +561,15 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
return;
}
std::string fileToCheck = GetDerivedDatasetSourceFileName(m_FileName);
// Test if the file exists.
if (!itksys::SystemTools::FileExists(this->m_FileName.c_str()))
if (!itksys::SystemTools::FileExists(fileToCheck.c_str()))
{
otb::ImageFileReaderException e(__FILE__, __LINE__);
std::ostringstream msg;
msg << "The file doesn't exist. "
<< std::endl << "Filename = " << this->m_FileName
<< std::endl << "Filename = " << fileToCheck
<< std::endl;
e.SetDescription(msg.str().c_str());
throw e;
......@@ -551,16 +578,16 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
// Test if the file can be open for reading access.
//Only if m_FileName specify a filename (not a dirname)
if (itksys::SystemTools::FileExists(this->m_FileName.c_str(), true) == true)
if (itksys::SystemTools::FileExists(fileToCheck.c_str(), true))
{
std::ifstream readTester;
readTester.open(this->m_FileName.c_str());
readTester.open(fileToCheck.c_str());
if (readTester.fail())
{
readTester.close();
std::ostringstream msg;
msg << "The file couldn't be opened for reading. "
<< std::endl << "Filename: " << this->m_FileName
<< std::endl << "Filename: " << fileToCheck
<< std::endl;
otb::ImageFileReaderException e(__FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION);
throw e;
......@@ -619,7 +646,6 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
//Supprime l'extension
GdalFileName = System::GetRootName(strFileName);
}
else
{
// Sinon le filename est le nom du fichier a ouvrir
......@@ -627,6 +653,7 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
}
fic_trouve = true;
}
otbMsgDevMacro(<< "lFileNameGdal : " << GdalFileName.c_str());
otbMsgDevMacro(<< "fic_trouve : " << fic_trouve);
return (fic_trouve);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment