Commit 7beb05c2 authored by Guillaume Pasero's avatar Guillaume Pasero

ENH: Handle band metadata

parent f1fefa67
Pipeline #3706 passed with stage
in 26 minutes and 11 seconds
......@@ -228,8 +228,6 @@ public:
static void PrintMetadata(std::ostream& os, itk::Indent indent, const MetaDataDictionaryType& dict);
bool ParseStringKey(const MetadataSupplierInterface * mds, const char *path, MDStr key, int band=-1);
std::string& Fetch(const MetadataSupplierInterface * mds, const char *path, MDStr key, int band=-1);
double& Fetch(const MetadataSupplierInterface * mds, const char *path, MDNum key, int band=-1);
......
......@@ -72,19 +72,25 @@ public:
// Maybe not needed
// virtual std::vector<std::string> GetResourceFiles() = 0;
//~ virtual bool HasValue(const char * path) = 0;
/** Get the metadata value corresponding to a given path (meaning of this path
* depends on the specific implementation. Returns NULL when path is not found */
virtual const char * GetMetadataValue(const char * path) const = 0;
// probably not needed
//~ virtual std::vector<std::string> GetValuesList(const std::string& path) = 0;
* depends on the specific implementation. Returns NULL when path is not found
* If band >= 0, the metadata value is looked in the specified band*/
virtual const char * GetMetadataValue(const char * path, int band=-1) const = 0;
bool HasValue(const char * path, int band=-1)
{
const char * ret = GetMetadataValue(path, band);
if (ret == nullptr)
{
return false;
}
return true;
}
// utility functions
template <typename T> T GetAs(const char *path) const
template <typename T> T GetAs(const char *path, int band=-1) const
{
const char * ret = GetMetadataValue(path);
const char * ret = GetMetadataValue(path, band);
if (ret == nullptr)
{
otbGenericExceptionMacro(MissingMetadataException,<<"Missing metadata '"<<path<<"'")
......@@ -102,9 +108,9 @@ public:
/** Parse a metadata value to a std::vector,
* If size>=0, then the final std::vector size is checked and an exception
* is raised if it doesn't match the given size.*/
template < typename T> std::vector<T> GetAsVector(const char *path, const char sep=' ', int size=-1) const
template < typename T> std::vector<T> GetAsVector(const char *path, const char sep=' ', int size=-1, int band=-1) const
{
const char * ret = GetMetadataValue(path);
const char * ret = GetMetadataValue(path, band);
if (ret == nullptr)
{
otbGenericExceptionMacro(MissingMetadataException,<<"Missing metadata '"<<path<<"'")
......
......@@ -588,29 +588,6 @@ void ImageMetadataInterfaceBase::PrintSelf(std::ostream& os, itk::Indent indent)
}
}
bool ImageMetadataInterfaceBase::ParseStringKey(
const MetadataSupplierInterface * mds,
const char *path,
MDStr key,
int band)
{
const char *res = mds->GetMetadataValue(path);
if (res != nullptr)
{
if (band < 0)
{
m_Imd.StringKeys[key] = std::string(res);
}
else
{
assert( (size_t)(band) < m_Imd.Bands.size());
m_Imd.Bands[band].StringKeys[key] = std::string(res);
}
return true;
}
return false;
}
std::string&
ImageMetadataInterfaceBase::Fetch(
const MetadataSupplierInterface * mds,
......
......@@ -208,7 +208,7 @@ public:
std::string GetResourceFile() override;
/** Get metadata item in GDALDataset, domain can specified as "domain/key" */
const char * GetMetadataValue(const char * path) const override;
const char * GetMetadataValue(const char * path, int band = -1) const override;
/** Set metadata item in GDALDataset, domain can specified as prefix of the
* path, like "domain/key"*/
......@@ -263,6 +263,9 @@ private:
/** Dump the ImageMetadata content into GDAL metadata */
void ExportMetadata();
/** Import the ImageMetadata content from GDAL metadata */
void ImportMetadata();
/** GDAL parameters. */
typedef itk::SmartPointer<GDALDatasetWrapper> GDALDatasetWrapperPointer;
GDALDatasetWrapperPointer m_Dataset;
......
......@@ -1783,7 +1783,7 @@ std::string GDALImageIO::GetResourceFile()
}
const char * GDALImageIO::GetMetadataValue(const char * path) const
const char * GDALImageIO::GetMetadataValue(const char * path, int band) const
{
// detect namespace if any
const char *slash = strchr(path,'/');
......@@ -1796,8 +1796,11 @@ const char * GDALImageIO::GetMetadataValue(const char * path) const
domain_c = domain.c_str();
key = std::string(slash+1);
}
const char * ret = m_Dataset->GetDataSet()->GetMetadataItem(key.c_str(), domain_c);
return ret;
if (band >= 0)
{
return m_Dataset->GetDataSet()->GetRasterBand(band+1)->GetMetadataItem(key.c_str(), domain_c);
}
return m_Dataset->GetDataSet()->GetMetadataItem(key.c_str(), domain_c);
}
void GDALImageIO::SetMetadataValue(const char * path, const char * value, int band)
......@@ -1854,5 +1857,10 @@ void GDALImageIO::ExportMetadata()
}
}
void GDALImageIO::ImportMetadata()
{
// TODO
}
} // end namespace otb
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