Commit 6baf289a authored by Julien Osman's avatar Julien Osman

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

Metadata refactoring

See merge request orfeotoolbox/otb!707
parents 6ffbc6bb a0d54968
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
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
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
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
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
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
mytime : 2009-08-10T10:30:08.142149Z
First try size: 608
Second try size: 312
Third try size: 312
OrthoRectification
Output Cartographic Map Projection
<?xml version="1.0" ?>
<OTB>
<version>3.18</version>
<build>18-05-2013</build>
<platform>Linux</platform>
<application>
<name>OrthoRectification</name>
<descr>This application allows ortho-rectifying optical images from supported sensors.&#x0A;</descr>
<doc>
<name>Ortho-rectification</name>
<longdescr>An inverse sensor model is built from the input image metadata to convert geographical to raw geometry coordinates. This inverse sensor model is then combined with the chosen map projection to build a global coordinate mapping grid. Last, this grid is used to resample using the chosen interpolation algorithm. A Digital Elevation Model can be specified to account for terrain deformations. &#x0A;In case of SPOT5 images, the sensor model can be approximated by an RPC model in order to speed-up computation.</longdescr>
<authors>OTB-Team</authors>
<limitations>Supported sensors are Pleiades, SPOT5 (TIF format), Ikonos, Quickbird, Worldview2, GeoEye.</limitations>
<seealso>Ortho-rectification chapter from the OTB Software Guide</seealso>
<tags>
<tag>Geometry</tag>
</tags>
</doc>
<parameter mandatory="true">
<key>io.in</key>
<type>InputImage</type>
<name>Input Image</name>
<value>/media/ssh/pc-inglada/media/TeraDisk2/LargeInput/QUICKBIRD/TOULOUSE/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF</value>
</parameter>
<parameter mandatory="true">
<key>io.out</key>
<type>OutputImage</type>
<name>Output Image</name>
<value>/home/rashad/repos/orfeo/build/OTB_/test-build/Testing/Temporary/apTvPrOrthorectifTest_UTM_OutXML1.tif</value>
</parameter>
<parameter mandatory="true">
<key>map</key>
<type>Choice</type>
<name>Output Cartographic Map Projection</name>
<value>utm</value>
</parameter>
<parameter mandatory="true">
<key>outputs.ulx</key>
<type>Float</type>
<name>Upper Left X</name>
<value>374100.8125</value>
</parameter>
<parameter mandatory="true">
<key>outputs.uly</key>
<type>Float</type>
<name>Upper Left Y</name>
<value>4829185</value>
</parameter>
<parameter mandatory="true">
<key>outputs.sizex</key>
<type>Int</type>
<name>Size X</name>
<value>500</value>
</parameter>
<parameter mandatory="true">
<key>outputs.sizey</key>
<type>Int</type>
<name>Size Y</name>
<value>500</value>
</parameter>
<parameter mandatory="true">
<key>outputs.spacingx</key>
<type>Float</type>
<name>Pixel Size X</name>
<value>0.5</value>
</parameter>
<parameter mandatory="true">
<key>outputs.spacingy</key>
<type>Float</type>
<name>Pixel Size Y</name>
<value>-0.5</value>
</parameter>
<parameter mandatory="false">
<key>elev.dem</key>
<type>Directory</type>
<name>DEM directory</name>
<value>/home/rashad/repos/orfeo/OTB-Data/Input/DEM/srtm_directory/</value>
</parameter>
<parameter mandatory="true">
<key>interpolator</key>
<type>Choice</type>
<name>Interpolation</name>
<value>linear</value>
</parameter>
<parameter mandatory="false">
<key>opt.gridspacing</key>
<type>Float</type>
<name>Resampling grid spacing</name>
<value>4</value>
</parameter>
</application>
</OTB>
......@@ -138,6 +138,14 @@ public:
bool operator==(const Self&) const;
inline bool operator!=(const Self&) const;
/** Read an ImageKeywordlist from a geom file
* without calling ossim */
bool ReadGeometry(const std::string & path);
/** Write an ImageKeywordlist to a geom file
* without calling ossim */
void WriteGeometry(const std::string& filename) const;
protected:
/** Methods invoked by Print() to print information about the object
* Typically not called by the user (use Print()
......@@ -163,6 +171,8 @@ OTBOSSIMAdapters_EXPORT ImageKeywordlist ReadGeometryFromGEOMFile(const std::str
OTBOSSIMAdapters_EXPORT ImageKeywordlist ReadGeometryFromRPCTag(const std::string& filename);
/** Write the content of the ImageKeywordlist into a geom file
* \deprecated : use ImageKeywordlist::WriteGeomtry instead */
OTBOSSIMAdapters_EXPORT void WriteGeometry(const ImageKeywordlist& otb_kwl, const std::string& filename);
inline bool ImageKeywordlist::operator!=(const Self& p) const
......
......@@ -456,5 +456,23 @@ void WriteGeometry(const ImageKeywordlist& otb_kwl, const std::string& filename)
}
}
bool ImageKeywordlist::ReadGeometry(const std::string & path)
{
// The geom files used in OTB are simpler than what OSSIM actually supports
// It is basically a list of 'key: value' lines
// if the value contains special character like \n, \r, or if it has whitespaces
// at the beginning or at the end, the value is enclosed in triple double-quotes
// ("""value""")
// TODO
return false;
}
void ImageKeywordlist::WriteGeometry(const std::string& filename) const
{
// Write the image keyword list if any (without using ossimKeywordlist)
// values in the keywordlist matching the regex '\n|\r| $|^ ' must be
// encapsulated with triple double-quotes (""")
// TODO
}
} // namespace otb
This diff is collapsed.
......@@ -28,6 +28,7 @@ set(OTBCommon_SRC
otbWriterWatcherBase.cxx
otbStopwatch.cxx
otbStringToHTML.cxx
otbStringUtilities.cxx
otbExtendedFilenameHelper.cxx
otbLogger.cxx
otbStandardOutputPrintCallback.cxx
......
/*
* 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 "otbStringUtilities.h"
namespace otb
{
string_view lstrip(string_view const& v, string_view const& c )
{
string_view::const_iterator pos = std::find_first_of(
v.cbegin(), v.cend(), c.cbegin(), c.cend(),
[](char c1, char c2) -> bool { return bool(c1 != c2) ;});
// Beware: returned string_view may be empty
return string_view(pos, v.cend());
}
string_view rstrip(string_view const& v, string_view const& c )
{
string_view::const_reverse_iterator pos = std::find_first_of(
v.crbegin(), v.crend(), c.cbegin(), c.cend(),
[](char c1, char c2) -> bool { return bool(c1 != c2) ;});
// Beware: returned string_view may be empty
return string_view(v.cbegin(),&*pos - &(*v.cbegin()));
}
} // end namespace otb
......@@ -31,6 +31,7 @@
#endif
#include "otbImageMetadataInterfaceBase.h"
#include "otbImageCommons.h"
#include "OTBImageBaseExport.h"
namespace otb
......@@ -86,7 +87,9 @@ namespace otb
*/
template <class TPixel, unsigned int VImageDimension = 2>
class OTBImageBase_EXPORT_TEMPLATE Image : public itk::Image<TPixel, VImageDimension>
class OTBImageBase_EXPORT_TEMPLATE Image
: public itk::Image<TPixel, VImageDimension>
, public ImageCommons
{
public:
/** Standard class typedefs. */
......@@ -192,31 +195,18 @@ public:
return NeighborhoodAccessorFunctorType();
}
/** Get the projection coordinate system of the image. */
virtual std::string GetProjectionRef(void) const;
virtual void SetProjectionRef(const std::string& wkt);
/** Get the GCP projection coordinates of the image. */
virtual std::string GetGCPProjection(void) const;
virtual unsigned int GetGCPCount(void) const;
virtual OTB_GCP& GetGCPs(unsigned int GCPnum);
virtual const OTB_GCP& GetGCPs(unsigned int GCPnum) const;
virtual std::string GetGCPId(unsigned int GCPnum) const;
virtual std::string GetGCPInfo(unsigned int GCPnum) const;
virtual double GetGCPRow(unsigned int GCPnum) const;
virtual double GetGCPCol(unsigned int GCPnum) const;
virtual double GetGCPX(unsigned int GCPnum) const;
virtual double GetGCPY(unsigned int GCPnum) const;
virtual double GetGCPZ(unsigned int GCPnum) const;
/** Get the six coefficients of affine geoTtransform. */
virtual VectorType GetGeoTransform(void) const;
/** Get image corners. */
// TODO: GenericRSTransform should be instanciated to translate from physical
// space to EPSG:4328 ?
VectorType GetUpperLeftCorner(void) const;
VectorType GetUpperRightCorner(void) const;
VectorType GetLowerLeftCorner(void) const;
VectorType GetLowerRightCorner(void) const;
/** Get signed spacing */
SpacingType GetSignedSpacing() const;
......@@ -232,12 +222,6 @@ public:
virtual void SetSignedSpacing(SpacingType spacing);
virtual void SetSignedSpacing(double spacing[VImageDimension]);
/** Get image corners. */
virtual VectorType GetUpperLeftCorner(void) const;
virtual VectorType GetUpperRightCorner(void) const;
virtual VectorType GetLowerLeftCorner(void) const;
virtual VectorType GetLowerRightCorner(void) const;
/** Get image keyword list */
virtual ImageKeywordlistType GetImageKeywordlist(void);
......
......@@ -34,113 +34,6 @@ Image<TPixel, VImageDimension>::Image()
{
}
template <class TPixel, unsigned int VImageDimension>
std::string Image<TPixel, VImageDimension>::GetProjectionRef(void) const
{
return (this->GetMetaDataInterface()->GetProjectionRef());
}
template <class TPixel, unsigned int VImageDimension>
void Image<TPixel, VImageDimension>::SetProjectionRef(const std::string& kwl)
{
itk::EncapsulateMetaData<std::string>(this->GetMetaDataDictionary(), MetaDataKey::ProjectionRefKey, kwl);
}
template <class TPixel, unsigned int VImageDimension>
std::string Image<TPixel, VImageDimension>::GetGCPProjection(void) const
{
return (this->GetMetaDataInterface()->GetGCPProjection());
}
template <class TPixel, unsigned int VImageDimension>
unsigned int Image<TPixel, VImageDimension>::GetGCPCount(void) const
{
return (this->GetMetaDataInterface()->GetGCPCount());
}
template <class TPixel, unsigned int VImageDimension>
OTB_GCP& Image<TPixel, VImageDimension>::GetGCPs(unsigned int GCPnum)
{
return (this->GetMetaDataInterface()->GetGCPs(GCPnum));
}
template <class TPixel, unsigned int VImageDimension>
const OTB_GCP& Image<TPixel, VImageDimension>::GetGCPs(unsigned int GCPnum) const
{
return (this->GetMetaDataInterface()->GetGCPs(GCPnum));
}
template <class TPixel, unsigned int VImageDimension>
std::string Image<TPixel, VImageDimension>::GetGCPId(unsigned int GCPnum) const
{
return (this->GetMetaDataInterface()->GetGCPId(GCPnum));
}
template <class TPixel, unsigned int VImageDimension>
std::string Image<TPixel, VImageDimension>::GetGCPInfo(unsigned int GCPnum) const
{
return (this->GetMetaDataInterface()->GetGCPInfo(GCPnum));
}
template <class TPixel, unsigned int VImageDimension>
double Image<TPixel, VImageDimension>::GetGCPRow(unsigned int GCPnum) const
{
return (this->GetMetaDataInterface()->GetGCPRow(GCPnum));
}
template <class TPixel, unsigned int VImageDimension>
double Image<TPixel, VImageDimension>::GetGCPCol(unsigned int GCPnum) const
{
return (this->GetMetaDataInterface()->GetGCPCol(GCPnum));
}
template <class TPixel, unsigned int VImageDimension>
double Image<TPixel, VImageDimension>::GetGCPX(unsigned int GCPnum) const
{
return (this->GetMetaDataInterface()->GetGCPX(GCPnum));
}
template <class TPixel, unsigned int VImageDimension>
double Image<TPixel, VImageDimension>::GetGCPY(unsigned int GCPnum) const
{
return (this->GetMetaDataInterface()->GetGCPY(GCPnum));
}
template <class TPixel, unsigned int VImageDimension>
double Image<TPixel, VImageDimension>::GetGCPZ(unsigned int GCPnum) const
{
return (this->GetMetaDataInterface()->GetGCPZ(GCPnum));
}
template <class TPixel, unsigned int VImageDimension>
typename Image<TPixel, VImageDimension>::VectorType Image<TPixel, VImageDimension>::GetGeoTransform(void) const
{
return (this->GetMetaDataInterface()->GetGeoTransform());
}
template <class TPixel, unsigned int VImageDimension>
typename Image<TPixel, VImageDimension>::VectorType Image<TPixel, VImageDimension>::GetUpperLeftCorner(void) const
{
return (this->GetMetaDataInterface()->GetUpperLeftCorner());
}
template <class TPixel, unsigned int VImageDimension>
typename Image<TPixel, VImageDimension>::VectorType Image<TPixel, VImageDimension>::GetUpperRightCorner(void) const
{
return (this->GetMetaDataInterface()->GetUpperRightCorner());
}
template <class TPixel, unsigned int VImageDimension>
typename Image<TPixel, VImageDimension>::VectorType Image<TPixel, VImageDimension>::GetLowerLeftCorner(void) const
{
return (this->GetMetaDataInterface()->GetLowerLeftCorner());
}
template <class TPixel, unsigned int VImageDimension>
typename Image<TPixel, VImageDimension>::VectorType Image<TPixel, VImageDimension>::GetLowerRightCorner(void) const
{
return (this->GetMetaDataInterface()->GetLowerRightCorner());
}
template <class TPixel, unsigned int VImageDimension>
typename Image<TPixel, VImageDimension>::SpacingType Image<TPixel, VImageDimension>::GetSignedSpacing() const
......@@ -214,6 +107,21 @@ void Image<TPixel, VImageDimension>::CopyInformation(const itk::DataObject* data
{
Superclass::CopyInformation(data);
this->itk::Object::SetMetaDataDictionary(data->GetMetaDataDictionary());
const ImageCommons* imc = dynamic_cast<const ImageCommons*>(data);
if (imc != nullptr)
{
const auto & imd = imc->GetImageMetadata();
if (imd.Bands.size() > 0 && imd.Bands.size() != this->GetNumberOfComponentsPerPixel())
{
SetImageMetadata(ImageMetadata(imd.GeometryKeys, imd.NumericKeys, imd.StringKeys, imd.LUT1DKeys,
imd.LUT2DKeys, imd.TimeKeys, imd.ExtraKeys, ImageMetadata::ImageMetadataBandsType(this->GetNumberOfComponentsPerPixel())));
}
else
{
SetImageMetadata(imd);
}
}
}