Commit 1156ec6c authored by Cédric Traizet's avatar Cédric Traizet

ENH: parse RPCs in IkonosMetadataInterface

parent 14741fa5
Pipeline #5948 failed with stages
in 5 minutes and 31 seconds
......@@ -136,6 +136,8 @@ public:
* There values a computed by 6S. */
WavelengthSpectralBandVectorType GetSpectralSensitivity() const override;
void Parse(const MetadataSupplierInterface *) override;
protected:
IkonosImageMetadataInterface();
~IkonosImageMetadataInterface() override
......
......@@ -786,4 +786,42 @@ IkonosImageMetadataInterface::WavelengthSpectralBandVectorType IkonosImageMetada
return wavelengthSpectralBand;
}
namespace
{
struct IkonosMetadata
{
double sunAzimuth;
}
}
void IkonosImageMetadataInterface::Parse(const MetadataSupplierInterface *mds)
{
assert(mds);
std::cout << "IkonosImageMetadataInterface::Parse " << std::endl;
bool hasValue = 0;
auto metadatatype = mds->GetMetadataValue("METADATATYPE", hasValue);
if (!hasValue || metadatatype != "GE")
{
otbGenericExceptionMacro(MissingMetadataException,
<< "No Geo-Eye metadata has been found")
}
auto inputFilename = mds->GetResourceFile();
auto fileNames = mds->GetResourceFiles();
for (const auto & filename: fileNames )
{
std::cout << filename << std::endl;
}
FetchRPC(*mds);
std::cout << m_Imd << std::endl;
}
} // end namespace otb
......@@ -692,17 +692,48 @@ const boost::any& ImageMetadataInterfaceBase::FetchRPC(
const MetadataSupplierInterface & mds)
{
Projection::RPCParam rpcStruct;
rpcStruct.LineOffset = mds.GetAs<double>("RPC/LINE_OFF");
rpcStruct.SampleOffset = mds.GetAs<double>("RPC/SAMP_OFF");
rpcStruct.LatOffset = mds.GetAs<double>("RPC/LAT_OFF");
rpcStruct.LonOffset = mds.GetAs<double>("RPC/LONG_OFF");
rpcStruct.HeightOffset = mds.GetAs<double>("RPC/HEIGHT_OFF");
rpcStruct.LineScale = mds.GetAs<double>("RPC/LINE_SCALE");
rpcStruct.SampleScale = mds.GetAs<double>("RPC/SAMP_SCALE");
rpcStruct.LatScale = mds.GetAs<double>("RPC/LAT_SCALE");
rpcStruct.LonScale = mds.GetAs<double>("RPC/LONG_SCALE");
rpcStruct.HeightScale = mds.GetAs<double>("RPC/HEIGHT_SCALE");
// In some products, RPC metadata read by GDAL have an unit attached, and the
// fetched string cannot be converted to double directly, e.g.
// LINE_OFF=+002320.00 pixels (from an Ikonos product)
// This lambda removes the unit suffix from the metadata.
auto GetMetadataWithoutUnit = [](const std::string & path,
const MetadataSupplierInterface & mds)
{
const std::vector<std::string> unitNames = {"meters", "degrees", "pixels"};
auto metadataAsString = mds.GetAs<std::string>(path);
for (const auto & name : unitNames)
{
auto i = metadataAsString.find(name);
if (i != std::string::npos)
{
metadataAsString.erase(i, name.size());
break;
}
}
try
{
return std::stod(metadataAsString);
}
catch (const std::invalid_argument&)
{
otbGenericExceptionMacro(MissingMetadataException,<<"Bad metadata value for '"<<path<<"', got: "<<metadataAsString)
}
};
rpcStruct.LineOffset = GetMetadataWithoutUnit("RPC/LINE_OFF", mds);
rpcStruct.SampleOffset = GetMetadataWithoutUnit("RPC/SAMP_OFF", mds);
rpcStruct.LatOffset = GetMetadataWithoutUnit("RPC/LAT_OFF", mds);
rpcStruct.LonOffset = GetMetadataWithoutUnit("RPC/LONG_OFF", mds);
rpcStruct.HeightOffset = GetMetadataWithoutUnit("RPC/HEIGHT_OFF", mds);
rpcStruct.LineScale = GetMetadataWithoutUnit("RPC/LINE_SCALE", mds);
rpcStruct.SampleScale = GetMetadataWithoutUnit("RPC/SAMP_SCALE", mds);
rpcStruct.LatScale = GetMetadataWithoutUnit("RPC/LAT_SCALE", mds);
rpcStruct.LonScale = GetMetadataWithoutUnit("RPC/LONG_SCALE", mds);
rpcStruct.HeightScale = GetMetadataWithoutUnit("RPC/HEIGHT_SCALE", mds);
std::vector<double> coeffs(20);
......
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