Commit d733220c authored by Julien Osman's avatar Julien Osman
Browse files

BUG: Fix the Python API

parent 516310cd
Pipeline #9328 failed with stages
in 79 minutes and 13 seconds
......@@ -58,6 +58,32 @@ inline std::ostream& Join(std::ostream& os, TRange const& range, std::string con
}
return os;
}
/**
* Joins elements from a map (second) into a stream.
* \tparam Tmap Map type
* \param os destination stream
* \param[in] range Range to print
* \param[in] separator Separator string to use between elements.
*
* \return the stream
* \throw None At least, this function is exception neutral.
*/
template <typename Tmap>
inline std::ostream& JoinMap(std::ostream& os, Tmap const& range, std::string const& separator)
{
if (!boost::empty(range))
{
typename boost::range_iterator<Tmap const>::type first = boost::begin(range);
typename boost::range_iterator<Tmap const>::type const last = boost::end(range);
os << first->second;
for (++first; first != last; ++first)
{
os << separator << first->second;
}
}
return os;
}
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
......
......@@ -20,6 +20,7 @@
#include "otbImageMetadata.h"
#include "otbSpatialReference.h"
#include "otbJoinContainer.h"
namespace otb
{
......@@ -201,11 +202,8 @@ bool ImageMetadataBase::Has(const MDStr& key) const
std::string ImageMetadataBase::GetKeyListStr() const
{
std::ostringstream oss;
for (const auto& kv : MetaData::MDStrNames.left)
oss << kv.second << " ";
auto returnString = oss.str();
returnString.pop_back();
return returnString;
JoinMap(oss, MetaData::MDStrNames.left, " ");
return oss.str();
}
// -------------------- LUT1D utility function ----------------------------
......
......@@ -91,7 +91,6 @@ class ImageMetadataBase
{
public:
std::string GetProjectedGeometry() const;
std::string GetProjectionWKT() const;
std::string GetProjectionProj() const;
std::string GetKeyListNum() const;
......@@ -113,7 +112,7 @@ public:
std::string __repr__() {
std::ostringstream oss;
oss << *$self;
return oss.str().c_str();
return oss.str();
}
}
......@@ -174,6 +173,14 @@ public:
return it != otb::MetaData::MDGeomNames.right.end();
}
bool is_extra(const std::string& key) {
return $self->Has(key);
}
std::string get_extra(const std::string& key) {
return $self->operator[](key);
}
bool has(const std::string& key) const {
auto it_num = otb::MetaData::MDNumNames.right.find(key);
if (it_num != otb::MetaData::MDNumNames.right.end())
......@@ -199,7 +206,7 @@ public:
if (it_geom != otb::MetaData::MDGeomNames.right.end())
return $self->Has(it_geom->second);
return false;
return $self->Has(key);
}
void __setitem__(const std::string& key, const double val) {
......@@ -214,7 +221,13 @@ public:
if (it != otb::MetaData::MDStrNames.right.end())
$self->Add(it->second, val);
else
$self->Add(key, val);
{
auto it2 = otb::MetaData::MDGeomNames.right.find(key);
if (it2 != otb::MetaData::MDGeomNames.right.end())
$self->Add(it2->second, val);
else
$self->Add(key, val);
}
}
void __setitem__(const std::string& key, const otb::MetaData::LUT1D& val) {
auto it = otb::MetaData::MDL1DNames.right.find(key);
......@@ -263,6 +276,8 @@ public:
return self.get_time(key)
elif self.is_geom(key):
return None # TODO: the geom part of the Imagemetadata is not wrapped yet
elif self.is_extra(key):
return self.get_extra(key)
else:
return None
}
......
Supports Markdown
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