Commit 7cee3883 authored by Guillaume Pasero's avatar Guillaume Pasero

Merge branch '1507--geom-file-loading' into 'develop'

Resolve "Inconsistent behaviour of geom file loading"

Closes #1507

See merge request !13
parents 697ea5ea 5fc45cb6
......@@ -287,60 +287,15 @@ ReadGeometryFromImage(const std::string& filename, bool checkRpcTag)
}
/**********************************************************/
/* Third try : look for external geom file and RPC tags */
/* Third try : look for RPC tags */
/**********************************************************/
if (!hasMetaData)
if (!hasMetaData && 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
std::string geomType(otb_kwl.GetMetadataByKey("type"));
ossimProjection *testProj = ossimProjectionFactoryRegistry::instance()
->createProjection(ossimString(geomType));
if (dynamic_cast<ossimSensorModel*>(testProj))
{
// "type" keyword corresponds to a sensor model : don't erase it
if (rpc_kwl.GetSize() > 0)
{
rpc_kwl.ClearMetadataByKey("type");
}
ossimKeywordlist ossim_test_kwl;
otb_kwl.convertToOSSIMKeywordlist(ossim_test_kwl);
testProj = ossimProjectionFactoryRegistry::instance()
->createProjection(ossim_test_kwl);
if (testProj)
{
// external geom contains a valid sensor geometry
hasMetaData = true;
}
}
}
// check any RPC tags
otb_kwl = ReadGeometryFromRPCTag(filename);
// copy keywords found in RPC tags if the external geom is not valid
if (!hasMetaData && rpc_kwl.GetSize() > 0)
if (!otb_kwl.Empty())
{
const ImageKeywordlist::KeywordlistMap &kwlMap = rpc_kwl.GetKeywordlist();
for (ImageKeywordlist::KeywordlistMap::const_iterator it = kwlMap.begin();
it != kwlMap.end();
++it)
{
if (it->second != "")
{
otb_kwl.AddKey(it->first , it->second);
}
}
hasMetaData = true;
}
}
......
......@@ -398,18 +398,33 @@ ImageFileReader<TOutputImage, ConvertPixelTraits>
{
std::string lFileNameOssimKeywordlist = GetDerivedDatasetSourceFileName(m_FileName);
std::string extension = itksys::SystemTools::GetFilenameLastExtension(lFileNameOssimKeywordlist);
std::string attachedGeom = lFileNameOssimKeywordlist.substr(
0,
lFileNameOssimKeywordlist.size() - extension.size()) + std::string(".geom");
// Update otb Keywordlist
ImageKeywordlist otb_kwl;
if (!m_FilenameHelper->ExtGEOMFileNameIsSet())
// Case 1: external geom supplied through extended filename
if (m_FilenameHelper->ExtGEOMFileNameIsSet())
{
otb_kwl = ReadGeometryFromImage(lFileNameOssimKeywordlist,!m_FilenameHelper->GetSkipRpcTag());
otbMsgDevMacro(<< "Loading internal kwl");
otb_kwl = ReadGeometryFromGEOMFile(m_FilenameHelper->GetExtGEOMFileName());
otbMsgDevMacro(<< "Loading external kwl: "<< m_FilenameHelper->GetExtGEOMFileName());
}
// Case 2: attached geom (if present)
else if (itksys::SystemTools::FileExists(attachedGeom))
{
otb_kwl = ReadGeometryFromGEOMFile(attachedGeom);
otbMsgDevMacro(<< "Loading attached kwl");
}
// Case 3: find an ossimPluginProjection
// Case 4: find an ossimProjection
// Case 5: find RPC tags in TIF
else
{
otb_kwl = ReadGeometryFromGEOMFile(m_FilenameHelper->GetExtGEOMFileName());
otbMsgDevMacro(<< "Loading external kwl");
otb_kwl = ReadGeometryFromImage(lFileNameOssimKeywordlist,!m_FilenameHelper->GetSkipRpcTag());
otbMsgDevMacro(<< "Loading internal kwl");
}
// Don't add an empty ossim keyword list
......
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