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
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
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
@ 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