Commit 43c568f2 authored by Julien Osman's avatar Julien Osman
Browse files

ENH: Read GCP from GEOM file

parent 7cff3cce
Pipeline #8090 failed with stages
in 4 minutes and 11 seconds
......@@ -72,6 +72,13 @@ public:
*/
bool FetchRPC(ImageMetadata & imd);
/**
* @brief Fill the ImageMetadata with the GCP from the geom file
*
* @param imd The ImageMetadata to fill
*/
bool FetchGCP(ImageMetadata & imd);
/** Get the number of keys starting with path */
unsigned int GetNumberOf(std::string const&) const override
{
......
......@@ -22,11 +22,14 @@
#include <iostream>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
#include <unordered_map>
#include "otbGeomMetadataSupplier.h"
#include "otbMetaDataKey.h"
#include "otbGeometryMetadata.h"
#include "otbStringUtils.h"
#include "otbSARMetadata.h"
namespace otb
{
......@@ -145,6 +148,54 @@ bool GeomMetadataSupplier::FetchRPC(ImageMetadata & imd)
return true;
}
bool GeomMetadataSupplier::FetchGCP(ImageMetadata & imd)
{
int numberOfGcp = GetAs<int>(0, "support_data.geom.gcp.number");
if (numberOfGcp == 0)
return false;
std::stringstream ss;
auto facet = new boost::posix_time::time_input_facet("%Y-%m-%dT%H:%M:%S%F");
ss.imbue(std::locale(std::locale(), facet));
Projection::GCPParam gcpPrm;
std::unordered_map<std::string, GCPTime> gcpTimes;
std::ostringstream oss;
for(int i = 0 ; i < numberOfGcp ; ++i)
{
oss.str("");
oss << "support_data.geom.gcp[" << i << "].";
gcpPrm.GCPs.emplace_back(std::to_string(i), // ID
"", // Comment
GetAs<double>(oss.str() + "im_pt.x"), // col
GetAs<double>(oss.str() + "im_pt.y"), // row
GetAs<double>(oss.str() + "world_pt.lat"), // px
GetAs<double>(oss.str() + "world_pt.lon"), // py
GetAs<double>(oss.str() + "world_pt.hgt")); // pz
GCPTime time;
ss << GetAs<std::string>(oss.str() + "azimuthTime");
ss >> time.azimuthTime;
time.slantRangeTime = GetAs<double>((oss.str() + "slant_range_time"));
gcpTimes[std::to_string(i)] = time;
}
imd.Add(MDGeom::GCP, gcpPrm); // This step will erase the GCP read by GDAL if any.
if(imd.Has(MDGeom::SAR))
{
auto sarParam = boost::any_cast<SARParam>(imd[MDGeom::SAR]);
sarParam.gcpTimes = std::move(gcpTimes);
imd.Add(MDGeom::SAR, sarParam);
}
else
{
SARParam sarParam;
sarParam.gcpTimes = std::move(gcpTimes);
imd.Add(MDGeom::SAR, sarParam);
}
assert(imd.Has(MDGeom::GCP));
return true;
}
std::string GeomMetadataSupplier::PrintSelf() const
{
std::ostringstream oss;
......
......@@ -487,6 +487,7 @@ void ImageFileReader<TOutputImage, ConvertPixelTraits>::GenerateOutputInformatio
GeomMetadataSupplier geomSupplier(m_FilenameHelper->GetExtGEOMFileName(), m_FileName);
ImageMetadataInterfaceFactory::CreateIMI(imd, geomSupplier);
geomSupplier.FetchRPC(imd);
geomSupplier.FetchGCP(imd);
}
// Case 2: attached geom (if present)
else if (!m_FilenameHelper->GetSkipGeom() && itksys::SystemTools::FileExists(attachedGeom))
......@@ -494,6 +495,7 @@ void ImageFileReader<TOutputImage, ConvertPixelTraits>::GenerateOutputInformatio
GeomMetadataSupplier geomSupplier(attachedGeom, m_FileName);
ImageMetadataInterfaceFactory::CreateIMI(imd, geomSupplier);
geomSupplier.FetchRPC(imd);
geomSupplier.FetchGCP(imd);
}
// Case 3: tags in file
else
......
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