diff --git a/Code/IO/otbImageMetadataInterfaceBase.cxx b/Code/IO/otbImageMetadataInterfaceBase.cxx index 00e53f725981180da30bfe2c91be1e2e7ec752c2..4682ed67b3d3ff272066400a8fefe4cd5e1130e7 100755 --- a/Code/IO/otbImageMetadataInterfaceBase.cxx +++ b/Code/IO/otbImageMetadataInterfaceBase.cxx @@ -420,6 +420,35 @@ ImageMetadataInterfaceBase::GetBandName( const MetaDataDictionaryType & dict ) c return outputValues; } +double ImageMetadataInterfaceBase::GetXPixelSpacing( const MetaDataDictionaryType & dict ) const +{ + ImageKeywordlistType ImageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist); + } + ossimKeywordlist kwl; + ImageKeywordlist.convertToOSSIMKeywordlist(kwl); + std::string key= "support_data.x_pixel_spacing"; + ossimString keywordString = kwl.find(key.c_str()); + return keywordString.toDouble(); +} + +double ImageMetadataInterfaceBase::GetYPixelSpacing( const MetaDataDictionaryType & dict ) const +{ + ImageKeywordlistType ImageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist); + } + ossimKeywordlist kwl; + ImageKeywordlist.convertToOSSIMKeywordlist(kwl); + std::string key= "support_data.y_pixel_spacing"; + ossimString keywordString = kwl.find(key.c_str()); + return keywordString.toDouble(); +} void ImageMetadataInterfaceBase::PrintSelf(std::ostream& os, itk::Indent indent, const MetaDataDictionaryType & dict) const diff --git a/Code/IO/otbImageMetadataInterfaceBase.h b/Code/IO/otbImageMetadataInterfaceBase.h index 664a4aa06f10e8c16511ea2dca127534a8976a59..147e4c5347ca70bdb472573838404566417b688e 100755 --- a/Code/IO/otbImageMetadataInterfaceBase.h +++ b/Code/IO/otbImageMetadataInterfaceBase.h @@ -202,6 +202,14 @@ public: virtual VariableLengthVectorType GetLastWavelengths( const MetaDataDictionaryType & dict ) const =0; otbMetadataGetMacro(LastWavelengths, VariableLengthVectorType); + /** Get the x resolution */ + double GetXPixelSpacing( const MetaDataDictionaryType & dict ) const; + otbMetadataGetMacro(XPixelSpacing, double); + + /** Get the y resolution */ + double GetYPixelSpacing( const MetaDataDictionaryType & dict ) const; + otbMetadataGetMacro(YPixelSpacing, double); + virtual bool CanRead( const MetaDataDictionaryType & dict ) const =0; virtual void PrintSelf(std::ostream& os, itk::Indent indent, const MetaDataDictionaryType & dict) const; diff --git a/Code/Visualization/otbImageLayer.txx b/Code/Visualization/otbImageLayer.txx index dd48a7ad48a023b5f1e8aa3f0f71593e563d9fb8..b91c5b3f7926d4e3680eba1d8b0229b1e8a9b15c 100755 --- a/Code/Visualization/otbImageLayer.txx +++ b/Code/Visualization/otbImageLayer.txx @@ -26,6 +26,7 @@ #include "otbImageKeywordlist.h" // #include "otbCoordinateToName.h" +#include "otbImageMetadataInterfaceBase.h" namespace otb { @@ -300,6 +301,30 @@ ImageLayer<TImage,TOutputImage> oss << otbGetTextMacro("Location unknown") << std::endl; } } + + /** Metadatas typedef */ + typedef typename ImageMetadataInterfaceBase ImageMetadataInterfaceType; + typedef typename ImageMetadataInterfaceBase::Pointer ImageMetadataInterfacePointerType; + // Build the metadata interface + ImageMetadataInterfacePointerType lImageMetadata = ImageMetadataInterfaceType::New(); + + // Check availability + bool mdIsAvailable = lImageMetadata->CanRead(m_Image->GetMetaDataDictionary()); + + if (mdIsAvailable) + { + double x_spacing = lImageMetadata->GetXPixelSpacing(m_Image->GetMetaDataDictionary()); + double y_spacing = lImageMetadata->GetYPixelSpacing(m_Image->GetMetaDataDictionary()); + oss<< "x res: " << x_spacing << std::endl; + oss<< "y res: " << y_spacing << std::endl; + } + else + { + oss << otbGetTextMacro("Resolution unknown") << std::endl; + } + + + return oss.str(); } diff --git a/Examples/OBIA/otbOBIAExamplesTests.cxx b/Examples/OBIA/otbOBIAExamplesTests.cxx index b7674544635a7b5022697c9cc9168f4cee758216..08728cc154a64f67ca8375cd432a596696fe1848 100755 --- a/Examples/OBIA/otbOBIAExamplesTests.cxx +++ b/Examples/OBIA/otbOBIAExamplesTests.cxx @@ -14,7 +14,6 @@ PURPOSE. See the above copyright notices for more information. =========================================================================*/ - // this file defines the otbMultiScaleTest for the test driver // and all it expects is that you have a function called RegisterTests #if defined(_MSC_VER)