Commit 62d8e08b authored by Julien Osman's avatar Julien Osman
Browse files

ENH: Allow GeomMetadataSupplier to keep trace of the image file

parent dff9aad5
......@@ -22,6 +22,7 @@
#define otbGeomMetadataSupplier_h
#include <boost/any.hpp>
#include <unordered_map>
#include "OTBMetadataExport.h"
#include "otbMetadataSupplierInterface.h"
......@@ -43,7 +44,8 @@ class OTBMetadata_EXPORT GeomMetadataSupplier
public:
using DictType = std::unordered_map<std::string, std::string>;
GeomMetadataSupplier(const std::string &);
GeomMetadataSupplier(const std::string & geomFile);
GeomMetadataSupplier(const std::string & geomFile, const std::string & imageFile);
GeomMetadataSupplier(const GeomMetadataSupplier &) = delete;
GeomMetadataSupplier& operator=(const GeomMetadataSupplier&) = delete;
~GeomMetadataSupplier() = default;
......@@ -59,6 +61,7 @@ public:
std::string GetMetadataValue(std::string const& path, bool& hasValue, int band=1) const override;
std::string GetResourceFile(std::string const& s="") const override;
std::vector<std::string> GetResourceFiles() const override;
int GetNbBands() const override;
......@@ -96,9 +99,10 @@ protected:
private:
/** List of resource files */
std::string m_FileName;
std::unordered_map<std::string, std::string> m_FileNames;
/** Dictionary containing the metadata */
DictType m_MetadataDic;
};
} // end namespace otb
......
......@@ -30,9 +30,15 @@
namespace otb
{
GeomMetadataSupplier::GeomMetadataSupplier(std::string const& fileName)
: m_FileName(fileName)
GeomMetadataSupplier::GeomMetadataSupplier(std::string const& geomFile)
{
GeomMetadataSupplier(geomFile, "");
}
GeomMetadataSupplier::GeomMetadataSupplier(std::string const& geomFile, const std::string & imageFile)
{
this->m_FileNames["geom"] = geomFile;
this->m_FileNames["image"] = imageFile;
this->ReadGeomFile();
}
......@@ -48,9 +54,17 @@ std::string GeomMetadataSupplier::GetMetadataValue(std::string const& path, bool
return "";
}
std::string GeomMetadataSupplier::GetResourceFile(std::string const&) const
std::string GeomMetadataSupplier::GetResourceFile(std::string const& name) const
{
assert((name == "") || (name == "geom") || (name == "image"));
if (name.empty())
return this->m_FileNames.at("geom");
return this->m_FileNames.at(name);
}
std::vector<std::string> GeomMetadataSupplier::GetResourceFiles() const
{
return this->m_FileName;
return std::vector<std::string>({this->m_FileNames.at("geom"), this->m_FileNames.at("image")});
}
int GeomMetadataSupplier::GetNbBands() const
......@@ -135,7 +149,7 @@ bool GeomMetadataSupplier::FetchRPC(ImageMetadata & imd)
std::string GeomMetadataSupplier::PrintSelf() const
{
std::ostringstream oss;
oss << "GeomMetadataSupplier: " << this->m_FileName << '\n';
oss << "GeomMetadataSupplier: " << this->m_FileNames.at("geom") << '\t' << this->m_FileNames.at("image") << '\n';
for (const auto& kv : this->m_MetadataDic)
oss << kv.first << " : " << kv.second << '\n';
return oss.str();
......@@ -143,9 +157,8 @@ std::string GeomMetadataSupplier::PrintSelf() const
void GeomMetadataSupplier::ReadGeomFile()
{
std::ifstream inputFile(this->m_FileName);
std::ifstream inputFile(this->m_FileNames["geom"]);
std::string line;
std::vector< std::string > keyVal;
while (std::getline(inputFile, line))
{
auto pos = line.find(":");
......
......@@ -44,15 +44,16 @@ std::unique_ptr<MetadataSupplierInterfaceType> GetIMI(const char* TheFileName)
std::string DerivatedFileName = ImageReaderType::GetDerivedDatasetSourceFileName(TheFileName);
std::string extension = itksys::SystemTools::GetFilenameLastExtension(DerivatedFileName);
std::string attachedGeom = DerivatedFileName.substr(0, DerivatedFileName.size() - extension.size()) + std::string(".geom");
std::string imageFileName = DerivatedFileName.substr(0, DerivatedFileName.find('?'));
// Case 1: external geom supplied through extended filename
if (!FilenameHelper->GetSkipGeom() && FilenameHelper->ExtGEOMFileNameIsSet())
{
return std::make_unique<otb::GeomMetadataSupplier>(FilenameHelper->GetExtGEOMFileName());
return std::make_unique<otb::GeomMetadataSupplier>(FilenameHelper->GetExtGEOMFileName(), imageFileName);
}
// Case 2: attached geom (if present)
else if (!FilenameHelper->GetSkipGeom() && itksys::SystemTools::FileExists(attachedGeom))
{
return std::make_unique<otb::GeomMetadataSupplier>(attachedGeom);
return std::make_unique<otb::GeomMetadataSupplier>(attachedGeom, imageFileName);
}
// Case 3: tags in file
else
......
......@@ -484,14 +484,14 @@ void ImageFileReader<TOutputImage, ConvertPixelTraits>::GenerateOutputInformatio
// Case 1: external geom supplied through extended filename
if (!m_FilenameHelper->GetSkipGeom() && m_FilenameHelper->ExtGEOMFileNameIsSet())
{
GeomMetadataSupplier geomSupplier(m_FilenameHelper->GetExtGEOMFileName());
GeomMetadataSupplier geomSupplier(m_FilenameHelper->GetExtGEOMFileName(), m_FileName);
ImageMetadataInterfaceFactory::CreateIMI(imd, geomSupplier);
geomSupplier.FetchRPC(imd);
}
// Case 2: attached geom (if present)
else if (!m_FilenameHelper->GetSkipGeom() && itksys::SystemTools::FileExists(attachedGeom))
{
GeomMetadataSupplier geomSupplier(attachedGeom);
GeomMetadataSupplier geomSupplier(attachedGeom, m_FileName);
ImageMetadataInterfaceFactory::CreateIMI(imd, geomSupplier);
geomSupplier.FetchRPC(imd);
}
......
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