From 83fd4fbe2955b0a597e17ec53d4e25ee33f2b624 Mon Sep 17 00:00:00 2001 From: Cyrille Valladeau <cyrille.valladeau@c-s.fr> Date: Fri, 21 Aug 2009 15:53:56 +0200 Subject: [PATCH] ENH : add production date in metadata + correction in IkonosIMI (YY/MM/DD -> MM/DD/YY) --- Code/IO/otbDefaultImageMetadataInterface.h | 36 ++- Code/IO/otbIkonosImageMetadataInterface.cxx | 237 +++++++++++++++--- Code/IO/otbIkonosImageMetadataInterface.h | 21 +- Code/IO/otbImageMetadataInterfaceBase.h | 26 +- Code/IO/otbImageMetadataInterfaceFactory.cxx | 2 +- .../IO/otbQuickBirdImageMetadataInterface.cxx | 214 ++++++++++++++-- Code/IO/otbQuickBirdImageMetadataInterface.h | 21 +- Code/IO/otbSpotImageMetadataInterface.cxx | 171 +++++++++++++ Code/IO/otbSpotImageMetadataInterface.h | 21 +- .../Code/IO/otbImageMetadataInterfaceTest.cxx | 6 +- .../ossim/support_data/ossimIkonosMetaData.h | 2 + .../support_data/ossimSpotDimapSupportData.h | 3 + .../support_data/ossimIkonosMetaData.cpp | 51 ++++ .../ossimSpotDimapSupportData.cpp | 34 +++ 14 files changed, 766 insertions(+), 79 deletions(-) diff --git a/Code/IO/otbDefaultImageMetadataInterface.h b/Code/IO/otbDefaultImageMetadataInterface.h index f388ed0355..33d56ae6df 100644 --- a/Code/IO/otbDefaultImageMetadataInterface.h +++ b/Code/IO/otbDefaultImageMetadataInterface.h @@ -71,24 +71,54 @@ public: itkExceptionMacro("GetSolarIrradiance not implemented in DefaultImageMetadataInterface, no captor type found"); }; - /** Get the imaging day from the ossim metadata */ + /** Get the imaging acquisition day from the ossim metadata */ int GetDay( const MetaDataDictionaryType & dict ) const { itkExceptionMacro("GetDay not implemented in DefaultImageMetadataInterface, no captor type found"); }; - /** Get the imaging month from the ossim metadata */ + /** Get the imaging acquisition month from the ossim metadata */ int GetMonth( const MetaDataDictionaryType & dict ) const { itkExceptionMacro("GetMonth not implemented in DefaultImageMetadataInterface, no captor type found"); }; - /** Get the imaging month from the ossim metadata */ + /** Get the imaging acquisition year from the ossim metadata */ int GetYear( const MetaDataDictionaryType & dict ) const { itkExceptionMacro("GetYear not implemented in DefaultImageMetadataInterface, no captor type found"); }; + /** Get the imaging acquisition hour from the ossim metadata */ + int GetHour( const MetaDataDictionaryType & dict ) const + { + itkExceptionMacro("GetHour not implemented in DefaultImageMetadataInterface, no captor type found"); + }; + + /** Get the imaging acquisition minute from the ossim metadata */ + int GetMinute( const MetaDataDictionaryType & dict ) const + { + itkExceptionMacro("GetMinute not implemented in DefaultImageMetadataInterface, no captor type found"); + }; + + /** Get the imaging production day from the ossim metadata */ + int GetProductionDay( const MetaDataDictionaryType & dict ) const + { + itkExceptionMacro("GetProductionDay not implemented in DefaultImageMetadataInterface, no captor type found"); + }; + + /** Get the imaging production month from the ossim metadata */ + int GetProductionMonth( const MetaDataDictionaryType & dict ) const + { + itkExceptionMacro("GetProductionMonth not implemented in DefaultImageMetadataInterface, no captor type found"); + }; + + /** Get the imaging production year from the ossim metadata */ + int GetProductionYear( const MetaDataDictionaryType & dict ) const + { + itkExceptionMacro("GetProductionYear not implemented in DefaultImageMetadataInterface, no captor type found"); + }; + /** Get the sat elevation from the ossim metadata */ double GetSatElevation( const MetaDataDictionaryType & dict ) const { diff --git a/Code/IO/otbIkonosImageMetadataInterface.cxx b/Code/IO/otbIkonosImageMetadataInterface.cxx index 9306d6b4dc..49792cd182 100755 --- a/Code/IO/otbIkonosImageMetadataInterface.cxx +++ b/Code/IO/otbIkonosImageMetadataInterface.cxx @@ -117,6 +117,186 @@ IkonosImageMetadataInterface::GetDay( const MetaDataDictionaryType & dict ) cons std::string key; ossimString separatorList; + key = "support_data.acquisition_date"; + separatorList = "-"; + + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if(keywordStrings.size() <= 2) + itkExceptionMacro(<<"Invalid Day"); + + // YYYY/MM/DD + ossimString day = keywordStrings[2]; + + return day.toInt(); +} + + +int +IkonosImageMetadataInterface::GetMonth( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no Ikonos Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + + key = "support_data.acquisition_date"; + separatorList = "-"; + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if(keywordStrings.size() <= 2) + itkExceptionMacro(<<"Invalid Month"); + + // YYYY/MM/DD + ossimString month = keywordStrings[1]; + + return month.toInt(); +} + +int +IkonosImageMetadataInterface::GetHour( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no Ikonos Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + + key = "support_data.acquisition_time"; + separatorList = ":"; + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if(keywordStrings.size() <= 1) + itkExceptionMacro(<<"Invalid Hour"); + + // HH:MM + ossimString hour = keywordStrings[0]; + + return hour.toInt(); +} + + +int +IkonosImageMetadataInterface::GetMinute( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no Ikonos Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + + key = "support_data.acquisition_time"; + separatorList = ":"; + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if(keywordStrings.size() <= 1) + itkExceptionMacro(<<"Invalid Minute"); + + // HH:MM + ossimString minute = keywordStrings[1]; + + return minute.toInt(); +} + + +int +IkonosImageMetadataInterface::GetYear( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no Ikonos Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + + key = "support_data.acquisition_date"; + separatorList = "-"; + + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if( keywordStrings.size() <= 2 ) + itkExceptionMacro("Invalid Year"); + + // YYYY/MM/DD + ossimString year = keywordStrings[0]; + + return year.toInt(); +} + +int +IkonosImageMetadataInterface::GetProductionDay( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no Ikonos Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + key = "support_data.production_date"; separatorList = "/"; @@ -126,16 +306,15 @@ IkonosImageMetadataInterface::GetDay( const MetaDataDictionaryType & dict ) cons if(keywordStrings.size() <= 2) itkExceptionMacro(<<"Invalid Day"); - ossimString day = keywordStrings[2]; // MM/DD/YY - day = keywordStrings[1]; + ossimString day = keywordStrings[1]; return day.toInt(); } int -IkonosImageMetadataInterface::GetMonth( const MetaDataDictionaryType & dict ) const +IkonosImageMetadataInterface::GetProductionMonth( const MetaDataDictionaryType & dict ) const { if( !this->CanRead( dict ) ) { @@ -158,22 +337,19 @@ IkonosImageMetadataInterface::GetMonth( const MetaDataDictionaryType & dict ) co key = "support_data.production_date"; separatorList = "/"; ossimString keywordString = kwl.find(key.c_str()); - //ossimString separatorList = "-T"; - //std::string key= "support_data.image_date"; std::vector<ossimString> keywordStrings = keywordString.split(separatorList); - //assert(keywordStrings.size() > 2); if(keywordStrings.size() <= 2) itkExceptionMacro(<<"Invalid Month"); - ossimString month = keywordStrings[1]; - month = keywordStrings[0]; + // MM/DD/YY + ossimString month = keywordStrings[0]; return month.toInt(); } int -IkonosImageMetadataInterface::GetYear( const MetaDataDictionaryType & dict ) const +IkonosImageMetadataInterface::GetProductionYear( const MetaDataDictionaryType & dict ) const { if( !this->CanRead( dict ) ) { @@ -198,20 +374,21 @@ IkonosImageMetadataInterface::GetYear( const MetaDataDictionaryType & dict ) con ossimString keywordString = kwl.find(key.c_str()); std::vector<ossimString> keywordStrings = keywordString.split(separatorList); - //assert(keywordStrings.size() > 2); + if( keywordStrings.size() <= 2 ) itkExceptionMacro("Invalid Year"); - ossimString year = keywordStrings[0]; - // For Ikonos 2002 is 02 + // MM/DD/YY + int year = keywordStrings[2].toInt(); - year = keywordStrings[2]; - year = "20"+year; + if(year==99) + year += 1900; + else + year += 2000; - return year.toInt(); + return year; } - IkonosImageMetadataInterface::VariableLengthVectorType IkonosImageMetadataInterface ::GetPhysicalBias( const MetaDataDictionaryType & dict ) const @@ -238,29 +415,9 @@ IkonosImageMetadataInterface itkExceptionMacro(<<"Invalid Metadata, no Ikonos Image"); } - ImageKeywordlistType ImageKeywordlist; - - if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) - { - itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist); - } - ossimKeywordlist kwl; - ImageKeywordlist.convertToOSSIMKeywordlist(kwl); - std::string key= "support_data.production_date"; - ossimString keywordString = kwl.find(key.c_str()); - std::string output(keywordString.chars()); - - //The Ikonos production date has the format MM/DD/YY - ossimString separatorList = "/"; - std::vector<ossimString> keywordStrings = keywordString.split(separatorList); - if (keywordStrings.size() < 3) - { - itkGenericExceptionMacro(<<"Could not retrieve the production date for Ikonos"); - } - - int productionYear = keywordStrings[2].toInt(); - int productionMonth = keywordStrings[0].toInt(); - int productionDay = keywordStrings[1].toInt(); + int productionYear = this->GetProductionYear(dict); + int productionMonth = this->GetProductionMonth(dict); + int productionDay = this->GetProductionDay(dict); bool isPost20010122 = false; if ((productionYear > 2) || (productionYear < 99)) isPost20010122 = true; else @@ -273,7 +430,7 @@ IkonosImageMetadataInterface } } - //Value computed from + //Value computed from // http://www.geoeye.com/CorpSite/assets/docs/technical-papers/2009/IKONOS_Esun_Calculations.pdf // to get the equivalent of the SPOT alpha VariableLengthVectorType gain; diff --git a/Code/IO/otbIkonosImageMetadataInterface.h b/Code/IO/otbIkonosImageMetadataInterface.h index 81974edaa4..161d9c7384 100644 --- a/Code/IO/otbIkonosImageMetadataInterface.h +++ b/Code/IO/otbIkonosImageMetadataInterface.h @@ -63,15 +63,30 @@ public: /** Get the solar irradiance from the ossim metadata */ VariableLengthVectorType GetSolarIrradiance( const MetaDataDictionaryType & dict ) const; - /** Get the imaging day from the ossim metadata */ + /** Get the imaging acquisition day from the ossim metadata : "Acquisition Date/Time" metadata variable */ int GetDay( const MetaDataDictionaryType & dict ) const; - /** Get the imaging month from the ossim metadata */ + /** Get the imaging acquisition month from the ossim metadata : "Acquisition Date/Time" metadata variable */ int GetMonth( const MetaDataDictionaryType & dict ) const; - /** Get the imaging month from the ossim metadata */ + /** Get the imaging acquisition year from the ossim metadata : "Acquisition Date/Time" metadata variable */ int GetYear( const MetaDataDictionaryType & dict ) const; + /** Get the imaging acquisition hour from the ossim metadata : "Acquisition Date/Time" metadata variable */ + int GetHour( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging acquisition year from the ossim metadata : "Acquisition Date/Time" metadata variable */ + int GetMinute( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging production day from the ossim metadata : "Creation Date" metadata variable */ + int GetProductionDay( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging production month from the ossim metadata : "Creation Date" metadata variable */ + int GetProductionMonth( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging production year from the ossim metadata : "Creation Date" metadata variable */ + int GetProductionYear( const MetaDataDictionaryType & dict ) const; + /** Get the sat elevation from the ossim metadata */ double GetSatElevation( const MetaDataDictionaryType & dict ) const; diff --git a/Code/IO/otbImageMetadataInterfaceBase.h b/Code/IO/otbImageMetadataInterfaceBase.h index 951b5fe6aa..3a95fc0e97 100644 --- a/Code/IO/otbImageMetadataInterfaceBase.h +++ b/Code/IO/otbImageMetadataInterfaceBase.h @@ -154,18 +154,38 @@ public: virtual VariableLengthVectorType GetSolarIrradiance( const MetaDataDictionaryType & dict ) const =0; otbMetadataGetMacro(SolarIrradiance, VariableLengthVectorType); - /** Get the imaging day from the ossim metadata */ + /** Get the imaging acquisition day from the ossim metadata */ virtual int GetDay( const MetaDataDictionaryType & dict ) const =0; otbMetadataGetMacro(Day, int); - /** Get the imaging month from the ossim metadata */ + /** Get the imaging acquisition month from the ossim metadata */ virtual int GetMonth( const MetaDataDictionaryType & dict ) const =0; otbMetadataGetMacro(Month, int); - /** Get the imaging month from the ossim metadata */ + /** Get the imaging acquisition year from the ossim metadata */ virtual int GetYear( const MetaDataDictionaryType & dict ) const =0; otbMetadataGetMacro(Year, int); + /** Get the imaging acquisition hour from the ossim metadata */ + virtual int GetHour( const MetaDataDictionaryType & dict ) const =0; + otbMetadataGetMacro(Hour, int); + + /** Get the imaging acquisition minute from the ossim metadata */ + virtual int GetMinute( const MetaDataDictionaryType & dict ) const =0; + otbMetadataGetMacro(Minute, int); + + /** Get the imaging production day from the ossim metadata */ + virtual int GetProductionDay( const MetaDataDictionaryType & dict ) const =0; + otbMetadataGetMacro(ProductionDay, int); + + /** Get the imaging production month from the ossim metadata */ + virtual int GetProductionMonth( const MetaDataDictionaryType & dict ) const =0; + otbMetadataGetMacro(ProductionMonth, int); + + /** Get the imaging production year from the ossim metadata */ + virtual int GetProductionYear( const MetaDataDictionaryType & dict ) const =0; + otbMetadataGetMacro(ProductionYear, int); + /** Get the sat elevation from the ossim metadata */ virtual double GetSatElevation( const MetaDataDictionaryType & dict ) const =0; otbMetadataGetMacro(SatElevation, double); diff --git a/Code/IO/otbImageMetadataInterfaceFactory.cxx b/Code/IO/otbImageMetadataInterfaceFactory.cxx index 8a080484ee..f9b564bd82 100644 --- a/Code/IO/otbImageMetadataInterfaceFactory.cxx +++ b/Code/IO/otbImageMetadataInterfaceFactory.cxx @@ -65,7 +65,7 @@ ImageMetadataInterfaceFactory return *k; } } - std::cout<<"bothing found -> use default"<<std::endl; + DefaultImageMetadataInterface::Pointer defaultIMI = DefaultImageMetadataInterface::New(); return dynamic_cast<ImageMetadataInterfaceBase*>(static_cast<DefaultImageMetadataInterface*>(defaultIMI)); } diff --git a/Code/IO/otbQuickBirdImageMetadataInterface.cxx b/Code/IO/otbQuickBirdImageMetadataInterface.cxx index c3bc4a8864..26d74ae29f 100755 --- a/Code/IO/otbQuickBirdImageMetadataInterface.cxx +++ b/Code/IO/otbQuickBirdImageMetadataInterface.cxx @@ -197,6 +197,176 @@ QuickBirdImageMetadataInterface::GetYear( const MetaDataDictionaryType & dict ) return year.toInt(); } +int +QuickBirdImageMetadataInterface::GetHour( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no QuickBird Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + key = "support_data.tlc_date"; + separatorList = "-T:"; + + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if( keywordStrings.size() <= 2 ) + itkExceptionMacro("Invalid Hour"); + + ossimString hour = keywordStrings[3]; + + return hour.toInt(); +} + +int +QuickBirdImageMetadataInterface::GetMinute( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no QuickBird Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + key = "support_data.tlc_date"; + separatorList = "-T:"; + ossimString keywordString = kwl.find(key.c_str()); + + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if( keywordStrings.size() <= 2 ) + itkExceptionMacro("Invalid Minute"); + + ossimString minute = keywordStrings[4]; + + return minute.toInt(); +} + +int +QuickBirdImageMetadataInterface::GetProductionDay( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no QuickBird Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + key = "support_data.generation_date"; + separatorList = "-T"; + + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if(keywordStrings.size() <= 2) + itkExceptionMacro(<<"Invalid Day"); + + ossimString day = keywordStrings[2]; + + return day.toInt(); +} + + +int +QuickBirdImageMetadataInterface::GetProductionMonth( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no QuickBird Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + key = "support_data.generation_date"; + separatorList = "-T"; + + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if(keywordStrings.size() <= 2) + itkExceptionMacro(<<"Invalid Month"); + + ossimString month = keywordStrings[1]; + + return month.toInt(); +} + +int +QuickBirdImageMetadataInterface::GetProductionYear( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no QuickBird Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + key = "support_data.generation_date"; + separatorList = "-T"; + + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if( keywordStrings.size() <= 2 ) + itkExceptionMacro("Invalid Year"); + + ossimString year = keywordStrings[0]; + + return year.toInt(); +} QuickBirdImageMetadataInterface::VariableLengthVectorType QuickBirdImageMetadataInterface @@ -247,29 +417,29 @@ QuickBirdImageMetadataInterface itkExceptionMacro(<<"Invalid Metadata, no QuickBird Image"); } - ImageKeywordlistType ImageKeywordlist; + ImageKeywordlistType ImageKeywordlist; - if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) - { - itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist); - } - ossimKeywordlist kwl; - ImageKeywordlist.convertToOSSIMKeywordlist(kwl); - std::string key= "support_data.generation_date"; - ossimString keywordString = kwl.find(key.c_str()); - std::string output(keywordString.chars()); - - //The Ikonos production date has the format MM/DD/YY - ossimString separatorList = "-"; - std::vector<ossimString> keywordStrings = keywordString.split(separatorList); - if (keywordStrings.size() < 3) - { - itkGenericExceptionMacro(<<"Could not retrieve the production date for Ikonos"); - } - - int productionYear = keywordStrings[0].toInt(); - int productionMonth = keywordStrings[1].toInt(); - int productionDay = keywordStrings[2].toInt(); + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, ImageKeywordlist); + } + ossimKeywordlist kwl; + ImageKeywordlist.convertToOSSIMKeywordlist(kwl); +// std::string key= "support_data.generation_date"; +// ossimString keywordString = kwl.find(key.c_str()); +// std::string output(keywordString.chars()); + +// //The Ikonos production date has the format MM/DD/YY +// ossimString separatorList = "-"; +// std::vector<ossimString> keywordStrings = keywordString.split(separatorList); +// if (keywordStrings.size() < 3) +// { +// itkGenericExceptionMacro(<<"Could not retrieve the production date for Ikonos"); +// } + + int productionYear = this->GetProductionYear(dict);//keywordStrings[0].toInt(); + int productionMonth = this->GetProductionMonth(dict);//keywordStrings[1].toInt(); + int productionDay = this->GetProductionDay(dict);//keywordStrings[2].toInt(); bool isPost20030606 = false; if(productionYear > 2003) isPost20030606 = true; diff --git a/Code/IO/otbQuickBirdImageMetadataInterface.h b/Code/IO/otbQuickBirdImageMetadataInterface.h index ecdfe6c5e5..0c9000f92f 100644 --- a/Code/IO/otbQuickBirdImageMetadataInterface.h +++ b/Code/IO/otbQuickBirdImageMetadataInterface.h @@ -62,15 +62,30 @@ public: /** Get the solar irradiance from the ossim metadata */ VariableLengthVectorType GetSolarIrradiance( const MetaDataDictionaryType & dict ) const; - /** Get the imaging day from the ossim metadata */ + /** Get the imaging acquisition day from the ossim metadata : TLCTime metadata value */ int GetDay( const MetaDataDictionaryType & dict ) const; - /** Get the imaging month from the ossim metadata */ + /** Get the imaging acquisition month from the ossim metadata : TLCTime metadata value */ int GetMonth( const MetaDataDictionaryType & dict ) const; - /** Get the imaging month from the ossim metadata */ + /** Get the imaging acquisition year from the ossim metadata : TLCTime metadata value */ int GetYear( const MetaDataDictionaryType & dict ) const; + /** Get the imaging acquisition hour from the ossim metadata : TLCTime metadata value */ + int GetHour( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging acquisition year from the ossim metadata : TLCTime metadata value */ + int GetMinute( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging production day from the ossim metadata : generationTime metadata value */ + int GetProductionDay( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging production month from the ossim metadata : generationTime metadata value */ + int GetProductionMonth( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging production year from the ossim metadata : generationTime metadata value */ + int GetProductionYear( const MetaDataDictionaryType & dict ) const; + /** Get the sat elevation from the ossim metadata */ double GetSatElevation( const MetaDataDictionaryType & dict ) const; diff --git a/Code/IO/otbSpotImageMetadataInterface.cxx b/Code/IO/otbSpotImageMetadataInterface.cxx index 8a95bbacc7..2d03f6fa37 100755 --- a/Code/IO/otbSpotImageMetadataInterface.cxx +++ b/Code/IO/otbSpotImageMetadataInterface.cxx @@ -204,6 +204,177 @@ SpotImageMetadataInterface::GetYear( const MetaDataDictionaryType & dict ) const return year.toInt(); } +int +SpotImageMetadataInterface::GetHour( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no Spot Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + key = "support_data.image_date"; + separatorList = "-T:"; + + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if( keywordStrings.size() <= 2 ) + itkExceptionMacro("Invalid Hour"); + + ossimString hour = keywordStrings[3]; + + return hour.toInt(); +} + +int +SpotImageMetadataInterface::GetMinute( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no Spot Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + key = "support_data.image_date"; + separatorList = "-T:"; + + ossimString keywordString = kwl.find(key.c_str()); + std::cout<<"SPOT: "<<keywordString<<std::endl; + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + std::cout<<"SPOT: "<<keywordString.size()<<std::endl; + if( keywordStrings.size() <= 2 ) + itkExceptionMacro("Invalid Minute"); + + ossimString minute = keywordStrings[4]; + + return minute.toInt(); +} + +int +SpotImageMetadataInterface::GetProductionDay( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no Spot Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + key = "support_data.production_date"; + separatorList = "-T:"; + + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if(keywordStrings.size() <= 2) + itkExceptionMacro(<<"Invalid Day"); + + ossimString day = keywordStrings[2]; + + return day.toInt(); +} + +int +SpotImageMetadataInterface::GetProductionMonth( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no Spot Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + key = "support_data.production_date"; + separatorList = "-T"; + + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if(keywordStrings.size() <= 2) + itkExceptionMacro(<<"Invalid Month"); + + ossimString month = keywordStrings[1]; + + return month.toInt(); +} + + +int +SpotImageMetadataInterface::GetProductionYear( const MetaDataDictionaryType & dict ) const +{ + if( !this->CanRead( dict ) ) + { + itkExceptionMacro(<<"Invalid Metadata, no Spot Image"); + } + + ImageKeywordlistType imageKeywordlist; + + if (dict.HasKey(MetaDataKey::OSSIMKeywordlistKey)) + { + itk::ExposeMetaData<ImageKeywordlistType>(dict, MetaDataKey::OSSIMKeywordlistKey, imageKeywordlist); + } + + ossimKeywordlist kwl; + imageKeywordlist.convertToOSSIMKeywordlist(kwl); + + std::string key; + ossimString separatorList; + key = "support_data.production_date"; + separatorList = "-T"; + + ossimString keywordString = kwl.find(key.c_str()); + std::vector<ossimString> keywordStrings = keywordString.split(separatorList); + + if( keywordStrings.size() <= 2 ) + itkExceptionMacro("Invalid Year"); + + ossimString year = keywordStrings[0]; + + return year.toInt(); +} SpotImageMetadataInterface::VariableLengthVectorType SpotImageMetadataInterface diff --git a/Code/IO/otbSpotImageMetadataInterface.h b/Code/IO/otbSpotImageMetadataInterface.h index 50a86a0e96..f73e31e713 100644 --- a/Code/IO/otbSpotImageMetadataInterface.h +++ b/Code/IO/otbSpotImageMetadataInterface.h @@ -63,15 +63,30 @@ public: /** Get the solar irradiance from the ossim metadata */ VariableLengthVectorType GetSolarIrradiance( const MetaDataDictionaryType & dict ) const; - /** Get the imaging day from the ossim metadata */ + /** Get the imaging acquisition day from the ossim metadata : IMAGING_DATE metadata variable */ int GetDay( const MetaDataDictionaryType & dict ) const; - /** Get the imaging month from the ossim metadata */ + /** Get the imaging acquisition month from the ossim metadata : IMAGING_DATE metadata variable */ int GetMonth( const MetaDataDictionaryType & dict ) const; - /** Get the imaging month from the ossim metadata */ + /** Get the imaging acquisition year from the ossim metadata : IMAGING_DATE metadata variable */ int GetYear( const MetaDataDictionaryType & dict ) const; + /** Get the imaging acquisition hour from the ossim metadata : IMAGING_DATE metadata variable */ + int GetHour( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging acquisition year from the ossim metadata : IMAGING_DATE metadata variable */ + int GetMinute( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging production day from the ossim metadata : DATASET_PRODUCTION_DATE metadata variable */ + int GetProductionDay( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging production month from the ossim metadata : DATASET_PRODUCTION_DATE metadata variable */ + int GetProductionMonth( const MetaDataDictionaryType & dict ) const; + + /** Get the imaging production year from the ossim metadata : DATASET_PRODUCTION_DATE metadata variable */ + int GetProductionYear( const MetaDataDictionaryType & dict ) const; + /** Get the sat elevation from the ossim metadata */ double GetSatElevation( const MetaDataDictionaryType & dict ) const; diff --git a/Testing/Code/IO/otbImageMetadataInterfaceTest.cxx b/Testing/Code/IO/otbImageMetadataInterfaceTest.cxx index 8e4be57268..f6366a16be 100644 --- a/Testing/Code/IO/otbImageMetadataInterfaceTest.cxx +++ b/Testing/Code/IO/otbImageMetadataInterfaceTest.cxx @@ -46,13 +46,17 @@ int otbImageMetadataInterfaceTest (int argc, char* argv[]) std::ofstream file; file.open(outputFilename); - file<<"GetSensorID: "<<lImageMetadata->GetSensorID(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; file<<"GetPhysicalGain: "<<lImageMetadata->GetPhysicalGain(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; file<<"GetPhysicalBias: "<<lImageMetadata->GetPhysicalBias(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; + file<<"GetMinute: "<<lImageMetadata->GetMinute(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; + file<<"GetHour: "<<lImageMetadata->GetHour(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; file<<"GetDay: "<<lImageMetadata->GetDay(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; file<<"GetMonth: "<<lImageMetadata->GetMonth(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; file<<"GetYear: "<<lImageMetadata->GetYear(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; + file<<"GetProductionDay: "<<lImageMetadata->GetProductionDay(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; + file<<"GetProductionMonth: "<<lImageMetadata->GetProductionMonth(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; + file<<"GetProductionYear: "<<lImageMetadata->GetProductionYear(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; file<<"GetSolarIrradiance: "<<lImageMetadata->GetSolarIrradiance(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; file<<"GetSatElevation: "<<lImageMetadata->GetSatElevation(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; file<<"GetSatAzimuth: "<<lImageMetadata->GetSatAzimuth(reader->GetOutput()->GetMetaDataDictionary())<<std::endl; diff --git a/Utilities/otbossim/include/ossim/support_data/ossimIkonosMetaData.h b/Utilities/otbossim/include/ossim/support_data/ossimIkonosMetaData.h index 3702ec0269..cab0ffee89 100644 --- a/Utilities/otbossim/include/ossim/support_data/ossimIkonosMetaData.h +++ b/Utilities/otbossim/include/ossim/support_data/ossimIkonosMetaData.h @@ -108,6 +108,8 @@ private: ossim_uint32 theNumBands; ossimString theBandName; ossimString theProductionDate; + ossimString theAcquisitionDate; + ossimString theAcquisitionTime; ossimString theSensorID; TYPE_DATA diff --git a/Utilities/otbossim/include/ossim/support_data/ossimSpotDimapSupportData.h b/Utilities/otbossim/include/ossim/support_data/ossimSpotDimapSupportData.h index 001624ab0d..d4e35e7c6c 100644 --- a/Utilities/otbossim/include/ossim/support_data/ossimSpotDimapSupportData.h +++ b/Utilities/otbossim/include/ossim/support_data/ossimSpotDimapSupportData.h @@ -63,6 +63,7 @@ public: ossimString getSensorID() const; ossimString getMetadataVersionString() const; ossimString getAcquisitionDate() const; + ossimString getProductionDate() const; ossimString getImageID() const; ossimFilename getMetadataFile() const; void getSunAzimuth(ossim_float64& az) const; @@ -208,6 +209,7 @@ private: * theUrCorner * theLrCorner * theLlCorner + * theViewingAngle * * Note that the theRefImagePoint will be the zero based center of the * frame. @@ -219,6 +221,7 @@ private: ossimSpotMetadataVersion theMetadataVersion; ossimString theImageID; ossimFilename theMetadataFile; + ossimString theProductionDate; /* * From xml section: diff --git a/Utilities/otbossim/src/ossim/support_data/ossimIkonosMetaData.cpp b/Utilities/otbossim/src/ossim/support_data/ossimIkonosMetaData.cpp index 282274659f..0056b9c3c2 100644 --- a/Utilities/otbossim/src/ossim/support_data/ossimIkonosMetaData.cpp +++ b/Utilities/otbossim/src/ossim/support_data/ossimIkonosMetaData.cpp @@ -36,6 +36,8 @@ ossimIkonosMetaData::ossimIkonosMetaData() theNumBands(0), theBandName("Unknown"), theProductionDate("Unknown"), + theAcquisitionDate("Unknown"), + theAcquisitionTime("Unknown"), theSensorID("Unknown") { } @@ -120,6 +122,8 @@ void ossimIkonosMetaData::clearFields() theNumBands = 0; theBandName = "Unknown"; theProductionDate = "Unknown"; + theAcquisitionDate = "Unknown"; + theAcquisitionTime = "Unknown"; theSensorID = "Unknown"; } @@ -135,6 +139,8 @@ std::ostream& ossimIkonosMetaData::print(std::ostream& out) const << "\n Number of bands: " << theNumBands << "\n Band name: " << theBandName << "\n Production date: " << theProductionDate + << "\n Acquisition date: " << theAcquisitionDate + << "\n Acquisition time: " << theAcquisitionTime << "\n Sensor Type: " << theSensorID << "\n" << "\n---------------------------------------------------------" @@ -190,6 +196,17 @@ bool ossimIkonosMetaData::saveState(ossimKeywordlist& kwl, "production_date", theProductionDate, true); + + kwl.add(prefix, + "acquisition_date", + theAcquisitionDate, + true); + + kwl.add(prefix, + "acquisition_time", + theAcquisitionTime, + true); + kwl.add(prefix, "sensor", theSensorID, @@ -263,6 +280,18 @@ bool ossimIkonosMetaData::loadState(const ossimKeywordlist& kwl, theProductionDate = lookup; } + lookup = kwl.find(prefix, "acquisition_date"); + if (lookup) + { + theAcquisitionDate = lookup; + } + + lookup = kwl.find(prefix, "acquisition_time"); + if (lookup) + { + theAcquisitionTime = lookup; + } + lookup = kwl.find(prefix, "sensor"); if (lookup) { @@ -440,6 +469,28 @@ bool ossimIkonosMetaData::parseMetaData(const ossimFilename& data_file) sscanf(strptr, "%21c %lf %s", dummy, &value, name); theSunElevation = value; + //--- + // Acquisition date and time: + //--- + strptr = strstr(filebuf, "\nAcquisition Date\/Time:"); + if (!strptr) + { + if(traceDebug()) + { + ossimNotify(ossimNotifyLevel_FATAL) + << "FATAL ossimIkonosRpcModel::parseMetaData(data_file): " + << "\n\tAborting construction. Error encountered parsing " + << "presumed meta-data file." << std::endl; + + delete [] filebuf; + return false; + } + } + char name2[80]; + sscanf(strptr, "%23c %s %s", dummy, name, name2); + theAcquisitionDate = name; + theAcquisitionTime = name2; + delete [] filebuf; filebuf = 0; diff --git a/Utilities/otbossim/src/ossim/support_data/ossimSpotDimapSupportData.cpp b/Utilities/otbossim/src/ossim/support_data/ossimSpotDimapSupportData.cpp index 026c237d27..cfbe251269 100644 --- a/Utilities/otbossim/src/ossim/support_data/ossimSpotDimapSupportData.cpp +++ b/Utilities/otbossim/src/ossim/support_data/ossimSpotDimapSupportData.cpp @@ -182,6 +182,7 @@ void ossimSpotDimapSupportData::clearFields() theMetadataVersion = OSSIM_SPOT_METADATA_VERSION_UNKNOWN; theImageID = ""; theMetadataFile = ""; + theProductionDate = ""; theSunAzimuth = 0.0; theSunElevation = 0.0; theIncidenceAngle = 0.0; @@ -851,6 +852,7 @@ void ossimSpotDimapSupportData::printInfo(ostream& os) const << "\n " << "\n Job Number (ID): " << theImageID << "\n Acquisition Date: " << theAcquisitionDate + << "\n Production Date: " << theProductionDate << "\n Number of Bands: " << theNumBands << "\n Geo Center Point: " << theRefGroundPoint << "\n Detector count: " << theDetectorCount @@ -898,6 +900,11 @@ ossimString ossimSpotDimapSupportData::getAcquisitionDate() const return theAcquisitionDate; } +ossimString ossimSpotDimapSupportData::getProductionDate() const +{ + return theProductionDate; +} + ossimString ossimSpotDimapSupportData::getImageID() const { return theImageID; @@ -1232,6 +1239,11 @@ bool ossimSpotDimapSupportData::saveState(ossimKeywordlist& kwl, theAcquisitionDate, true); + kwl.add(prefix, + "production_date", + theProductionDate, + true); + kwl.add(prefix, "incident_angle", theIncidenceAngle, @@ -1467,6 +1479,7 @@ bool ossimSpotDimapSupportData::loadState(const ossimKeywordlist& kwl, theSwirDataFlag = ossimString(kwl.find(prefix, "swir_data_flag")).toBool(); theNumBands = ossimString(kwl.find(prefix, ossimKeywordNames::NUMBER_BANDS_KW)).toUInt32(); theAcquisitionDate = kwl.find(prefix, ossimKeywordNames::IMAGE_DATE_KW); + theProductionDate = kwl.find(prefix, "production_date"); theStepCount = ossimString(kwl.find(prefix, "step_count")).toInt32(); theIncidenceAngle = ossimString(kwl.find(prefix, "incident_angle")).toDouble(); @@ -1681,6 +1694,27 @@ bool ossimSpotDimapSupportData::parsePart1( theAcquisitionDate = xml_nodes[0]->getText(); convertTimeStamp(theAcquisitionDate, theRefLineTime); + //--- + // Fetch the ProductionDate: + //--- + xml_nodes.clear(); + xpath = "/Dimap_Document/Production/DATASET_PRODUCTION_DATE"; + xmlDocument->findNodes(xpath, xml_nodes); + if (xml_nodes.size() == 0) + { + setErrorStatus(); + if(traceDebug()) + { + ossimNotify(ossimNotifyLevel_DEBUG) + << MODULE << " DEBUG:" + << "\nCould not find: " << xpath + << std::endl; + } + return false; + } + theProductionDate = xml_nodes[0]->getText(); + + return true; } -- GitLab