diff --git a/Data/Baseline/OTB/Files/ioTuotbGeomMetadataSupplierTest.txt b/Data/Baseline/OTB/Files/ioTuotbGeomMetadataSupplierTest.txt index 74cf65821c6dfbd7790f61868f856013922d8ef1..ba8a5893601173216985bd2abac09cd0e41ea1eb 100644 --- a/Data/Baseline/OTB/Files/ioTuotbGeomMetadataSupplierTest.txt +++ b/Data/Baseline/OTB/Files/ioTuotbGeomMetadataSupplierTest.txt @@ -39,3 +39,19 @@ adjustment_0.adj_param_4.lock_flag : 0 adjustment_0.adj_param_4.parameter : 0 adjustment_0.adj_param_4.sigma : 0.1 adjustment_0.adj_param_4.units : degrees + +{"LineOffset": "14522", +"SampleOffset": "13779", +"LatOffset": "43.5668", +"LonOffset": "1.4635", +"HeightOffset": "242", +"LineScale": "14767", +"SampleScale": "13799", +"LatScale": "0.0881", +"LonScale": "0.1095", +"HeightScale": "500", +"LineNum": [ "-0.00139825", "0.00153793", "-0.986303", "0.0160753", "3.45261e-05", "-1.10444e-06", "0.00025058", "-0.000783885", "0.00210043", "-5.89713e-06", "-8.42682e-07", "5.24613e-08", "2.93096e-05", "0", "-8.65437e-06", "-4.4754e-05", "-1.0574e-05", "4.18275e-07", "-4.687e-06", "1.93054e-07", ], +"LineDen": [ "1", "3.82226e-05", "0.000565666", "0.00027757", "1.71173e-05", "-4.27783e-07", "-2.03092e-06", "6.16391e-06", "-2.06465e-05", "1.08768e-05", "4.17567e-08", "5.94172e-08", "-4.37271e-06", "0", "3.06573e-08", "0.00043593", "7.99703e-08", "0", "-1.43435e-05", "2.29249e-08", ], +"SampleNum": [ "-0.00263535", "1.00384", "0.0034115", "0.000261524", "-0.00232656", "0.000620898", "-0.000415032", "0.00128362", "-0.00119353", "7.47621e-06", "2.39993e-06", "-2.14036e-05", "-4.92957e-05", "-1.14876e-05", "8.27706e-05", "-7.63615e-05", "-2.79215e-07", "3.04261e-07", "7.00103e-06", "-2.55119e-08", ], +"SampleDen": [ "1", "0.00136456", "0.00234838", "-0.000621177", "-5.99001e-05", "1.56209e-06", "-1.88818e-06", "-4.23341e-06", "3.14449e-05", "-1.20077e-05", "-1.56497e-07", "-7.45329e-08", "1.97967e-06", "0", "-1.26249e-07", "-1.4791e-06", "-5.68974e-08", "3.27442e-08", "1.06612e-07", "1.69648e-08", ], +} diff --git a/Modules/Core/Metadata/include/otbGeomMetadataSupplier.h b/Modules/Core/Metadata/include/otbGeomMetadataSupplier.h index 6486eaf375e2bbbea8e4c735528589c7618bd3a3..f5ef799d01139763eea089797574f413afb4f814 100644 --- a/Modules/Core/Metadata/include/otbGeomMetadataSupplier.h +++ b/Modules/Core/Metadata/include/otbGeomMetadataSupplier.h @@ -23,9 +23,11 @@ #include <fstream> #include <boost/algorithm/string.hpp> +#include <boost/any.hpp> #include "OTBMetadataExport.h" #include "otbMetadataSupplierInterface.h" +#include "otbImageMetadata.h" namespace otb @@ -61,6 +63,13 @@ public: int GetNbBands() const override; + /** + * @brief Fill the ImageMetadata with the data from the geom file + * + * @param imd The ImageMetadata to fill + */ + const boost::any& FetchRPC(ImageMetadata & imd); + /** * @brief Writes the content of the Geom file into a string * diff --git a/Modules/Core/Metadata/src/otbGeomMetadataSupplier.cxx b/Modules/Core/Metadata/src/otbGeomMetadataSupplier.cxx index 4c011e89e0b69a1847798e3ae268e431af46a26b..c249152aa4d3973421dd13d644bf4104441e0a68 100644 --- a/Modules/Core/Metadata/src/otbGeomMetadataSupplier.cxx +++ b/Modules/Core/Metadata/src/otbGeomMetadataSupplier.cxx @@ -18,7 +18,12 @@ * limitations under the License. */ +#include <iomanip> +#include <iostream> + #include "otbGeomMetadataSupplier.h" +#include "otbMetaDataKey.h" +#include "otbGeometryMetadata.h" namespace otb { @@ -50,6 +55,56 @@ int GeomMetadataSupplier::GetNbBands() const return 0; } +const boost::any& GeomMetadataSupplier::FetchRPC(ImageMetadata & imd) +{ + Projection::RPCParam rpcStruct; + rpcStruct.LineOffset = this->GetAs<double>("line_off"); + rpcStruct.SampleOffset = this->GetAs<double>("samp_off"); + rpcStruct.LatOffset = this->GetAs<double>("lat_off"); + rpcStruct.LonOffset = this->GetAs<double>("long_off"); + rpcStruct.HeightOffset = this->GetAs<double>("height_off"); + + rpcStruct.LineScale = this->GetAs<double>("line_scale"); + rpcStruct.SampleScale = this->GetAs<double>("samp_scale"); + rpcStruct.LatScale = this->GetAs<double>("lat_scale"); + rpcStruct.LonScale = this->GetAs<double>("long_scale"); + rpcStruct.HeightScale = this->GetAs<double>("height_scale"); + + std::vector<double> coeffs; + int loop = 0; + std::stringstream path; + for (auto & coeff : rpcStruct.LineNum) + { + path.str(""); + path << "line_num_coeff_" << std::setfill('0') << std::setw(2) << loop++; + coeff = this->GetAs<double>(path.str()); + } + loop = 0; + for (auto & coeff : rpcStruct.LineDen) + { + path.str(""); + path << "line_den_coeff_" << std::setfill('0') << std::setw(2) << loop++; + coeff = this->GetAs<double>(path.str()); + } + loop = 0; + for (auto & coeff : rpcStruct.SampleNum) + { + path.str(""); + path << "samp_num_coeff_" << std::setfill('0') << std::setw(2) << loop++; + coeff = this->GetAs<double>(path.str()); + } + loop = 0; + for (auto & coeff : rpcStruct.SampleDen) + { + path.str(""); + path << "samp_den_coeff_" << std::setfill('0') << std::setw(2) << loop++; + coeff = this->GetAs<double>(path.str()); + } + + imd.Add(MDGeom::RPC, rpcStruct); + return imd[MDGeom::RPC]; +} + std::string GeomMetadataSupplier::PrintSelf() { std::ostringstream oss; diff --git a/Modules/Core/Metadata/test/otbGeomMetadataSupplierTest.cxx b/Modules/Core/Metadata/test/otbGeomMetadataSupplierTest.cxx index baff73bc7a73cb90329bed9cc43b6ba2df7aeb26..8e87ebb43dded91b134ff62caed237b177cbc9c1 100644 --- a/Modules/Core/Metadata/test/otbGeomMetadataSupplierTest.cxx +++ b/Modules/Core/Metadata/test/otbGeomMetadataSupplierTest.cxx @@ -58,6 +58,12 @@ int otbGeomMetadataSupplierTest(int itkNotUsed(argc), char* argv[]) } } + file << '\n'; + + otb::ImageMetadata imd; + mds.FetchRPC(imd); + file << boost::any_cast<otb::Projection::RPCParam>(imd[otb::MDGeom::RPC]).ToJSON(true) << '\n'; + file.close(); return EXIT_SUCCESS; }