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

ENH: Add Sensor model comparison

parent 5df655db
......@@ -165,7 +165,7 @@ struct OTBMetadata_EXPORT RPCParam
oss << " \"" << array[loop] << "\", ";
oss << "]";
return oss.str();
};
}
// Equality comparison with tolerance
template <class BinaryPredicate>
......
......@@ -106,6 +106,8 @@ public:
const boost::any & operator[](const MDGeom& key) const;
const Projection::GCPParam & GetGCPParam() const;
const Projection::RPCParam & GetRPCParam() const;
const SARParam & GetSARParam() const;
std::string GetProjectedGeometry() const;
......@@ -334,6 +336,11 @@ OTBMetadata_EXPORT bool HasSARSensorMetadata(const ImageMetadata & imd);
OTBMetadata_EXPORT void WriteImageMetadataToGeomFile(const ImageMetadata & imd, const std::string & filename);
/** Comparison test */
bool HasSameRPCModel(const ImageMetadataBase& a, const ImageMetadataBase& b);
bool HasSameSARModel(const ImageMetadataBase& a, const ImageMetadataBase& b);
bool HasSameSensorModel(const ImageMetadataBase& a, const ImageMetadataBase& b);
} // end namespace otb
#endif
......@@ -206,6 +206,16 @@ struct OTBMetadata_EXPORT SARParam
/** Keywordlist import */
void FromKeywordlist(const MetaData::Keywordlist & kwl, const std::string & prefix);
// Equality comparison operator (hidden friend idiom)
friend bool operator==(const SARParam & lhs, const SARParam & rhs)
{
MetaData::Keywordlist lhs_kwl;
lhs.ToKeywordlist(lhs_kwl, "");
MetaData::Keywordlist rhs_kwl;
rhs.ToKeywordlist(rhs_kwl, "");
return lhs_kwl == rhs_kwl;
}
};
/** \struct SARCalib
......
......@@ -56,6 +56,16 @@ const Projection::GCPParam & ImageMetadataBase::GetGCPParam() const
return boost::any_cast<const Projection::GCPParam &>(GeometryKeys.at(MDGeom::GCP));
}
const Projection::RPCParam & ImageMetadataBase::GetRPCParam() const
{
return boost::any_cast<const Projection::RPCParam &>(GeometryKeys.at(MDGeom::RPC));
}
const SARParam & ImageMetadataBase::GetSARParam() const
{
return boost::any_cast<const SARParam &>(GeometryKeys.at(MDGeom::SAR));
}
std::string ImageMetadataBase::GetProjectedGeometry() const
{
if (this->Has(MDGeom::ProjectionWKT))
......@@ -843,5 +853,43 @@ void WriteImageMetadataToGeomFile(const ImageMetadata & imd, const std::string &
}
}
bool HasSameRPCModel(const ImageMetadataBase& a, const ImageMetadataBase& b)
{
bool aHasRpc = a.Has(MDGeom::RPC);
bool bHasRpc = b.Has(MDGeom::RPC);
if (aHasRpc && bHasRpc)
// Both have a model
return a.GetRPCParam() == b.GetRPCParam();
else if (aHasRpc != bHasRpc)
// One has a model, not the other
return false;
// Both don't have a model
return true;
}
bool HasSameSARModel(const ImageMetadataBase& a, const ImageMetadataBase& b)
{
bool aHasSar = a.Has(MDGeom::SAR);
bool bHasSar = b.Has(MDGeom::SAR);
if (aHasSar && bHasSar)
// Both have a model
return a.GetSARParam() == b.GetSARParam();
else if (aHasSar != bHasSar)
// One has a model, not the other
return false;
// Both don't have a model
return true;
}
bool HasSameSensorModel(const ImageMetadataBase& a, const ImageMetadataBase& b)
{
return HasSameRPCModel(a, b) && HasSameSARModel(a, b);
}
}
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