OTB  10.0.0
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
141 // optical section
142  PhysicalGain,
143  PhysicalBias,
145  SunElevation,
146  SunAzimuth,
147  SatElevation,
148  SatAzimuth,
149  SpectralStep,
150  SpectralMin,
151  SpectralMax,
152 // SAR section
153  CalScale,
154  CalFactor,
155  PRF,
156  RSF,
160  LineSpacing,
161  PixelSpacing,
165  END
166 };
167 
169 enum class MDStr
170 {
171  SensorID,
172  Mission,
173  Instrument,
175  BandName,
177  ProductType,
180  Polarization,
181  Mode,
182  Swath,
184  BeamMode,
185  BeamSwath,
186  AreaOrPoint,
187  LayerType,
188  MetadataType,
189  OtbVersion,
190  END
191 };
192 
194 enum class MDL1D
195 {
197  END
198 };
199 
201 enum class MDL2D
202 {
203  // Sar calibration lut ...
204  END
205 };
206 
208 enum class MDTime
209 {
214  END
215 };
216 
217 enum class MDGeom
218 {
219  ProjectionWKT, // -> string
220  ProjectionEPSG, // -> int
221  ProjectionProj, // -> string
222  RPC, // -> RPCParam
223  SAR, // -> SARParam
224  SARCalib, // -> SARCalib
225  SensorGeometry, // -> boost::any
226  GCP, // -> GCPParam
227  Adjustment, // -> ?
228  Spot5Geometry, //Spot5Param
229  END
230 };
231 
232 namespace MetaData
233 {
234 
235 using Keywordlist = std::unordered_map<std::string, std::string>;
236 
237 struct LUTAxis
238 {
240  int Size;
241 
243  double Origin;
244 
246  double Spacing;
247 
249  std::vector<double> Values;
250 
252  std::string ToJSON(bool multiline=false) const;
253 
254  friend bool operator==(const LUTAxis & lhs, const LUTAxis & rhs)
255  {
256  return lhs.Size == rhs.Size
257  && lhs.Origin == rhs.Origin
258  && lhs.Spacing == rhs.Spacing
259  && lhs.Values == rhs.Values;
260  }
261 };
262 
263 template <unsigned int VDim> class LUT
264 {
265 public:
266  LUTAxis Axis[VDim];
267 
268  std::vector<double> Array;
269 
270  std::string OTBMetadata_EXPORT ToJSON(bool multiline=false) const;
271 
272  std::string OTBMetadata_EXPORT ToString() const;
273 
274  void OTBMetadata_EXPORT FromString(std::string);
275 
276  friend bool operator==(const LUT<VDim> & lhs, const LUT<VDim> & rhs)
277  {
278  return std::equal(std::begin(lhs.Array), std::end(lhs.Array), std::begin(rhs.Array) )
279  && lhs.Array == rhs.Array;
280  }
281 
282 };
283 
284 
285 template <unsigned int VDim>
286 std::ostream& operator<<(std::ostream& os, const LUT<VDim>& val)
287 {
288  os << val.ToString();
289  return os;
290 }
291 
292 
293 typedef LUT<1> LUT1D;
294 
295 typedef LUT<2> LUT2D;
296 
297 template <typename T>
298 inline boost::bimap<T, std::string> bimapGenerator(std::map<T, std::string> inMap)
299 {
300  boost::bimap<T, std::string> bm;
301  for (const auto& kv : inMap)
302  bm.insert({kv.first, kv.second});
303  //bm.insert(typename boost::bimap<T, std::string>::value_type(kv.first, kv.second));
304  return bm;
305 }
306 
307 typedef boost::bimap<MDGeom, std::string> MDGeomBmType;
308 extern OTBMetadata_EXPORT MDGeomBmType MDGeomNames;
309 
310 typedef boost::bimap<MDNum, std::string> MDNumBmType;
311 extern OTBMetadata_EXPORT MDNumBmType MDNumNames;
312 
313 typedef boost::bimap<MDStr, std::string> MDStrBmType;
314 extern OTBMetadata_EXPORT MDStrBmType MDStrNames;
315 
316 typedef boost::bimap<MDTime, std::string> MDTimeBmType;
317 extern OTBMetadata_EXPORT MDTimeBmType MDTimeNames;
318 
319 typedef boost::bimap<MDL1D, std::string> MDL1DBmType;
320 extern OTBMetadata_EXPORT MDL1DBmType MDL1DNames;
321 
322 typedef boost::bimap<MDL2D, std::string> MDL2DBmType;
323 extern OTBMetadata_EXPORT MDL2DBmType MDL2DNames;
324 
325 template<class T>
326 std::string EnumToString(T t);
327 
328 template<>
329 std::string EnumToString(MDGeom value);
330 
331 template<>
332 std::string EnumToString(MDNum value);
333 
334 template<>
335 std::string EnumToString(MDStr value);
336 
337 template<>
338 std::string EnumToString(MDL1D value);
339 
340 template<>
341 std::string EnumToString(MDL2D value);
342 
343 template<>
344 std::string EnumToString(MDTime value);
345 
346 // Specialization for extra keys
347 template<>
348 std::string EnumToString(std::string value);
349 
350 
351 } // end namespace MetaData
352 
353 } // end namespace otb
354 
355 #endif
friend bool operator==(const LUT< VDim > &lhs, const LUT< VDim > &rhs)
void OTBMetadata_EXPORT FromString(std::string)
LUTAxis Axis[VDim]
std::vector< double > Array
std::string OTBMetadata_EXPORT ToString() const
std::string OTBMetadata_EXPORT ToJSON(bool multiline=false) const
OTBMetadata_EXPORT char const * UpperLeftCornerKey
std::vector< bool > BoolVectorType
OTBMetadata_EXPORT char const * VectorDataKeywordlistKey
OTBMetadata_EXPORT char const * SubMetadataKey
OTBMetadata_EXPORT char const * DriverShortNameKey
OTBMetadata_EXPORT char const * SubDatasetIndex
OTBMetadata_EXPORT char const * MetadataKey
OTBMetadata_EXPORT char const * ColorEntryAsRGBKey
OTBMetadata_EXPORT char const * GCPCountKey
OTBMetadata_EXPORT char const * UpperRightCornerKey
OTBMetadata_EXPORT char const * CacheSizeInBytes
OTBMetadata_EXPORT char const * GCPProjectionKey
OTBMetadata_EXPORT char const * TileHintY
OTBMetadata_EXPORT char const * DataType
OTBMetadata_EXPORT char const * LowerLeftCornerKey
OTBMetadata_EXPORT char const * TileHintX
OTBMetadata_EXPORT char const * GCPParametersKey
OTBMetadata_EXPORT char const * ColorTableNameKey
OTBMetadata_EXPORT char const * LowerRightCornerKey
OTBMetadata_EXPORT char const * ResolutionFactor
OTBMetadata_EXPORT char const * GeoTransformKey
std::vector< double > VectorType
KeyType OTBMetadata_EXPORT GetKeyType(const std::string &name)
OTBMetadata_EXPORT char const * VectorDataKeywordlistDelimiterKey
itk::VariableLengthVector< double > VariableLengthVectorType
OTBMetadata_EXPORT char const * NoDataValue
OTBMetadata_EXPORT char const * ProjectionRefKey
OTBMetadata_EXPORT char const * NoDataValueAvailable
OTBMetadata_EXPORT char const * DriverLongNameKey
OTBMetadata_EXPORT char const * ColorEntryCountKey
OTBMetadata_EXPORT MDNumBmType MDNumNames
OTBMetadata_EXPORT MDTimeBmType MDTimeNames
boost::bimap< MDTime, std::string > MDTimeBmType
OTBMetadata_EXPORT MDL1DBmType MDL1DNames
boost::bimap< MDL1D, std::string > MDL1DBmType
boost::bimap< MDNum, std::string > MDNumBmType
OTBMetadata_EXPORT MDL2DBmType MDL2DNames
boost::bimap< MDL2D, std::string > MDL2DBmType
boost::bimap< MDStr, std::string > MDStrBmType
std::unordered_map< std::string, std::string > Keywordlist
boost::bimap< MDGeom, std::string > MDGeomBmType
std::string EnumToString(T t)
OTBMetadata_EXPORT MDStrBmType MDStrNames
boost::bimap< T, std::string > bimapGenerator(std::map< T, std::string > inMap)
OTBMetadata_EXPORT MDGeomBmType MDGeomNames
std::ostream & operator<<(std::ostream &os, const LUT< VDim > &val)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
@ BlueDisplayChannel
@ DeepBlueDisplayChannel
@ CenterIncidenceAngle
@ GreenDisplayChannel
@ AverageSceneHeight
@ AbsoluteCalibrationConstant
@ RangeTimeLastPixel
@ RangeTimeFirstPixel
@ SpectralSensitivity
@ AcquisitionStartTime
KeyTypeDef(const std::string &_keyname, const KeyType &_type)
friend bool operator==(const LUTAxis &lhs, const LUTAxis &rhs)
std::string ToJSON(bool multiline=false) const
std::vector< double > Values