Commit e6b10461 authored by Julien Osman's avatar Julien Osman

Merge branch '2024-metadata-refac' into metadata-sentinel1

parents 934dbc96 0df350d8
{{"Extra.Comment": "Test Extrakeys",
"ProductionDate": "2009-08-10T10:30:08.142149Z",
"ProjectionWKT": "UTM projRef",
"SensorID": "PHR",
}Bands[{"PhysicalBias": "1",
"PhysicalGain": "2",
"BandName": "B0",
"NoData": "-10000",
},{"PhysicalBias": "2",
"PhysicalGain": "3",
"BandName": "B1",
"NoData": "-10000",
},{"PhysicalBias": "1",
"PhysicalGain": "2",
"BandName": "B0",
"NoData": "-10000",
},{"PhysicalBias": "2",
"PhysicalGain": "3",
"BandName": "B1",
"NoData": "-10000",
},{"PhysicalBias": "3",
"PhysicalGain": "4",
"BandName": "B2",
"NoData": "-10000",
},]
}
\ No newline at end of file
SensorID PHR
ProductionDate 2009-08-10T10:30:08.142149Z
ProjectionWKT UTM projRef
Extra.Comment Test Extrakeys
BandName B0
NoData -10000
PhysicalGain 2
PhysicalBias 1
BandName B1
NoData -10000
PhysicalGain 3
PhysicalBias 2
BandName B0
NoData -10000
PhysicalGain 2
PhysicalBias 1
BandName B1
NoData -10000
PhysicalGain 3
PhysicalBias 2
BandName B2
NoData -10000
PhysicalGain 4
PhysicalBias 3
{{"Extra.Information": "Very important",
"Extra.Comment": "Test Extrakeys",
"SensorID": "PHR",
"ProjectionWKT": "UTM projRef",
"ProductionDate": "2009-08-10T10:30:08.142149Z",
"Polarization": "Polarization",
"NoData": "-10000",
"AcquisitionDate": "2009-08-05T20:34:38.236478Z",
}Bands[{"PhysicalBias": "1",
"BandName": "B0",
"PhysicalGain": "2",
},{"PhysicalBias": "2",
"BandName": "B1",
"PhysicalGain": "3",
},{"PhysicalBias": "3",
"BandName": "B2",
"PhysicalGain": "4",
},]
}
\ No newline at end of file
SensorID PHR
Polarization Polarization
NoData -10000
AcquisitionDate 2009-08-05T20:34:38.236478Z
ProductionDate 2009-08-10T10:30:08.142149Z
ProjectionWKT UTM projRef
Extra.Comment Test Extrakeys
Extra.Information Very important
BandName B0
PhysicalGain 2
PhysicalBias 1
BandName B1
PhysicalGain 3
PhysicalBias 2
BandName B2
PhysicalGain 4
PhysicalBias 3
{{"ProductionDate": "2009-08-10T10:30:08.142149Z",
"Polarization": "Polarization",
"ProjectionWKT": "UTM projRef",
"Extra.Comment": "Test Extrakeys",
"SensorID": "SPOT",
}Bands[{"PhysicalBias": "1",
"PhysicalGain": "2",
"BandName": "B0",
"NoData": "-10000",
},{"PhysicalBias": "2",
"PhysicalGain": "3",
"BandName": "B1",
"SunAzimuth": "20",
"NoData": "-10000",
},]
}
\ No newline at end of file
SensorID SPOT
Polarization Polarization
ProductionDate 2009-08-10T10:30:08.142149Z
ProjectionWKT UTM projRef
Extra.Comment Test Extrakeys
BandName B0
NoData -10000
PhysicalGain 2
PhysicalBias 1
BandName B1
NoData -10000
PhysicalGain 3
PhysicalBias 2
SunAzimuth 20
{{"Extra.Comment": "Test Extrakeys",
"ProductionDate": "2009-08-10T10:30:08.142149Z",
"ProjectionWKT": "UTM projRef",
"SensorID": "PHR",
}Bands[{"PhysicalBias": "1",
"PhysicalGain": "2",
"BandName": "B0",
"NoData": "-10000",
},{"PhysicalBias": "2",
"PhysicalGain": "3",
"BandName": "B1",
"NoData": "-10000",
},]
}
\ No newline at end of file
SensorID PHR
ProductionDate 2009-08-10T10:30:08.142149Z
ProjectionWKT UTM projRef
Extra.Comment Test Extrakeys
BandName B0
NoData -10000
PhysicalGain 2
PhysicalBias 1
BandName B1
NoData -10000
PhysicalGain 3
PhysicalBias 2
{{"Extra.Comment": "Test Extrakeys",
"ProjectionEPSG": "4326",
"ProjectionWKT": "UTM projRef",
"ProjectionProj": "+proj=longlat +datum=WGS84 +no_defs ",
"SpectralSensitivity": "LUT1D.DIM0.SIZE = 3
SensorID PHR
ProductionDate 2009-08-10T10:30:08.142149Z
ProjectionWKT UTM projRef
ProjectionEPSG 4326
ProjectionProj +proj=longlat +datum=WGS84 +no_defs
SpectralSensitivity LUT1D.DIM0.SIZE = 3
LUT1D.DIM0.ORIGIN = 0
LUT1D.DIM0.SPACING = 1
LUT1D.ARRAY = 1 2 3"
"RPC": "<RPCParam>",
"ProductionDate": "2009-08-10T10:30:08.142149Z",
"GCP": "<GCPParam>",
"SensorID": "PHR",
}Bands[{"PhysicalBias": "1",
"PhysicalGain": "2",
"BandName": "B0",
"NoData": "-10000",
},{"PhysicalBias": "2",
"PhysicalGain": "3",
"BandName": "B1",
"NoData": "-10000",
},{"PhysicalBias": "3",
"PhysicalGain": "4",
"BandName": "B2",
"NoData": "-10000",
},]
}
\ No newline at end of file
LUT1D.ARRAY = 1 2 3
Extra.Comment Test Extrakeys
BandName B0
NoData -10000
PhysicalGain 2
PhysicalBias 1
BandName B1
NoData -10000
PhysicalGain 3
PhysicalBias 2
BandName B2
NoData -10000
PhysicalGain 4
PhysicalBias 3
......@@ -567,6 +567,11 @@ protected:
/** Image metadata pre-parsed by the ImageIO */
ImageMetadata m_Imd;
/** Mapping between origin components and output components. Note that the buffer is
already mapped after calling the DoMapBuffer method. This attribute is useful to write
band related metadatas. */
std::vector<unsigned int> m_BandList;
private:
ImageIOBase(const Self&) = delete;
void operator=(const Self&) = delete;
......
......@@ -54,8 +54,11 @@ void ImageCommons::SetProjectionRef(const std::string& proj)
std::string ImageCommons::GetGCPProjection(void) const
{
assert(m_Imd.Has(MDGeom::GCP));
return m_Imd.GetGCPParam().GCPProjection;
if (m_Imd.Has(MDGeom::GCP))
{
return m_Imd.GetGCPParam().GCPProjection;
}
return "";
}
......
......@@ -1194,6 +1194,8 @@ std::vector<double> ImageIOBase::GetDefaultDirection(unsigned int k) const
void ImageIOBase::DoMapBuffer(void* buffer, size_t numberOfPixels, std::vector<unsigned int>& bandList)
{
m_BandList = bandList;
size_t componentSize = this->GetComponentSize();
size_t inPixelSize = componentSize * this->GetNumberOfComponents();
size_t outPixelSize = componentSize * bandList.size();
......
......@@ -26,6 +26,7 @@
#include <utility>
#include <cstdlib>
#include "otbStopwatch.h"
#include "otbTestTools.h"
void SetUpImageMetadata(otb::ImageMetadata& md, unsigned int nbBands)
{
......@@ -189,7 +190,7 @@ void otbImageMetadataSliceTest(char* argv[])
SetUpImageMetadata(md, 3);
ImageMetadata md2 = md.slice(0, 1);
outfile << md2;
otb::testtools::PrintMetadata(md2, outfile);
outfile.close();
}
......@@ -207,7 +208,7 @@ void otbImageMetadataAppendTest(char* argv[])
SetUpImageMetadata(md2, 3);
md.append(md2);
outfile << md;
otb::testtools::PrintMetadata(md, outfile);
outfile.close();
}
......@@ -234,7 +235,7 @@ void otbImageMetadataMergeTest(char* argv[])
md.Merge(md2);
outfile << md;
otb::testtools::PrintMetadata(md, outfile);
outfile.close();
}
void otbImageMetadataToFromKeywordlistTest(char* argv[])
......@@ -265,7 +266,7 @@ void otbImageMetadataToFromKeywordlistTest(char* argv[])
md.AppendToKeywordlists(kwlVect);
ImageMetadata md2;
md2.FromKeywordlists(kwlVect);
outfile << md2;
otb::testtools::PrintMetadata(md2, outfile);
outfile.close();
}
......@@ -288,7 +289,7 @@ void otbImageMetadataCompactTest(char* argv[])
}
md.compact();
outfile << md;
otb::testtools::PrintMetadata(md, outfile);
outfile.close();
}
......
......@@ -1294,9 +1294,19 @@ void GDALImageIO::InternalWriteImageInformation(const void* buffer)
// char ** papszOptions = NULL;
std::string driverShortName;
m_NbBands = this->GetNumberOfComponents();
// If the band mapping is different from the one of the input (e.g. because an extended filename
// has been set, the bands in the imageMetadata object needs to be reorganized.
if (!m_BandList.empty())
{
ImageMetadata::ImageMetadataBandsType bandRangeMetadata;
for (auto elem: m_BandList)
{
bandRangeMetadata.push_back(m_Imd.Bands[elem]);
}
m_Imd.Bands = bandRangeMetadata;
}
std::cout << m_Imd << std::endl;
std::cout << "m_NbBands " << (std::size_t)m_NbBands << std::endl;
std::cout << "m_ImdBands size " << m_Imd.Bands.size() << std::endl;
if ( !m_Imd.Bands.empty() && (std::size_t)m_NbBands != m_Imd.Bands.size())
{
......
......@@ -574,6 +574,15 @@ void ImageFileReader<TOutputImage, ConvertPixelTraits>::GenerateOutputInformatio
m_IOComponents = m_BandList.size();
}
// Delete band metadata if the Conversion policy changed the number of bands, in the case of
// grayscale to RGB for example. Because we cannot know how the metadata should be mapped.
// TODO: define proper behavior in this case.
using ConvertIOPixelTraits = otb::DefaultConvertPixelTraits<typename TOutputImage::IOPixelType>;
if (strcmp(output->GetNameOfClass(), "Image") == 0 && !(this->m_ImageIO->GetNumberOfComponents() == ConvertIOPixelTraits::GetNumberOfComponents()))
{
imd.Bands = ImageMetadata::ImageMetadataBandsType (ConvertIOPixelTraits::GetNumberOfComponents());
}
// THOMAS : ajout
// If a VectorImage, this requires us to set the
// VectorLength before allocate
......
/*
* Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
*
* This file is part of Orfeo Toolbox
*
* https://www.orfeo-toolbox.org/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef otbTestTools_h
#define otbTestTools_h
#include "otbMetaDataKey.h"
#include "otbImageMetadata.h"
namespace otb
{
namespace testtools
{
void PrintMetadataBase(ImageMetadataBase imdb, std::ostream& oss)
{
std::unordered_map<std::string, std::string> kwl;
imdb.ToKeywordlist(kwl);
for (auto It = otb::MetaData::MDStrNames.left.begin() ; It != otb::MetaData::MDStrNames.left.end() ; ++It)
{
auto Key = kwl.find(It->second);
if (Key != kwl.end())
oss << It->second << ' ' << Key->second << '\n';
}
for (auto It = otb::MetaData::MDNumNames.left.begin() ; It != otb::MetaData::MDNumNames.left.end() ; ++It)
{
auto Key = kwl.find(It->second);
if (Key != kwl.end())
oss << It->second << ' ' << Key->second << '\n';
}
for (auto It = otb::MetaData::MDTimeNames.left.begin() ; It != otb::MetaData::MDTimeNames.left.end() ; ++It)
{
auto Key = kwl.find(It->second);
if (Key != kwl.end())
oss << It->second << ' ' << Key->second << '\n';
}
for (auto It = otb::MetaData::MDGeomNames.left.begin() ; It != otb::MetaData::MDGeomNames.left.end() ; ++It)
{
auto Key = kwl.find(It->second);
if (Key != kwl.end())
oss << It->second << ' ' << Key->second << '\n';
}
for (auto It = otb::MetaData::MDL1DNames.left.begin() ; It != otb::MetaData::MDL1DNames.left.end() ; ++It)
{
auto Key = kwl.find(It->second);
if (Key != kwl.end())
oss << It->second << ' ' << Key->second << '\n';
}
for (auto It = otb::MetaData::MDL2DNames.left.begin() ; It != otb::MetaData::MDL2DNames.left.end() ; ++It)
{
auto Key = kwl.find(It->second);
if (Key != kwl.end())
oss << It->second << ' ' << Key->second << '\n';
}
std::string prefix("Extra.");
for (const auto& kv : imdb.ExtraKeys)
oss << prefix + kv.first << ' ' << kv.second << '\n';
}
void PrintMetadata(ImageMetadata imd, std::ostream& oss)
{
PrintMetadataBase(imd, oss);
for (ImageMetadataBase imdb : imd.Bands)
PrintMetadataBase(imdb, oss);
}
}
}
#endif
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