Commit ceba8cc2 authored by Guillaume Pasero's avatar Guillaume Pasero
Browse files

ENH: OTB-608 : export RPC coefficients in the correspondant GDAL metadata field

parent 30d2a6a4
......@@ -27,6 +27,7 @@ class GDALDriver;
#include "gdal.h"
#include "gdaljp2metadata.h"
#include "gdal_priv.h"
#include "gdal_alg.h"
namespace otb
{
......
......@@ -26,6 +26,7 @@
#include "otbImage.h"
#include "itkVariableLengthVector.h"
#include "otbTinyXML.h"
#include "otbImageKeywordlist.h"
#include "itkMetaDataObject.h"
#include "otbMetaDataKey.h"
......@@ -1692,6 +1693,24 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer)
dataset->SetMetadataItem(tag.c_str(), value.c_str(), NULL);
}
}
// Report any RPC coefficients
ImageKeywordlist otb_kwl;
itk::ExposeMetaData<ImageKeywordlist>(dict,
MetaDataKey::OSSIMKeywordlistKey,
otb_kwl);
if( otb_kwl.GetSize() != 0 )
{
GDALRPCInfo gdalRpcStruct;
if ( otb_kwl.convertToGDALRPC(gdalRpcStruct) )
{
char **rpcMetadata = RPCInfoToMD(&gdalRpcStruct);
dataset->SetMetadata(rpcMetadata, "RPC");
CSLDestroy( rpcMetadata );
}
}
// END
// Dataset info
......
......@@ -21,7 +21,6 @@
#include "otbMacro.h"
#include "gdal.h"
#include "gdal_priv.h"
#include "ossim/base/ossimKeywordlist.h"
......@@ -30,8 +29,6 @@
#include "ossim/imaging/ossimImageHandlerRegistry.h"
#include "ossim/ossimTileMapModel.h"
#include "ossim/projection/ossimProjectionFactoryRegistry.h"
#include "ossim/imaging/ossimTiffTileSource.h"
#include "ossim/projection/ossimRpcModel.h"
#include "otbSensorModelAdapter.h"
......@@ -129,6 +126,44 @@ convertToOSSIMKeywordlist(ossimKeywordlist& kwl) const
kwl.getMap() = ossimMap;
}
bool
ImageKeywordlist::
convertToGDALRPC(GDALRPCInfo &rpc) const
{
ossimKeywordlist geom_kwl;
this->convertToOSSIMKeywordlist(geom_kwl);
ossimRefPtr<ossimRpcModel> rpcModel = new ossimRpcModel;
if (rpcModel->loadState(geom_kwl))
{
ossimRpcModel::rpcModelStruct ossimRpcStruct;
rpcModel->getRpcParameters(ossimRpcStruct);
if (ossimRpcStruct.type == 'B')
{
rpc.dfSAMP_OFF = ossimRpcStruct.sampOffset;
rpc.dfLINE_OFF = ossimRpcStruct.lineOffset;
rpc.dfSAMP_SCALE = ossimRpcStruct.sampScale;
rpc.dfLINE_SCALE = ossimRpcStruct.lineScale;
rpc.dfLAT_OFF = ossimRpcStruct.latOffset;
rpc.dfLONG_OFF = ossimRpcStruct.lonOffset;
rpc.dfHEIGHT_OFF = ossimRpcStruct.hgtOffset;
rpc.dfLAT_SCALE = ossimRpcStruct.latScale;
rpc.dfLONG_SCALE = ossimRpcStruct.lonScale;
rpc.dfHEIGHT_SCALE = ossimRpcStruct.hgtScale;
memcpy(rpc.adfLINE_NUM_COEFF, ossimRpcStruct.lineNumCoef, sizeof(double) * 20);
memcpy(rpc.adfLINE_DEN_COEFF, ossimRpcStruct.lineDenCoef, sizeof(double) * 20);
memcpy(rpc.adfSAMP_NUM_COEFF, ossimRpcStruct.sampNumCoef, sizeof(double) * 20);
memcpy(rpc.adfSAMP_DEN_COEFF, ossimRpcStruct.sampDenCoef, sizeof(double) * 20);
return true;
}
}
return false;
}
void
ImageKeywordlist::
Print(std::ostream& os, itk::Indent indent) const
......
......@@ -21,6 +21,8 @@
#include <iostream>
#include <map>
#include "gdal.h"
#include "itkObject.h"
#include "itkObjectFactory.h"
......@@ -83,6 +85,10 @@ public:
virtual void AddKey(const std::string& key, const std::string& value);
virtual void convertToOSSIMKeywordlist(ossimKeywordlist& kwl) const;
/** try to convert the image keywordlist into a GDALRpcInfo structure
* return true if successful, false otherwise */
virtual bool convertToGDALRPC(GDALRPCInfo &rpc) const;
virtual void Print(std::ostream& os, itk::Indent indent = 0) const;
......
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