Commit e48cb049 authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

BUG: check 'polynomial_format' key on internal keywordmap

Conflicts:
	Modules/Adapters/OSSIMAdapters/src/otbImageKeywordlist.cxx
parent 2b87a899
......@@ -137,38 +137,52 @@ 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')
/* ossimRpcModel::loadState() actually expects certain keyword values to be
* present in the keywordlist. So We check a single keyword value
* (polynomial_format) first. Even though it is not enough to ensure a valid
* ossimRpcModel by checking for presence of one single key but atleast we
* are sure about not to create an ossimRpcModel.
*
* The current mechanism creates ossimRpcModel instance, calls loadState()
* and fails. The below check for 'polynomial_format' save us from creating
* an ossimRpcModel which will be invalid if the 'polynomial_format' is not
* present.
*/
if( m_Keywordlist.find("polynomial_format") != m_Keywordlist.end() )
{
ossimKeywordlist geom_kwl;
this->convertToOSSIMKeywordlist(geom_kwl);
ossimRefPtr<ossimRpcModel> rpcModel = new ossimRpcModel;
if (rpcModel->loadState(geom_kwl))
{
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;
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;
}
return false;
>>>>>>> b6d7b16... BUG: check 'polynomial_format' key on internal keywordmap
}
void
......@@ -253,7 +267,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
hasMetaData = projection->saveState(geom_kwl);
}
}
// if the handler has found a sensor model, copy the tags found
if (hasMetaData && dynamic_cast<ossimSensorModel*>(projection))
{
......@@ -268,7 +282,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
delete handler;
}
}
/**********************************************************/
/* Third try : look for external geom file and RPC tags */
/**********************************************************/
......@@ -277,14 +291,14 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
// If still no metadata, try the ".geom" file
ossimFilename ossimGeomFile = ossimFilename(filename).setExtension(".geom");
otb_kwl = ReadGeometryFromGEOMFile(ossimGeomFile);
// also check any RPC tags
ImageKeywordlist rpc_kwl;
if (checkRpcTag)
{
rpc_kwl = ReadGeometryFromRPCTag(filename);
}
if (otb_kwl.HasKey("type"))
{
// external geom has a "type" keyword
......@@ -298,7 +312,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
{
rpc_kwl.ClearMetadataByKey("type");
}
ossimKeywordlist ossim_test_kwl;
otb_kwl.convertToOSSIMKeywordlist(ossim_test_kwl);
testProj = ossimProjectionFactoryRegistry::instance()
......@@ -310,7 +324,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
}
}
}
// copy keywords found in RPC tags if the external geom is not valid
if (!hasMetaData && rpc_kwl.GetSize() > 0)
{
......@@ -344,7 +358,7 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
// We then verify it is a valid sensor model by using otb::SensorModelAdapter
// which uses ossimSensorModelFactory and ossimPluginProjectionFactory internally,
// thus by-passing the need for a valid ossimImageHandler.
if (!hasMetaData)
{
otbMsgDevMacro(<< "OSSIM MetaData not present ! ");
......@@ -398,7 +412,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
{
ossimKeywordlist geom_kwl;
ImageKeywordlist otb_kwl;
// try to use GeoTiff RPC tag if present.
// Warning : RPC in subdatasets are not supported
GDALDriverH identifyDriverH = GDALIdentifyDriver(filename.c_str(), NULL);
......@@ -407,7 +421,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
// If no driver has identified the dataset, don't try to open it and exit
return otb_kwl;
}
GDALDatasetH datasetH = GDALOpen(filename.c_str(), GA_ReadOnly);
if (datasetH != NULL)
{
......@@ -420,7 +434,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
std::vector<double> lineDenCoefs;
std::vector<double> sampNumCoefs;
std::vector<double> sampDenCoefs;
for (unsigned int k=0; k<20; ++k)
{
lineNumCoefs.push_back(rpcStruct.adfLINE_NUM_COEFF[k]);
......@@ -428,7 +442,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
sampNumCoefs.push_back(rpcStruct.adfSAMP_NUM_COEFF[k]);
sampDenCoefs.push_back(rpcStruct.adfSAMP_DEN_COEFF[k]);
}
ossimRefPtr<ossimRpcModel> rpcModel = new ossimRpcModel;
rpcModel->setAttributes( rpcStruct.dfSAMP_OFF,
rpcStruct.dfLINE_OFF,
......@@ -444,10 +458,10 @@ ReadGeometryFromRPCTag(const std::string& filename)
sampDenCoefs,
lineNumCoefs,
lineDenCoefs);
double errorBias = 0.0;
double errorRand = 0.0;
// setup other metadata
rpcModel->setPositionError(errorBias,errorRand,true);
ossimDrect rectangle(0.0,
......@@ -455,27 +469,27 @@ ReadGeometryFromRPCTag(const std::string& filename)
static_cast<double>(dataset->GetRasterXSize()-1),
static_cast<double>(dataset->GetRasterYSize()-1));
rpcModel->setImageRect(rectangle);
ossimDpt size;
size.line = rectangle.height();
size.samp = rectangle.width();
rpcModel->setImageSize(size);
// Compute 4 corners and reference point
rpcModel->updateModel();
double heightOffset = rpcStruct.dfHEIGHT_OFF;
ossimGpt ulGpt, urGpt, lrGpt, llGpt;
ossimGpt refGndPt;
rpcModel->lineSampleHeightToWorld(rectangle.ul(), heightOffset, ulGpt);
rpcModel->lineSampleHeightToWorld(rectangle.ur(), heightOffset, urGpt);
rpcModel->lineSampleHeightToWorld(rectangle.lr(), heightOffset, lrGpt);
rpcModel->lineSampleHeightToWorld(rectangle.ll(), heightOffset, llGpt);
rpcModel->setGroundRect(ulGpt,urGpt,lrGpt,llGpt);
rpcModel->lineSampleHeightToWorld(rectangle.midPoint(), heightOffset, refGndPt);
rpcModel->setRefGndPt(refGndPt);
// compute ground sampling distance
try
{
......@@ -486,7 +500,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
{
otbMsgDevMacro(<< "OSSIM Compute ground sampling distance FAILED ! ");
}
if (rpcModel->saveState(geom_kwl))
{
otb_kwl.SetKeywordlist(geom_kwl);
......@@ -494,7 +508,7 @@ ReadGeometryFromRPCTag(const std::string& filename)
}
GDALClose(datasetH);
}
return otb_kwl;
}
......
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