OTB  8.1.1
Orfeo Toolbox
otbImageMetadata.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 otbImageMetadata_h
22 #define otbImageMetadata_h
23 
24 #include "otbGeometryMetadata.h"
25 #include "otbSARMetadata.h"
26 #include "otbMetaDataKey.h"
27 #include "OTBMetadataExport.h"
28 #include "otbMacro.h"
29 
30 #include <boost/any.hpp>
31 #include <vector>
32 #include <string>
33 #include <map>
34 #include <unordered_map>
35 
36 namespace otb
37 {
38 
49 class OTBMetadata_EXPORT ImageMetadataBase
50 {
51 public:
53  template <class TKey, class TVal>
54  using DictType = std::map<TKey, TVal>;
55 
56  using Keywordlist = std::unordered_map<std::string, std::string>;
57 
80 
82 
84 
86 
88 
90 
92 
93  // Constructor
96  DictType<MDNum, double> numericKeys,
102 
103  // -------------------- Geom utility function ----------------------------
104 
106  const boost::any & operator[](const MDGeom& key) const;
107 
108  const Projection::GCPParam & GetGCPParam() const;
109  const Projection::RPCParam & GetRPCParam() const;
110  const SARParam & GetSARParam() const;
111 
112  std::string GetProjectedGeometry() const;
113 
114  std::string GetProjectionWKT() const;
115 
116  std::string GetProjectionProj() const;
117 
119  void Add(const MDGeom& key, const boost::any &value);
120 
122  size_t Remove(const MDGeom& key);
123 
124  size_t RemoveSensorGeometry();
125 
126  size_t RemoveProjectedGeometry();
127 
129  bool Has(const MDGeom& key) const;
130 
131  bool HasSensorGeometry() const;
132 
133  bool HasProjectedGeometry() const;
134 
135  // -------------------- Double utility function ----------------------------
136 
138  const double & operator[](const MDNum& key) const;
139 
141  void Add(const MDNum& key, const double &value);
142 
144  size_t Remove(const MDNum& key);
145 
147  bool Has(const MDNum& key) const;
148 
150  std::string GetKeyListNum() const;
151 
152  // -------------------- String utility function ----------------------------
153 
155  const std::string & operator[](const MDStr& key) const;
156 
158  void Add(const MDStr& key, const std::string &value);
159 
161  size_t Remove(const MDStr& key);
162 
164  bool Has(const MDStr& key) const;
165 
167  std::string GetKeyListStr() const;
168 
169  // -------------------- LUT1D utility function ----------------------------
170 
172  const MetaData::LUT1D & operator[](const MDL1D& key) const;
173 
175  void Add(const MDL1D& key, const MetaData::LUT1D &value);
176 
178  size_t Remove(const MDL1D& key);
179 
181  bool Has(const MDL1D& key) const;
182 
184  std::string GetKeyListL1D() const;
185 
186  // -------------------- 2D LUT utility function ----------------------------
187 
189  const MetaData::LUT2D & operator[](const MDL2D& key) const;
190 
192  void Add(const MDL2D& key, const MetaData::LUT2D &value);
193 
195  size_t Remove(const MDL2D& key);
196 
198  bool Has(const MDL2D& key) const;
199 
201 // std::string GetKeyListL2D() const;
202 
203  // -------------------- Time utility function ----------------------------
204 
206  const MetaData::TimePoint & operator[](const MDTime& key) const;
207 
209  void Add(const MDTime& key, const MetaData::TimePoint &value);
210 
212  size_t Remove(const MDTime& key);
213 
215  bool Has(const MDTime& key) const;
216 
218  std::string GetKeyListTime() const;
219 
220  // -------------------- Extra keys utility function --------------------------
221 
223  const std::string & operator[](const std::string & key) const;
224 
226  void Add(const std::string& key, const std::string &value);
227 
229  size_t Remove(const std::string& key);
230 
232  bool Has(const std::string& key) const;
233 
234  // -------------------- Other --------------------------
235 
237  void ToKeywordlist(Keywordlist&) const;
238 
240  std::string ToJSON(bool multiline=false) const;
241 
246  bool FromKeywordlist(const Keywordlist&);
247 
250  void Fuse(const ImageMetadataBase& );
251 
256  std::vector<unsigned int> GetDefaultDisplay() const;
257 
259  int GetSize() const;
260 
261 };
262 
263 
270 class OTBMetadata_EXPORT ImageMetadata: public ImageMetadataBase
271 {
272 public:
274  using KeywordlistVector = std::vector<ImageMetadata::Keywordlist>;
275 
277  using ImageMetadataBandsType = std::vector<ImageMetadataBase>;
279 
280  // Constructor
281  ImageMetadata() = default;
283  DictType<MDNum, double> numericKeys,
284  DictType<MDStr, std::string> stringKeys,
290 
291  // utility functions
293  ImageMetadata slice(int start, int end) const;
294 
297  void append(const ImageMetadata& );
298 
300  void compact();
301 
305  void Merge(const ImageMetadata& );
306 
311  void AppendToKeywordlists(KeywordlistVector&) const;
312 
316  void AppendToBandKeywordlists(KeywordlistVector&) const;
317 
324  bool FromKeywordlists(const KeywordlistVector&);
325 
328  void Add(const MDNum&, const MetaDataKey::VariableLengthVectorType);
329 
331  itk::VariableLengthVector<double> GetAsVector(const MDNum & key) const;
332 
334  bool HasBandMetadata(const MDNum & key) const;
335 
337  bool HasBandMetadata(const MDL1D & key) const;
338 
341  std::vector<std::string> GetBandNames() const;
342 
345  std::vector<std::string> GetEnhancedBandNames() const;
346 
348  int GetSize() const;
349 };
350 
351 extern OTBMetadata_EXPORT std::ostream& operator<<(std::ostream& os, const otb::ImageMetadataBase& imd);
352 
353 extern OTBMetadata_EXPORT std::ostream& operator<<(std::ostream& os, const otb::ImageMetadata& imd);
354 
355 OTBMetadata_EXPORT bool HasOpticalSensorMetadata(const ImageMetadata & imd);
356 OTBMetadata_EXPORT bool HasSARSensorMetadata(const ImageMetadata & imd);
357 
358 OTBMetadata_EXPORT void WriteImageMetadataToGeomFile(const ImageMetadata & imd, const std::string & filename);
359 
361 bool HasSameRPCModel(const ImageMetadataBase& a, const ImageMetadataBase& b);
362 bool HasSameSARModel(const ImageMetadataBase& a, const ImageMetadataBase& b);
365 
366 } // end namespace otb
367 
368 #endif
OTBCommon_EXPORT std::ostream & operator<<(std::ostream &os, const otb::StringToHTML &str)
bool HasSameSARModel(const ImageMetadataBase &a, const ImageMetadataBase &b)
OTBMetadata_EXPORT void WriteImageMetadataToGeomFile(const ImageMetadata &imd, const std::string &filename)
OTBMetadata_EXPORT bool HasSARSensorMetadata(const ImageMetadata &imd)
std::vector< ImageMetadata::Keywordlist > KeywordlistVector
std::vector< ImageMetadataBase > ImageMetadataBandsType
itk::VariableLengthVector< double > VariableLengthVectorType
DictType< std::string, std::string > ExtraKeys
Generic class containing image metadata used in OTB.
std::map< TKey, TVal > DictType
DictType< MDTime, MetaData::TimePoint > TimeKeys
void Add(const MDGeom &key, const boost::any &value)
std::unordered_map< std::string, std::string > Keywordlist
SAR sensors parameters.
ImageMetadataBandsType Bands
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
static constexpr GLenum value() noexcept
Metadata hybrid dictionary.
Coefficients for RPC model (quite similar to GDALRPCInfo)
This structure handles the list of the GCP parameters.
DictType< MDNum, double > NumericKeys
bool HasSameSensorModel(const ImageMetadataBase &a, const ImageMetadataBase &b)
DictType< MDL1D, MetaData::LUT1D > LUT1DKeys
DictType< MDStr, std::string > StringKeys
Represents a point in Time.
Definition: otbDateTime.h:94
OTBMetadata_EXPORT bool HasOpticalSensorMetadata(const ImageMetadata &imd)
bool HasSameRPCModel(const ImageMetadataBase &a, const ImageMetadataBase &b)
DictType< MDGeom, boost::any > GeometryKeys
DictType< MDL2D, MetaData::LUT2D > LUT2DKeys