OTB  9.1.1
Orfeo Toolbox
otbMetaDataKey.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbMetaDataKey_h
22 #define otbMetaDataKey_h
23 
24 #include <string>
25 #include <vector>
26 #include <cstdio>
27 #include <unordered_map>
28 
29 #include <boost/bimap.hpp>
30 #include <boost/algorithm/string.hpp>
31 
32 #include "itkDataObject.h"
33 #include "itkVariableLengthVector.h"
34 
35 #include "OTBMetadataExport.h"
36 #include "otbStringUtils.h"
37 #include "otbJoinContainer.h"
38 
39 namespace otb
40 {
44 namespace MetaDataKey
45 {
46 extern OTBMetadata_EXPORT char const* DriverShortNameKey;
47 extern OTBMetadata_EXPORT char const* DriverLongNameKey;
48 
49 extern OTBMetadata_EXPORT char const* ProjectionRefKey;
50 
51 extern OTBMetadata_EXPORT char const* GCPProjectionKey;
52 extern OTBMetadata_EXPORT char const* GCPParametersKey;
53 extern OTBMetadata_EXPORT char const* GCPCountKey;
54 
55 extern OTBMetadata_EXPORT char const* GeoTransformKey;
56 
57 extern OTBMetadata_EXPORT char const* MetadataKey;
58 extern OTBMetadata_EXPORT char const* SubMetadataKey;
59 
60 extern OTBMetadata_EXPORT char const* UpperLeftCornerKey;
61 extern OTBMetadata_EXPORT char const* UpperRightCornerKey;
62 extern OTBMetadata_EXPORT char const* LowerLeftCornerKey;
63 extern OTBMetadata_EXPORT char const* LowerRightCornerKey;
64 
65 extern OTBMetadata_EXPORT char const* ColorTableNameKey;
66 extern OTBMetadata_EXPORT char const* ColorEntryCountKey;
67 extern OTBMetadata_EXPORT char const* ColorEntryAsRGBKey;
68 
69 extern OTBMetadata_EXPORT char const* VectorDataKeywordlistKey;
70 extern OTBMetadata_EXPORT char const* VectorDataKeywordlistDelimiterKey;
71 
72 extern OTBMetadata_EXPORT char const* ResolutionFactor;
73 extern OTBMetadata_EXPORT char const* SubDatasetIndex;
74 extern OTBMetadata_EXPORT char const* CacheSizeInBytes;
75 
76 extern OTBMetadata_EXPORT char const* TileHintX;
77 extern OTBMetadata_EXPORT char const* TileHintY;
78 
79 extern OTBMetadata_EXPORT char const* NoDataValueAvailable;
80 extern OTBMetadata_EXPORT char const* NoDataValue;
81 
82 extern OTBMetadata_EXPORT char const* DataType;
83 
84 
85 enum KeyType
86 {
94 };
95 /*
96 typedef struct
97 {
98  std::string keyname;
99  KeyType type;
100 } KeyTypeDef; */
101 
103 {
104  std::string keyname;
106 
108  {
109  }
110  KeyTypeDef(const std::string& _keyname, const KeyType& _type)
111  {
112  keyname = _keyname;
113  type = _type;
114  }
115 };
116 
117 KeyType OTBMetadata_EXPORT GetKeyType(const std::string& name);
118 
119 typedef std::vector<double> VectorType;
120 typedef std::vector<bool> BoolVectorType;
121 typedef itk::VariableLengthVector<double> VariableLengthVectorType;
122 }
123 
125 enum class MDNum
126 {
127 // generic
128  TileHintX,
129  TileHintY,
130  DataType,
131  NoData,
132  OrbitNumber,
136 // Display
140 // optical section
141  PhysicalGain,
142  PhysicalBias,
144  SunElevation,
145  SunAzimuth,
146  SatElevation,
147  SatAzimuth,
148  SpectralStep,
149  SpectralMin,
150  SpectralMax,
151 // SAR section
152  CalScale,
153  CalFactor,
154  PRF,
155  RSF,
159  LineSpacing,
160  PixelSpacing,
164  END
165 };
166 
168 enum class MDStr
169 {
170  SensorID,
171  Mission,
172  Instrument,
174  BandName,
176  ProductType,
179  Polarization,
180  Mode,
181  Swath,
183  BeamMode,
184  BeamSwath,
185  AreaOrPoint,
186  LayerType,
187  MetadataType,
188  OtbVersion,
189  END
190 };
191 
193 enum class MDL1D
194 {
196  END
197 };
198 
200 enum class MDL2D
201 {
202  // Sar calibration lut ...
203  END
204 };
205 
207 enum class MDTime
208 {
213  END
214 };
215 
216 enum class MDGeom
217 {
218  ProjectionWKT, // -> string
219  ProjectionEPSG, // -> int
220  ProjectionProj, // -> string
221  RPC, // -> RPCParam
222  SAR, // -> SARParam
223  SARCalib, // -> SARCalib
224  SensorGeometry, // -> boost::any
225  GCP, // -> GCPParam
226  Adjustment, // -> ?
227  Spot5Geometry, //Spot5Param
228  END
229 };
230 
231 namespace MetaData
232 {
233 
234 using Keywordlist = std::unordered_map<std::string, std::string>;
235 
236 struct LUTAxis
237 {
239  int Size;
240 
242  double Origin;
243 
245  double Spacing;
246 
248  std::vector<double> Values;
249 
251  std::string ToJSON(bool multiline=false) const;
252 
253  friend bool operator==(const LUTAxis & lhs, const LUTAxis & rhs)
254  {
255  return lhs.Size == rhs.Size
256  && lhs.Origin == rhs.Origin
257  && lhs.Spacing == rhs.Spacing
258  && lhs.Values == rhs.Values;
259  }
260 };
261 
262 template <unsigned int VDim> class LUT
263 {
264 public:
265  LUTAxis Axis[VDim];
266 
267  std::vector<double> Array;
268 
269  std::string OTBMetadata_EXPORT ToJSON(bool multiline=false) const;
270 
271  std::string OTBMetadata_EXPORT ToString() const;
272 
273  void OTBMetadata_EXPORT FromString(std::string);
274 
275  friend bool operator==(const LUT<VDim> & lhs, const LUT<VDim> & rhs)
276  {
277  return std::equal(std::begin(lhs.Array), std::end(lhs.Array), std::begin(rhs.Array) )
278  && lhs.Array == rhs.Array;
279  }
280 
281 };
282 
283 
284 template <unsigned int VDim>
285 std::ostream& operator<<(std::ostream& os, const LUT<VDim>& val)
286 {
287  os << val.ToString();
288  return os;
289 }
290 
291 
292 typedef LUT<1> LUT1D;
293 
294 typedef LUT<2> LUT2D;
295 
296 template <typename T>
297 inline boost::bimap<T, std::string> bimapGenerator(std::map<T, std::string> inMap)
298 {
299  boost::bimap<T, std::string> bm;
300  for (const auto& kv : inMap)
301  bm.insert({kv.first, kv.second});
302  //bm.insert(typename boost::bimap<T, std::string>::value_type(kv.first, kv.second));
303  return bm;
304 }
305 
306 typedef boost::bimap<MDGeom, std::string> MDGeomBmType;
307 extern OTBMetadata_EXPORT MDGeomBmType MDGeomNames;
308 
309 typedef boost::bimap<MDNum, std::string> MDNumBmType;
310 extern OTBMetadata_EXPORT MDNumBmType MDNumNames;
311 
312 typedef boost::bimap<MDStr, std::string> MDStrBmType;
313 extern OTBMetadata_EXPORT MDStrBmType MDStrNames;
314 
315 typedef boost::bimap<MDTime, std::string> MDTimeBmType;
316 extern OTBMetadata_EXPORT MDTimeBmType MDTimeNames;
317 
318 typedef boost::bimap<MDL1D, std::string> MDL1DBmType;
319 extern OTBMetadata_EXPORT MDL1DBmType MDL1DNames;
320 
321 typedef boost::bimap<MDL2D, std::string> MDL2DBmType;
322 extern OTBMetadata_EXPORT MDL2DBmType MDL2DNames;
323 
324 template<class T>
325 std::string EnumToString(T t);
326 
327 template<>
328 std::string EnumToString(MDGeom value);
329 
330 template<>
331 std::string EnumToString(MDNum value);
332 
333 template<>
334 std::string EnumToString(MDStr value);
335 
336 template<>
337 std::string EnumToString(MDL1D value);
338 
339 template<>
340 std::string EnumToString(MDL2D value);
341 
342 template<>
343 std::string EnumToString(MDTime value);
344 
345 // Specialization for extra keys
346 template<>
347 std::string EnumToString(std::string value);
348 
349 
350 } // end namespace MetaData
351 
352 } // end namespace otb
353 
354 #endif
otb::MetaDataKey::DataType
OTBMetadata_EXPORT char const * DataType
otb::MetaData::MDNumBmType
boost::bimap< MDNum, std::string > MDNumBmType
Definition: otbMetaDataKey.h:309
otb::MDNum::PixelSpacing
@ PixelSpacing
otb::MDGeom::GCP
@ GCP
otb::MDGeom::SARCalib
@ SARCalib
otb::MetaData::LUT2D
LUT< 2 > LUT2D
Definition: otbMetaDataKey.h:294
otb::MetaDataKey::NoDataValueAvailable
OTBMetadata_EXPORT char const * NoDataValueAvailable
otb::MDStr::AreaOrPoint
@ AreaOrPoint
otb::MetaDataKey::TENTIER
@ TENTIER
Definition: otbMetaDataKey.h:88
otb::MDNum::RangeTimeLastPixel
@ RangeTimeLastPixel
otb::MDStr::Swath
@ Swath
otb::MDNum::CenterIncidenceAngle
@ CenterIncidenceAngle
otb::MDGeom::Spot5Geometry
@ Spot5Geometry
otb::MetaDataKey::LowerRightCornerKey
OTBMetadata_EXPORT char const * LowerRightCornerKey
otb::MetaData::MDStrBmType
boost::bimap< MDStr, std::string > MDStrBmType
Definition: otbMetaDataKey.h:312
otb::MDNum::SatElevation
@ SatElevation
otb::MetaData::LUT::FromString
void OTBMetadata_EXPORT FromString(std::string)
otb::MetaDataKey::ResolutionFactor
OTBMetadata_EXPORT char const * ResolutionFactor
otb::MDStr::BeamSwath
@ BeamSwath
otb::MDNum::RadarFrequency
@ RadarFrequency
otb::MetaDataKey::KeyTypeDef::KeyTypeDef
KeyTypeDef()
Definition: otbMetaDataKey.h:107
otb::MDStr
MDStr
Definition: otbMetaDataKey.h:168
otb::MDStr::ProductType
@ ProductType
otb::MetaData::LUT::ToString
std::string OTBMetadata_EXPORT ToString() const
otb::MDNum
MDNum
Definition: otbMetaDataKey.h:125
otb::MetaDataKey::KeyType
KeyType
Definition: otbMetaDataKey.h:85
otb::MDNum::NoData
@ NoData
otb::MDNum::LineSpacing
@ LineSpacing
otb::MetaDataKey::BoolVectorType
std::vector< bool > BoolVectorType
Definition: otbMetaDataKey.h:120
otb::MDStr::RadiometricLevel
@ RadiometricLevel
otb::MetaData::bimapGenerator
boost::bimap< T, std::string > bimapGenerator(std::map< T, std::string > inMap)
Definition: otbMetaDataKey.h:297
otb::MDTime::AcquisitionDate
@ AcquisitionDate
otb::MDStr::LayerType
@ LayerType
otb::MDGeom::ProjectionProj
@ ProjectionProj
otb::MetaDataKey::MetadataKey
OTBMetadata_EXPORT char const * MetadataKey
otb::MetaData::EnumToString
std::string EnumToString(T t)
otb::MDTime::AcquisitionStartTime
@ AcquisitionStartTime
otb::MetaData::MDL2DBmType
boost::bimap< MDL2D, std::string > MDL2DBmType
Definition: otbMetaDataKey.h:321
otb::MetaData::LUT::Array
std::vector< double > Array
Definition: otbMetaDataKey.h:267
otb::MDTime::AcquisitionStopTime
@ AcquisitionStopTime
otbJoinContainer.h
otb::MetaDataKey::SubMetadataKey
OTBMetadata_EXPORT char const * SubMetadataKey
otb::MetaDataKey::DriverLongNameKey
OTBMetadata_EXPORT char const * DriverLongNameKey
otb::MDL2D
MDL2D
Definition: otbMetaDataKey.h:200
otb::MDStr::GeometricLevel
@ GeometricLevel
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::MDTime
MDTime
Definition: otbMetaDataKey.h:207
otb::MetaData::MDTimeNames
OTBMetadata_EXPORT MDTimeBmType MDTimeNames
otb::MDGeom::END
@ END
otb::MDNum::RescalingFactor
@ RescalingFactor
otb::MDStr::SensorID
@ SensorID
otb::MetaDataKey::VectorType
std::vector< double > VectorType
Definition: otbMetaDataKey.h:119
otb::MDStr::MetadataType
@ MetadataType
otb::MDGeom::RPC
@ RPC
otb::MDNum::PhysicalBias
@ PhysicalBias
otb::MDNum::BlueDisplayChannel
@ BlueDisplayChannel
otb::MDNum::RedDisplayChannel
@ RedDisplayChannel
otb::MDStr::Polarization
@ Polarization
otb::MDNum::CalScale
@ CalScale
otb::MetaDataKey::VariableLengthVectorType
itk::VariableLengthVector< double > VariableLengthVectorType
Definition: otbMetaDataKey.h:121
otb::MetaDataKey::KeyTypeDef::type
KeyType type
Definition: otbMetaDataKey.h:105
otb::MetaDataKey::LowerLeftCornerKey
OTBMetadata_EXPORT char const * LowerLeftCornerKey
otb::MDL1D
MDL1D
Definition: otbMetaDataKey.h:193
otb::MetaDataKey::TGCP
@ TGCP
Definition: otbMetaDataKey.h:90
otb::MetaData::MDGeomBmType
boost::bimap< MDGeom, std::string > MDGeomBmType
Definition: otbMetaDataKey.h:306
otb::MDNum::GreenDisplayChannel
@ GreenDisplayChannel
otb::MetaData::LUT::operator==
friend bool operator==(const LUT< VDim > &lhs, const LUT< VDim > &rhs)
Definition: otbMetaDataKey.h:275
otb::MDNum::SpectralStep
@ SpectralStep
otb::MetaDataKey::GetKeyType
KeyType OTBMetadata_EXPORT GetKeyType(const std::string &name)
otb::MetaDataKey::VectorDataKeywordlistKey
OTBMetadata_EXPORT char const * VectorDataKeywordlistKey
otb::MDGeom::Adjustment
@ Adjustment
otb::MetaData::LUTAxis::Spacing
double Spacing
Definition: otbMetaDataKey.h:245
otb::MDStr::Instrument
@ Instrument
otb::MetaData::MDNumNames
OTBMetadata_EXPORT MDNumBmType MDNumNames
otb::MetaData::LUT1D
LUT< 1 > LUT1D
Definition: otbMetaDataKey.h:292
otb::MetaData::LUTAxis::Origin
double Origin
Definition: otbMetaDataKey.h:242
otb::MDStr::OtbVersion
@ OtbVersion
otb::MetaData::LUT
Definition: otbMetaDataKey.h:262
otb::MDStr::END
@ END
otb::MetaData::MDGeomNames
OTBMetadata_EXPORT MDGeomBmType MDGeomNames
otb::MetaDataKey::GCPParametersKey
OTBMetadata_EXPORT char const * GCPParametersKey
otb::MDNum::PRF
@ PRF
otb::MDGeom
MDGeom
Definition: otbMetaDataKey.h:216
otb::MDGeom::SensorGeometry
@ SensorGeometry
otb::MDNum::NumberOfColumns
@ NumberOfColumns
otb::MDStr::BeamMode
@ BeamMode
otb::MetaDataKey::NoDataValue
OTBMetadata_EXPORT char const * NoDataValue
otb::MDStr::EnhancedBandName
@ EnhancedBandName
otb::MDNum::SpectralMax
@ SpectralMax
otb::MDStr::InstrumentIndex
@ InstrumentIndex
otb::MDStr::Mode
@ Mode
otb::MDTime::END
@ END
otb::MDNum::TileHintX
@ TileHintX
otb::MDNum::SpectralMin
@ SpectralMin
otb::MetaDataKey::SubDatasetIndex
OTBMetadata_EXPORT char const * SubDatasetIndex
otb::MDNum::SunAzimuth
@ SunAzimuth
otb::MetaDataKey::TVECTOR
@ TVECTOR
Definition: otbMetaDataKey.h:91
otb::MDNum::PhysicalGain
@ PhysicalGain
otb::MDNum::AbsoluteCalibrationConstant
@ AbsoluteCalibrationConstant
otb::MDNum::SatAzimuth
@ SatAzimuth
otb::MDNum::AverageSceneHeight
@ AverageSceneHeight
otb::MDNum::END
@ END
otb::MetaDataKey::CacheSizeInBytes
OTBMetadata_EXPORT char const * CacheSizeInBytes
otb::MetaData::LUT::ToJSON
std::string OTBMetadata_EXPORT ToJSON(bool multiline=false) const
otb::MetaDataKey::GeoTransformKey
OTBMetadata_EXPORT char const * GeoTransformKey
otb::MDNum::RangeTimeFirstPixel
@ RangeTimeFirstPixel
otb::MDNum::RSF
@ RSF
otbStringUtils.h
otb::MetaData::LUTAxis
Definition: otbMetaDataKey.h:236
otb::MetaDataKey::TileHintX
OTBMetadata_EXPORT char const * TileHintX
otb::MDNum::CalFactor
@ CalFactor
otb::MetaDataKey::UpperRightCornerKey
OTBMetadata_EXPORT char const * UpperRightCornerKey
otb::MetaDataKey::TVECTORDATAKEYWORDLIST
@ TVECTORDATAKEYWORDLIST
Definition: otbMetaDataKey.h:92
otb::MetaDataKey::KeyTypeDef::keyname
std::string keyname
Definition: otbMetaDataKey.h:104
otb::MetaDataKey::TSTRING
@ TSTRING
Definition: otbMetaDataKey.h:87
otb::MetaDataKey::TDOUBLE
@ TDOUBLE
Definition: otbMetaDataKey.h:89
otb::MetaDataKey::ColorTableNameKey
OTBMetadata_EXPORT char const * ColorTableNameKey
otb::MetaData::Keywordlist
std::unordered_map< std::string, std::string > Keywordlist
Definition: otbMetaDataKey.h:234
otb::MetaDataKey::ColorEntryAsRGBKey
OTBMetadata_EXPORT char const * ColorEntryAsRGBKey
otb::MDL2D::END
@ END
otb::MetaData::MDTimeBmType
boost::bimap< MDTime, std::string > MDTimeBmType
Definition: otbMetaDataKey.h:315
otb::MetaDataKey::GCPProjectionKey
OTBMetadata_EXPORT char const * GCPProjectionKey
otb::MetaDataKey::KeyTypeDef::KeyTypeDef
KeyTypeDef(const std::string &_keyname, const KeyType &_type)
Definition: otbMetaDataKey.h:110
otb::MDNum::TileHintY
@ TileHintY
otb::MDGeom::ProjectionEPSG
@ ProjectionEPSG
otb::MetaData::LUTAxis::Size
int Size
Definition: otbMetaDataKey.h:239
otb::MetaData::operator<<
std::ostream & operator<<(std::ostream &os, const LUT< VDim > &val)
Definition: otbMetaDataKey.h:285
otb::MDNum::OrbitNumber
@ OrbitNumber
otb::MDStr::OrbitDirection
@ OrbitDirection
otb::MDStr::BandName
@ BandName
otb::MetaData::LUT::Axis
LUTAxis Axis[VDim]
Definition: otbMetaDataKey.h:265
otb::MetaData::MDL1DBmType
boost::bimap< MDL1D, std::string > MDL1DBmType
Definition: otbMetaDataKey.h:318
otb::MetaData::LUTAxis::ToJSON
std::string ToJSON(bool multiline=false) const
otb::MetaDataKey::DriverShortNameKey
OTBMetadata_EXPORT char const * DriverShortNameKey
otb::MetaDataKey::UpperLeftCornerKey
OTBMetadata_EXPORT char const * UpperLeftCornerKey
otb::MetaDataKey::ProjectionRefKey
OTBMetadata_EXPORT char const * ProjectionRefKey
otb::MetaData::LUTAxis::operator==
friend bool operator==(const LUTAxis &lhs, const LUTAxis &rhs)
Definition: otbMetaDataKey.h:253
MetaDataKey
otb::MetaData::MDL2DNames
OTBMetadata_EXPORT MDL2DBmType MDL2DNames
otb::MDNum::DataType
@ DataType
otb::MDGeom::ProjectionWKT
@ ProjectionWKT
otb::MetaDataKey::ColorEntryCountKey
OTBMetadata_EXPORT char const * ColorEntryCountKey
otb::MDGeom::SAR
@ SAR
otb::MetaDataKey::TileHintY
OTBMetadata_EXPORT char const * TileHintY
otb::MetaDataKey::KeyTypeDef
Definition: otbMetaDataKey.h:102
otb::MetaDataKey::VectorDataKeywordlistDelimiterKey
OTBMetadata_EXPORT char const * VectorDataKeywordlistDelimiterKey
otb::MDL1D::SpectralSensitivity
@ SpectralSensitivity
otb::MDNum::SolarIrradiance
@ SolarIrradiance
otb::MetaDataKey::GCPCountKey
OTBMetadata_EXPORT char const * GCPCountKey
otb::MDStr::Mission
@ Mission
otb::MetaData::MDStrNames
OTBMetadata_EXPORT MDStrBmType MDStrNames
otb::MetaData::MDL1DNames
OTBMetadata_EXPORT MDL1DBmType MDL1DNames
otb::MDNum::NumberOfLines
@ NumberOfLines
otb::MDTime::ProductionDate
@ ProductionDate
otb::MetaData::LUTAxis::Values
std::vector< double > Values
Definition: otbMetaDataKey.h:248
otb::MetaDataKey::TBOOLVECTOR
@ TBOOLVECTOR
Definition: otbMetaDataKey.h:93
otb::MDL1D::END
@ END
otb::MDNum::SunElevation
@ SunElevation