Commit 01e43a2e authored by Cédric Traizet's avatar Cédric Traizet

Merge branch 'update_metadata' into 'develop'

Import OTB metadata

See merge request !796
parents 318afdd6 abf425ca
Pipeline #7159 passed with stages
in 6 minutes and 11 seconds
......@@ -184,6 +184,9 @@ std::istream& operator>>(std::istream& is, Time& val)
val.frac_sec = sec - (double) val.tm_sec;
_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)
// Disable Daylight Saving Time
val.tm_isdst = 0;
if (!is.eof())
{
......
......@@ -735,7 +735,6 @@ void GDALImageIO::InternalReadImageInformation()
if (m_NumberOfDimensions == 3)
m_Spacing[2] = 1;
char** papszMetadata = dataset->GetMetadata(nullptr);
/* -------------------------------------------------------------------- */
......@@ -970,7 +969,6 @@ void GDALImageIO::InternalReadImageInformation()
}
}
/* -------------------------------------------------------------------- */
/* Report subdatasets. */
/* -------------------------------------------------------------------- */
......@@ -1096,7 +1094,6 @@ void GDALImageIO::InternalReadImageInformation()
this->SetPixelType(VECTOR);
}
// Read no data value if present
std::vector<bool> isNoDataAvailable(dataset->GetRasterCount(), false);
std::vector<double> noDataValues(dataset->GetRasterCount(), 0);
......@@ -1122,6 +1119,8 @@ void GDALImageIO::InternalReadImageInformation()
m_Imd.Bands.push_back(bmd);
}
ImportMetadata();
if (noDataFound)
{
itk::EncapsulateMetaData<MetaDataKey::BoolVectorType>(dict, MetaDataKey::NoDataValueAvailable, isNoDataAvailable);
......@@ -1928,8 +1927,7 @@ void GDALImageIO::ImportMetadata()
ImageMetadataBase::Keywordlist kwl;
GDALMetadataToKeywordlist(m_Dataset->GetDataSet()->GetMetadata(), kwl);
m_Imd.FromKeywordlist(kwl);
// GCPs are imported directly in the ImageMetadata.
m_Imd.Add(MDGeom::GCP, m_Dataset->GetGCPParam());
// Parsing the bands
for (int band = 0 ; band < m_NbBands ; ++band)
{
......@@ -1937,6 +1935,7 @@ void GDALImageIO::ImportMetadata()
GDALMetadataToKeywordlist(m_Dataset->GetDataSet()->GetRasterBand(band+1)->GetMetadata(), kwl);
m_Imd.Bands[band].FromKeywordlist(kwl);
}
}
void GDALImageIO::KeywordlistToMetadata(ImageMetadataBase::Keywordlist kwl, int band)
......@@ -1960,12 +1959,19 @@ void GDALImageIO::KeywordlistToMetadata(ImageMetadataBase::Keywordlist kwl, int
// Projection have already been exported (see InternalWriteImageInformation)
}
else
{
SetMetadataValue(kv.first.c_str(), kv.second.c_str(), band);
}
}
}
void GDALImageIO::GDALMetadataToKeywordlist(const char* const* metadataList, ImageMetadataBase::Keywordlist &kwl)
{
if (!metadataList)
{
return;
}
// The GDAL metadata string list is formatted as a “Name=value” list with the last pointer value being NULL.
for ( ; *metadataList != nullptr ; ++metadataList )
{
......@@ -2014,7 +2020,9 @@ void GDALImageIO::GDALMetadataToKeywordlist(const char* const* metadataList, Ima
m_Imd.Add(MDGeom::RPC, rpcStruct);
}
else
{
kwl.emplace(fieldName, fieldValue);
}
}
}
......
......@@ -31,7 +31,6 @@ otbGDALReadPxlComplex.cxx
otbGDALImageIOTestCanRead.cxx
otbMultiDatasetReadingInfo.cxx
otbOGRVectorDataIOCanRead.cxx
otbGDALImageIOImportExportMetadata.cxx
otbGDALRPCTransformerTest.cxx
otbGDALRPCTransformerTest2.cxx
)
......@@ -131,16 +130,6 @@ otb_add_test(NAME ioTvGDALImageIOWriteMetadata COMMAND otbIOGDALTestDriver
${TEMP}/ioTvGDALImageIOWriteMetadata.hdr
${TEMP}/ioTvGDALImageIOWriteMetadata_Report.txt
)
# TODO implement this test
# otb_add_test(NAME ioTvGDALImageIOImportExportMetadata_JPEG_99 COMMAND otbIOGDALTestDriver
# --compare-ascii ${NOTOL} ${BASELINE_FILES}/ioTvGDALImageIOImportExportMetadata_JPEG_99.txt
# ${TEMP}/ioTvGDALImageIOImportExportMetadata_JPEG_99.txt
# otbGDALImageIOImportExportMetadata
# ${INPUTDATA}/maur_rgb_24bpp.tif
# ${TEMP}/ioTvGDALImageIOImportExportMetadata_JPEG_99.tif
# ${TEMP}/ioTvGDALImageIOImportExportMetadata_JPEG_99.txt
# )
otb_add_test(NAME ioTvGDALOverviewsBuilder_TIFF COMMAND otbIOGDALTestDriver
otbGDALOverviewsBuilder
......
/*
* 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.
*/
#include "itkMacro.h"
#include <iostream>
#include "otbGDALImageIO.h"
//struct sGDALImageIO : public GDALImageIO
//{
//
//};
int otbGDALImageIOImportExportMetadata(int itkNotUsed(argc), char* argv[])
{
// Verify the number of parameters in the command line
const char* inputFilename = argv[1];
const char* outputFilename = argv[2];
const char* outputTextFilename = argv[3];
std::ofstream outfile(outputTextFilename);
// otb::sGDALImageIO::Pointer io = otb::sGDALImageIO::New();
// io->CanReadFile(inputFilename);
// io->ImportMetadata();
// outfile << io->m_Imd;
//
// otb::sGDALImageIO::Pointer io2 = otb::sGDALImageIO::New();
// io2.CarWriteFile(outputFilename);
// io2->m_Imd = io->m_Imd;
// io2.ExportMetadata();
return EXIT_SUCCESS;
}
......@@ -33,7 +33,6 @@ void RegisterTests()
REGISTER_TEST(otbGDALImageIOTestCanRead);
REGISTER_TEST(otbMultiDatasetReadingInfo);
REGISTER_TEST(otbOGRVectorDataIOTestCanRead);
REGISTER_TEST(otbGDALImageIOImportExportMetadata);
REGISTER_TEST(otbGDALRPCTransformerTest);
REGISTER_TEST(otbGDALRPCTransformerTest2);
}
......@@ -1317,3 +1317,12 @@ otb_add_test(NAME ioTvCompareMetadataTest COMMAND otbImageIOTestDriver
otbImageFileReaderRGBTest
${INPUTDATA}/couleurs_extrait.png
${TEMP}/ioImageFileReaderRGB_PNG2PNG.png )
# Imports metadata from a tif file containing OTB type metadata and export it in another tif
otb_add_test(NAME ioTvImportExportMetadataTest COMMAND otbImageIOTestDriver
--compare-metadata ${EPSILON_9}
${INPUTDATA}/metadataIOexample.tif
${TEMP}/ioTvImportExportMetadataTest.tif
otbImageFileReaderTest
${INPUTDATA}/metadataIOexample.tif # contains OTB metadata
${TEMP}/ioTvImportExportMetadataTest.tif )
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