OTB  9.0.0
Orfeo Toolbox
otbMetaDataKey.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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  END
228 };
229 
230 namespace MetaData
231 {
232 
233 using Keywordlist = std::unordered_map<std::string, std::string>;
234 
235 struct LUTAxis
236 {
238  int Size;
239 
241  double Origin;
242 
244  double Spacing;
245 
247  std::vector<double> Values;
248 
250  std::string ToJSON(bool multiline=false) const;
251 
252  friend bool operator==(const LUTAxis & lhs, const LUTAxis & rhs)
253  {
254  return lhs.Size == rhs.Size
255  && lhs.Origin == rhs.Origin
256  && lhs.Spacing == rhs.Spacing
257  && lhs.Values == rhs.Values;
258  }
259 };
260 
261 template <unsigned int VDim> class LUT
262 {
263 public:
264  LUTAxis Axis[VDim];
265 
266  std::vector<double> Array;
267 
268  std::string OTBMetadata_EXPORT ToJSON(bool multiline=false) const;
269 
270  std::string OTBMetadata_EXPORT ToString() const;
271 
272  void OTBMetadata_EXPORT FromString(std::string);
273 
274  friend bool operator==(const LUT<VDim> & lhs, const LUT<VDim> & rhs)
275  {
276  return std::equal(std::begin(lhs.Array), std::end(lhs.Array), std::begin(rhs.Array) )
277  && lhs.Array == rhs.Array;
278  }
279 
280 };
281 
282 
283 template <unsigned int VDim>
284 std::ostream& operator<<(std::ostream& os, const LUT<VDim>& val)
285 {
286  os << val.ToString();
287  return os;
288 }
289 
290 
291 typedef LUT<1> LUT1D;
292 
293 typedef LUT<2> LUT2D;
294 
295 template <typename T>
296 inline boost::bimap<T, std::string> bimapGenerator(std::map<T, std::string> inMap)
297 {
298  boost::bimap<T, std::string> bm;
299  for (const auto& kv : inMap)
300  bm.insert({kv.first, kv.second});
301  //bm.insert(typename boost::bimap<T, std::string>::value_type(kv.first, kv.second));
302  return bm;
303 }
304 
305 typedef boost::bimap<MDGeom, std::string> MDGeomBmType;
306 extern OTBMetadata_EXPORT MDGeomBmType MDGeomNames;
307 
308 typedef boost::bimap<MDNum, std::string> MDNumBmType;
309 extern OTBMetadata_EXPORT MDNumBmType MDNumNames;
310 
311 typedef boost::bimap<MDStr, std::string> MDStrBmType;
312 extern OTBMetadata_EXPORT MDStrBmType MDStrNames;
313 
314 typedef boost::bimap<MDTime, std::string> MDTimeBmType;
315 extern OTBMetadata_EXPORT MDTimeBmType MDTimeNames;
316 
317 typedef boost::bimap<MDL1D, std::string> MDL1DBmType;
318 extern OTBMetadata_EXPORT MDL1DBmType MDL1DNames;
319 
320 typedef boost::bimap<MDL2D, std::string> MDL2DBmType;
321 extern OTBMetadata_EXPORT MDL2DBmType MDL2DNames;
322 
323 template<class T>
324 std::string EnumToString(T t);
325 
326 template<>
327 std::string EnumToString(MDGeom value);
328 
329 template<>
330 std::string EnumToString(MDNum value);
331 
332 template<>
333 std::string EnumToString(MDStr value);
334 
335 template<>
336 std::string EnumToString(MDL1D value);
337 
338 template<>
339 std::string EnumToString(MDL2D value);
340 
341 template<>
342 std::string EnumToString(MDTime value);
343 
344 // Specialization for extra keys
345 template<>
346 std::string EnumToString(std::string value);
347 
348 
349 } // end namespace MetaData
350 
351 } // end namespace otb
352 
353 #endif
otb::MetaDataKey::DataType
OTBMetadata_EXPORT char const * DataType
otb::MetaData::MDNumBmType
boost::bimap< MDNum, std::string > MDNumBmType
Definition: otbMetaDataKey.h:308
otb::MDNum::PixelSpacing
@ PixelSpacing
otb::MDGeom::GCP
@ GCP
otb::MDGeom::SARCalib
@ SARCalib
otb::MetaData::LUT2D
LUT< 2 > LUT2D
Definition: otbMetaDataKey.h:293
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::MetaDataKey::LowerRightCornerKey
OTBMetadata_EXPORT char const * LowerRightCornerKey
otb::MetaData::MDStrBmType
boost::bimap< MDStr, std::string > MDStrBmType
Definition: otbMetaDataKey.h:311
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:296
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:320
otb::MetaData::LUT::Array
std::vector< double > Array
Definition: otbMetaDataKey.h:266
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:305
otb::MDNum::GreenDisplayChannel
@ GreenDisplayChannel
otb::MetaData::LUT::operator==
friend bool operator==(const LUT< VDim > &lhs, const LUT< VDim > &rhs)
Definition: otbMetaDataKey.h:274
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:244
otb::MDStr::Instrument
@ Instrument
otb::MetaData::MDNumNames
OTBMetadata_EXPORT MDNumBmType MDNumNames
otb::MetaData::LUT1D
LUT< 1 > LUT1D
Definition: otbMetaDataKey.h:291
otb::MetaData::LUTAxis::Origin
double Origin
Definition: otbMetaDataKey.h:241
otb::MDStr::OtbVersion
@ OtbVersion
otb::MetaData::LUT
Definition: otbMetaDataKey.h:261
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:235
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:233
otb::MetaDataKey::ColorEntryAsRGBKey
OTBMetadata_EXPORT char const * ColorEntryAsRGBKey
otb::MDL2D::END
@ END
otb::MetaData::MDTimeBmType
boost::bimap< MDTime, std::string > MDTimeBmType
Definition: otbMetaDataKey.h:314
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:238
otb::MetaData::operator<<
std::ostream & operator<<(std::ostream &os, const LUT< VDim > &val)
Definition: otbMetaDataKey.h:284
otb::MDNum::OrbitNumber
@ OrbitNumber
otb::MDStr::OrbitDirection
@ OrbitDirection
otb::MDStr::BandName
@ BandName
otb::MetaData::LUT::Axis
LUTAxis Axis[VDim]
Definition: otbMetaDataKey.h:264
otb::MetaData::MDL1DBmType
boost::bimap< MDL1D, std::string > MDL1DBmType
Definition: otbMetaDataKey.h:317
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:252
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:247
otb::MetaDataKey::TBOOLVECTOR
@ TBOOLVECTOR
Definition: otbMetaDataKey.h:93
otb::MDL1D::END
@ END
otb::MDNum::SunElevation
@ SunElevation