From cc440fe171d2425097d39e8d2aed3141b19951d3 Mon Sep 17 00:00:00 2001 From: Julie Brossard <julie.brossard@c-s.fr> Date: Mon, 12 Oct 2020 16:56:37 +0200 Subject: [PATCH] [WIP] Cleaning code --- .../include/otbMetadataSupplierInterface.h | 2 -- .../src/otbImageMetadataInterfaceBase.cxx | 2 -- Modules/Core/Metadata/src/otbMetaDataKey.cxx | 5 +++ .../otbRadarsat2ImageMetadataInterface.cxx | 36 +++++++++++++++---- Modules/Core/Metadata/test/CMakeLists.txt | 5 +-- 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Modules/Core/Metadata/include/otbMetadataSupplierInterface.h b/Modules/Core/Metadata/include/otbMetadataSupplierInterface.h index edc5b2aa1d..b78599207c 100644 --- a/Modules/Core/Metadata/include/otbMetadataSupplierInterface.h +++ b/Modules/Core/Metadata/include/otbMetadataSupplierInterface.h @@ -70,8 +70,6 @@ public: { bool hasValue; std::string ret = GetMetadataValue(path, hasValue, band); - std::cout << "hasValue : " << hasValue << std::endl ; - std::cout << "ret : " << ret << std::endl ; if (!hasValue) { otbGenericExceptionMacro(MissingMetadataException,<<"Missing metadata '"<<path<<"'") diff --git a/Modules/Core/Metadata/src/otbImageMetadataInterfaceBase.cxx b/Modules/Core/Metadata/src/otbImageMetadataInterfaceBase.cxx index afd58a4f6e..c13bfbfd68 100644 --- a/Modules/Core/Metadata/src/otbImageMetadataInterfaceBase.cxx +++ b/Modules/Core/Metadata/src/otbImageMetadataInterfaceBase.cxx @@ -661,14 +661,12 @@ ImageMetadataInterfaceBase::Fetch( const char *path, int band) { - std::cout << "Fetching..." << std::endl ; if (band >= 0) { assert( (size_t)(band) < m_Imd.Bands.size()); m_Imd.Bands[band].Add(key, mds.GetAs<MetaData::Time>(path, band)); return m_Imd.Bands[band][key]; } - std::cout << "path : " << path << std::endl ; m_Imd.Add(key, mds.GetAs<MetaData::Time>(path)); return m_Imd[key]; diff --git a/Modules/Core/Metadata/src/otbMetaDataKey.cxx b/Modules/Core/Metadata/src/otbMetaDataKey.cxx index db6ec2ac91..0a21706a52 100644 --- a/Modules/Core/Metadata/src/otbMetaDataKey.cxx +++ b/Modules/Core/Metadata/src/otbMetaDataKey.cxx @@ -182,6 +182,11 @@ std::istream& operator>>(std::istream& is, Time& val) _OTB_ISTREAM_FAIL_IF( val.tm_sec < 0 || val.tm_sec > 60 ) _OTB_ISTREAM_FAIL_IF( val.frac_sec < 0.0 || val.frac_sec >= 1.0) //_OTB_ISTREAM_FAIL_IF( is.get() != 'Z' ) + if (!is.eof()) + { + _OTB_ISTREAM_FAIL_IF( is.get() != 'Z' ) + } + return is; } diff --git a/Modules/Core/Metadata/src/otbRadarsat2ImageMetadataInterface.cxx b/Modules/Core/Metadata/src/otbRadarsat2ImageMetadataInterface.cxx index 19b2bc6621..184a0de53c 100644 --- a/Modules/Core/Metadata/src/otbRadarsat2ImageMetadataInterface.cxx +++ b/Modules/Core/Metadata/src/otbRadarsat2ImageMetadataInterface.cxx @@ -28,6 +28,7 @@ // useful constants #include <otbMath.h> +#include "otbXMLMetadataSupplier.h" namespace otb { @@ -239,6 +240,8 @@ Radarsat2ImageMetadataInterface::UIntVectorType Radarsat2ImageMetadataInterface: return rgb; } +//" + void Radarsat2ImageMetadataInterface::Parse(const MetadataSupplierInterface *mds) { @@ -247,12 +250,12 @@ void Radarsat2ImageMetadataInterface::Parse(const MetadataSupplierInterface *mds // Metadata read by GDAL Fetch(MDTime::AcquisitionStartTime, *mds, "ACQUISITION_START_TIME"); - // Fetch(MDTime::AcquisitionStopTime, *mds, "ACQUISITION_STOP_TIME"); + // Fetch(MDTime::AcquisitionStopTime, *mds, "PROCESSING_TIME"); Fetch(MDStr::BeamMode, *mds, "BEAM_MODE"); - // Fetch(MDStr::BeamSwath, *mds, "BEAM_SWATH"); Fetch("FACILITY_IDENTIFIER", *mds, "FACILITY_IDENTIFIER"); Fetch(MDNum::LineSpacing, *mds, "LINE_SPACING"); - // Fetch(MDStr::Mission, *mds, "MISSION_ID"); + Fetch(MDNum::PixelSpacing, *mds, "PIXEL_SPACING"); + // Fetch(MDStr::Mission, *mds, "MISSION_ID"); // TODO : product.sourceAttributes.satellite ? // Fetch(MDStr::Mode, *mds, "MODE"); Fetch(MDStr::OrbitDirection, *mds, "ORBIT_DIRECTION"); // Fetch(MDNum::OrbitNumber, *mds, "ORBIT_NUMBER"); @@ -260,9 +263,30 @@ void Radarsat2ImageMetadataInterface::Parse(const MetadataSupplierInterface *mds Fetch(MDStr::ProductType, *mds, "PRODUCT_TYPE"); Fetch(MDStr::Instrument, *mds, "SATELLITE_IDENTIFIER"); Fetch(MDStr::SensorID, *mds, "SENSOR_IDENTIFIER"); - // Fetch(MDStr::Swath, *mds, "SWATH"); + - } + // Product file + std::string ProductFilePath = mds->GetResourceFile("product.xml"); + if (!ProductFilePath.empty()) + { + // std::cout<< ProductFilePath << std::endl; + XMLMetadataSupplier ProductMS(ProductFilePath); + + // m_Imd.Add(MDNum::NumberOfLines, ProductMS.GetAs<int>("product.imageAttributes.rasterAttributes.numberOfLines")); + // m_Imd.Add(MDNum::NumberOfColumns, ProductMS.GetAs<int>("product.imageAttributes.rasterAttributes.numberOfSamplesPerLine")); + m_Imd.Add(MDTime::ProductionDate, + ProductMS.GetFirstAs<MetaData::Time>("product.imageGenerationParameters.generalProcessingInformation.processingTime")); + // m_Imd.Add(MDNum::RadarFrequency, ProductMS.GetAs<double>("product.sourceAttributes.radarParameters.radarCenterFrequency")); + // m_Imd.Add(MDNum::AverageSceneHeight, ProductMS.GetAs<double>("product.imageAttributes.geographicInformation.referenceEllipsoidParameters.geodeticTerrainHeight")); + + SARParam sarParam; + for (int bandId = 0 ; bandId < mds->GetNbBands() ; ++bandId) + { + Fetch(MDStr::Polarization, *mds, "POLARIMETRIC_INTERP", bandId); + m_Imd.Bands[bandId].Add(MDGeom::SAR, sarParam); + } + } +} -} // end namespace otb +} // end namespace otb \ No newline at end of file diff --git a/Modules/Core/Metadata/test/CMakeLists.txt b/Modules/Core/Metadata/test/CMakeLists.txt index b20374f6cb..946fb0dbf5 100644 --- a/Modules/Core/Metadata/test/CMakeLists.txt +++ b/Modules/Core/Metadata/test/CMakeLists.txt @@ -431,8 +431,9 @@ otb_add_test(NAME ioTuotbXMLMetadataSupplierTest COMMAND otbMetadataTestDriver ) - -otb_add_test(NAME ioTvImageMetadataInterfaceTest_Radarsat2 COMMAND otbMetadataTestDriver + otb_add_test(NAME ioTvImageMetadataInterfaceTest_Radarsat2 COMMAND otbMetadataTestDriver + --compare-ascii ${EPSILON_9} ${BASELINE_FILES}/ioTvImageMetadataInterfaceTest_Radarsat2.txt + ${TEMP}/ioTvImageMetadataInterfaceTest_Radarsat2.txt otbImageMetadataInterfaceTest LARGEINPUT{RADARSAT2/ALTONA/Fine_Quad-Pol_Dataset/PK6621_DK406_FQ9_20080405_124900_HH_VV_HV_VH_SLC_Altona} ${TEMP}/ioTvImageMetadataInterfaceTest_Radarsat2.txt -- GitLab