Skip to content
Snippets Groups Projects
Commit fc0f84b3 authored by Julien Osman's avatar Julien Osman
Browse files

ENH: Add GetNumberOf function to MetadataSupplierInterface

parent f22b8204
No related branches found
No related tags found
1 merge request!807Use SAR metadata in SarRadiometricCalibrationToImageFilter
OrthoRectification
Output Cartographic Map Projection
12
......@@ -69,6 +69,12 @@ public:
*/
bool FetchRPC(ImageMetadata & imd);
/** Get the number of keys starting with path */
unsigned int GetNumberOf(std::string const&) const override
{
otbLogMacro(Error, << "GetNumberOf() not yet implemented in otbGeomMetadataSupplier");
}
/**
* @brief Writes the content of the Geom file into a string
*
......
......@@ -75,6 +75,9 @@ public:
* 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(std::string const& path, char sep=' ', int size=-1, int band=-1) const;
/** Get the number of keys starting with path */
virtual unsigned int GetNumberOf(std::string const& path) const = 0;
};
// TODO : for complex types ...
......
......@@ -102,6 +102,9 @@ public:
int GetNbBands() const override;
/** Get the number of keys starting with path */
unsigned int GetNumberOf(std::string const& path) const override;
/**
* @brief Writes the content of the XML file into a string
*
......@@ -145,7 +148,16 @@ protected:
* contain Name
*/
std::vector<std::string> FetchPartialNameValueMultiple(const std::vector<std::string> &StringVector,
const std::string &Name) const;
const std::string &Name) const;
/**
* @brief In a StringList of “Name=Value” pairs, look for the keys equal to the specified string
* @param papszStrList A StringList that will be searched
* @param pszName A string that will be looked for at the begining of the keys
* @return A StringList containing only the pairs from papszStrList whose key
* start with pszName
*/
std::vector<std::string> GetAllStartWith(char** papszStrList, const char *pszName) const;
private:
/** List of resource files */
......
......@@ -36,7 +36,7 @@ GeomMetadataSupplier::GeomMetadataSupplier(std::string const& fileName)
this->ReadGeomFile();
}
std::string GeomMetadataSupplier::GetMetadataValue(std::string const& path, bool& hasValue, int band) const
std::string GeomMetadataSupplier::GetMetadataValue(std::string const& path, bool& hasValue, int) const
{
auto value = this->m_MetadataDic.find(path);
if(value != this->m_MetadataDic.end())
......@@ -48,7 +48,7 @@ std::string GeomMetadataSupplier::GetMetadataValue(std::string const& path, bool
return "";
}
std::string GeomMetadataSupplier::GetResourceFile(std::string const& s) const
std::string GeomMetadataSupplier::GetResourceFile(std::string const&) const
{
return this->m_FileName;
}
......
......@@ -19,6 +19,7 @@
*/
#include "otbXMLMetadataSupplier.h"
#include <unordered_set>
namespace otb
{
......@@ -220,11 +221,39 @@ std::vector<std::string> XMLMetadataSupplier::FetchPartialNameValueMultiple(cons
return retStringVector;
}
std::vector<std::string> XMLMetadataSupplier::GetAllStartWith(char** papszStrList,
const char *pszName) const
{
std::vector<std::string> retStringVector;
if( papszStrList == nullptr || pszName == nullptr )
return retStringVector;
for( ; *papszStrList != nullptr ; ++papszStrList )
if( strstr(*papszStrList, pszName) == *papszStrList)
retStringVector.push_back(*papszStrList);
return retStringVector;
}
int XMLMetadataSupplier::GetNbBands() const
{
return 0;
}
unsigned int XMLMetadataSupplier::GetNumberOf(std::string const & path) const
{
std::unordered_set<int> idx;
for(auto const& key : GetAllStartWith(m_MetadataDic, path.c_str()))
{
auto after = key.substr(path.size());
if(after.size() > 0 && after.compare(0, 1, "_") == 0)
{
auto sub = after.substr(1, after.find("."));
idx.insert(std::stoi(sub));
}
}
return idx.size();
}
std::string XMLMetadataSupplier::PrintSelf()
{
std::ostringstream oss;
......
......@@ -32,6 +32,7 @@ int otbXMLMetadataSupplierTest(int itkNotUsed(argc), char* argv[])
file.open(outputFilename);
file << mds.GetMetadataValue("OTB.application.name", hasValue) << "\n";
file << mds.GetMetadataValue("OTB.application.parameter_3.name", hasValue) << "\n";
file << mds.GetNumberOf("OTB.application.parameter") << "\n";
file.close();
return EXIT_SUCCESS;
......
......@@ -219,6 +219,13 @@ public:
/** Set the projection system from EPSG code */
void SetEpsgCode(const unsigned int wellKnownCRS);
/** Get the number of keys starting with path */
unsigned int GetNumberOf(std::string const&) const override
{
itkExceptionMacro(
"GetNumberOf() not yet implemented in otbGDALImageIO");
}
protected:
/**
* Constructor.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment