OTB  9.0.0
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
94  ImageMetadataBase() = default;
96  DictType<MDNum, double> numericKeys,
102 
103  // -------------------- Geom utility function ----------------------------
104 
106  const boost::any & operator[](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(MDGeom key, const boost::any &value);
120 
122  size_t Remove(MDGeom key);
123 
124  size_t RemoveSensorGeometry();
125 
126  size_t RemoveProjectedGeometry();
127 
129  bool Has(MDGeom key) const;
130 
131  bool HasSensorGeometry() const;
132 
133  bool HasProjectedGeometry() const;
134 
135  // -------------------- Double utility function ----------------------------
136 
138  const double & operator[](MDNum key) const;
139 
141  void Add(MDNum key, const double &value);
142 
144  size_t Remove(MDNum key);
145 
147  bool Has(MDNum key) const;
148 
150  std::string GetKeyListNum() const;
151 
152  // -------------------- String utility function ----------------------------
153 
155  const std::string & operator[](MDStr key) const;
156 
158  void Add(MDStr key, const std::string &value);
159 
161  size_t Remove(MDStr key);
162 
164  bool Has(MDStr key) const;
165 
167  std::string GetKeyListStr() const;
168 
169  // -------------------- LUT1D utility function ----------------------------
170 
172  const MetaData::LUT1D & operator[](MDL1D key) const;
173 
175  void Add(MDL1D key, const MetaData::LUT1D &value);
176 
178  size_t Remove(MDL1D key);
179 
181  bool Has(MDL1D key) const;
182 
184  std::string GetKeyListL1D() const;
185 
186  // -------------------- 2D LUT utility function ----------------------------
187 
189  const MetaData::LUT2D & operator[](MDL2D key) const;
190 
192  void Add(MDL2D key, const MetaData::LUT2D &value);
193 
195  size_t Remove(MDL2D key);
196 
198  bool Has(MDL2D key) const;
199 
201 // std::string GetKeyListL2D() const;
202 
203  // -------------------- Time utility function ----------------------------
204 
206  const MetaData::TimePoint & operator[](MDTime key) const;
207 
209  void Add(MDTime key, const MetaData::TimePoint &value);
210 
212  size_t Remove(MDTime key);
213 
215  bool Has(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 
329 
331  itk::VariableLengthVector<double> GetAsVector(MDNum key) const;
332 
334  bool HasBandMetadata(MDNum key) const;
335 
337  bool HasBandMetadata(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
otb::ImageMetadataBase::NumericKeys
DictType< MDNum, double > NumericKeys
Definition: otbImageMetadata.h:81
otb::ImageMetadataBase::Keywordlist
std::unordered_map< std::string, std::string > Keywordlist
Definition: otbImageMetadata.h:56
otb::bands
Definition: otbParserXPlugins.h:52
otb::MDStr
MDStr
Definition: otbMetaDataKey.h:168
otb::MDNum
MDNum
Definition: otbMetaDataKey.h:125
otb::MDL2D
MDL2D
Definition: otbMetaDataKey.h:200
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::MDTime
MDTime
Definition: otbMetaDataKey.h:207
otb::ImageMetadataBase::DictType
std::map< TKey, TVal > DictType
Definition: otbImageMetadata.h:54
otbMacro.h
otb::MetaDataKey::VariableLengthVectorType
itk::VariableLengthVector< double > VariableLengthVectorType
Definition: otbMetaDataKey.h:121
otb::HasSameSensorModel
bool HasSameSensorModel(const ImageMetadataBase &a, const ImageMetadataBase &b)
otb::MDL1D
MDL1D
Definition: otbMetaDataKey.h:193
otbSARMetadata.h
otbGeometryMetadata.h
otb::ImageMetadataBase::LUT2DKeys
DictType< MDL2D, MetaData::LUT2D > LUT2DKeys
Definition: otbImageMetadata.h:87
otb::MetaData::LUT
Definition: otbMetaDataKey.h:261
otb::SARParam
SAR sensors parameters.
Definition: otbSARMetadata.h:211
otb::ImageMetadataBase::LUT1DKeys
DictType< MDL1D, MetaData::LUT1D > LUT1DKeys
Definition: otbImageMetadata.h:85
otb::MDGeom
MDGeom
Definition: otbMetaDataKey.h:216
otb::ImageMetadataBase::ExtraKeys
DictType< std::string, std::string > ExtraKeys
Definition: otbImageMetadata.h:91
otb::ImageMetadataBase
Metadata hybrid dictionary.
Definition: otbImageMetadata.h:49
otb::ImageMetadataBase::Add
void Add(MDGeom key, const boost::any &value)
otbMetaDataKey.h
otb::ImageMetadataBase::TimeKeys
DictType< MDTime, MetaData::TimePoint > TimeKeys
Definition: otbImageMetadata.h:89
otb::HasSameRPCModel
bool HasSameRPCModel(const ImageMetadataBase &a, const ImageMetadataBase &b)
otb::HasSARSensorMetadata
OTBMetadata_EXPORT bool HasSARSensorMetadata(const ImageMetadata &imd)
otb::ImageMetadataBase::StringKeys
DictType< MDStr, std::string > StringKeys
Definition: otbImageMetadata.h:83
otb::operator<<
OTBCommon_EXPORT std::ostream & operator<<(std::ostream &os, const otb::StringToHTML &str)
otb::Projection::RPCParam
Coefficients for RPC model (quite similar to GDALRPCInfo)
Definition: otbGeometryMetadata.h:130
otb::ImageMetadata
Generic class containing image metadata used in OTB.
Definition: otbImageMetadata.h:270
otb::MetaData::TimePoint
Represents a point in Time.
Definition: otbDateTime.h:94
otb::ImageMetadata::Bands
ImageMetadataBandsType Bands
Definition: otbImageMetadata.h:278
otb::HasOpticalSensorMetadata
OTBMetadata_EXPORT bool HasOpticalSensorMetadata(const ImageMetadata &imd)
otb::Projection::GCPParam
This structure handles the list of the GCP parameters.
Definition: otbGeometryMetadata.h:88
otb::ImageMetadataBase::GeometryKeys
DictType< MDGeom, boost::any > GeometryKeys
Definition: otbImageMetadata.h:79
otb::WriteImageMetadataToGeomFile
OTBMetadata_EXPORT void WriteImageMetadataToGeomFile(const ImageMetadata &imd, const std::string &filename)
otb::ImageMetadata::KeywordlistVector
std::vector< ImageMetadata::Keywordlist > KeywordlistVector
Definition: otbImageMetadata.h:274
otb::HasSameSARModel
bool HasSameSARModel(const ImageMetadataBase &a, const ImageMetadataBase &b)
otb::ImageMetadata::ImageMetadataBandsType
std::vector< ImageMetadataBase > ImageMetadataBandsType
Definition: otbImageMetadata.h:277