Commit 9a1a6e89 authored by Julien Osman's avatar Julien Osman

REFAC: Import the Geom Metadata through GDALImageIO

parent f053fd3d
Pipeline #4957 canceled with stages
in 3 minutes and 36 seconds
......@@ -64,6 +64,7 @@ public:
double m_GCPZ;
OTB_GCP();
OTB_GCP(std::string id, std::string info, double col, double row, double px, double py, double pz);
~OTB_GCP();
void Print(std::ostream& os) const;
......
......@@ -224,7 +224,7 @@ public:
std::string ToJSON(bool multiline=false) const;
/** Import metadata from a string keywordlist.
* Will skip MDGeom::SensorGeometry.
* Will skip MDGeom::SensorGeometry, MDGeom::RPC and MDGeom::GCP.
* Returns True if all keywords were parsed correctly.
*/
bool FromKeywordlist(const Keywordlist&);
......
......@@ -29,6 +29,11 @@ OTB_GCP::OTB_GCP() : m_GCPCol(0), m_GCPRow(0), m_GCPX(0), m_GCPY(0), m_GCPZ(0)
{
}
OTB_GCP::OTB_GCP(std::string id, std::string info, double col, double row, double px, double py, double pz)
: m_Id(id), m_Info(info), m_GCPCol(col), m_GCPRow(row), m_GCPX(px), m_GCPY(py), m_GCPZ(pz)
{
}
OTB_GCP::~OTB_GCP()
{
}
......
......@@ -337,31 +337,17 @@ bool ImageMetadataBase::FromKeywordlist(const Keywordlist& kwl)
auto geomKey = MetaData::MDGeomNames.right.find(kv.first);
if (geomKey != MetaData::MDGeomNames.right.end())
{
if(geomKey->second == MDGeom::RPC)
{
Projection::RPCParam rpcParam;
// TODO: Uncomment when deserialization is implemented
//kv.second >> rpcParam;
this->Add(geomKey->second, rpcParam);
}
else if (geomKey->second == MDGeom::ProjectionEPSG)
if (geomKey->second == MDGeom::ProjectionEPSG)
{
this->Add(geomKey->second, Utils::LexicalCast<int>(kv.second.c_str(), "Keywordlist.second.c_str()"));
}
else if (geomKey->second == MDGeom::GCP)
{
Projection::GCPParam gcpParam;
// TODO: Uncomment when deserialization is implemented
//kv.second >> gcpParam;
this->Add(geomKey->second, gcpParam);
}
// TODO : MDGeom::SAR
// TODO : MDGeom::Adjustment
// skip MDGeom::SensorGeometry (they will be decoded by future SensorModelFactory)
else
else if (geomKey->second == MDGeom::ProjectionWKT ||geomKey->second == MDGeom:: ProjectionProj)
{
this->Add(geomKey->second, kv.second);
}
// skip MDGeom::SensorGeometry, MDGeom::RPC and MDGeom::GCP
continue;
}
// Converting the StringKeys
......
......@@ -25,6 +25,7 @@
#include "itkObjectFactory.h"
#include "otbConfigure.h"
#include "otbGeometryMetadata.h"
class GDALDataset;
......@@ -76,6 +77,8 @@ public:
*/
size_t GetPixelBytes() const;
Projection::GCPParam GetGCPParam() const;
protected:
GDALDatasetWrapper();
......
......@@ -151,4 +151,21 @@ size_t GDALDatasetWrapper::GetPixelBytes() const
return size;
}
Projection::GCPParam GDALDatasetWrapper::GetGCPParam() const
{
Projection::GCPParam gcpParam;
gcpParam.GCPProjection = std::string(m_Dataset->GetGCPProjection());
for ( const GDAL_GCP *gcps = m_Dataset->GetGCPs() ; gcps != gcps + m_Dataset->GetGCPCount() ; ++gcps)
{
gcpParam.GCPs.push_back(OTB_GCP(std::string(gcps->pszId),
std::string(gcps->pszInfo),
gcps->dfGCPPixel,
gcps->dfGCPLine,
gcps->dfGCPX,
gcps->dfGCPY,
gcps->dfGCPZ));
}
return gcpParam;
}
} // end namespace otb
......@@ -1853,6 +1853,9 @@ void GDALImageIO::ImportMetadata()
ImageMetadataBase::Keywordlist kwl;
GDALMetadataToKeywordlist(m_Dataset->GetDataSet()->GetMetadata(), kwl);
m_Imd.FromKeywordlist(kwl);
// GCPs are imported directly in the ImageMetadata.
m_Imd.Add(MDGeom::GCP, m_Dataset->GetGCPParam());
// Parsing the bands
for (int band = 0 ; band < m_NbBands ; ++band)
{
kwl.clear();
......@@ -1883,13 +1886,16 @@ void GDALImageIO::GDALMetadataToKeywordlist(const char* const* metadataList, Ima
std::string::size_type pos = metadataLine.find('=');
std::string fieldName = metadataLine.substr(0, pos);
std::string fieldValue = metadataLine.substr(pos+1);
if((fieldName.size() > 36) && (fieldName.substr(0, 36) == "MDGeomNames[MDGeom::SensorGeometry]."))
{
// Sensor Geometry is imported directly in the ImageMetadata.
// TODO: Keys Starting with: MDGeomNames[MDGeom::SensorGeometry] + '.' should
// be decoded by the (future) SensorModelFactory.
}
else if (fieldName == MetaData::MDGeomNames.left.at(MDGeom::RPC))
{
// RPC Models are imported directly in the ImageMetadata.
Projection::RPCParam rpcStruct;
rpcStruct.LineOffset = this->GetAs<double>("RPC/LINE_OFF");
rpcStruct.SampleOffset = this->GetAs<double>("RPC/SAMP_OFF");
......
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