OTB  9.1.1
Orfeo Toolbox
otbImageMetadata.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 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 "otbSpot5Metadata.h"
29 #include "otbMacro.h"
30 
31 #include <boost/any.hpp>
32 #include <vector>
33 #include <string>
34 #include <map>
35 #include <unordered_map>
36 
37 namespace otb
38 {
39 
50 class OTBMetadata_EXPORT ImageMetadataBase
51 {
52 public:
54  template <class TKey, class TVal>
55  using DictType = std::map<TKey, TVal>;
56 
57  using Keywordlist = std::unordered_map<std::string, std::string>;
58 
81 
83 
85 
87 
89 
91 
93 
94  // Constructor
95  ImageMetadataBase() = default;
97  DictType<MDNum, double> numericKeys,
103 
104  // -------------------- Geom utility function ----------------------------
105 
107  const boost::any & operator[](MDGeom key) const;
108 
109  const Projection::GCPParam & GetGCPParam() const;
110  const Projection::RPCParam & GetRPCParam() const;
111  const SARParam & GetSARParam() const;
112  const Spot5Param & GetSpot5Param() const;
113 
114  std::string GetProjectedGeometry() const;
115 
116  std::string GetProjectionWKT() const;
117 
118  std::string GetProjectionProj() const;
119 
121  void Add(MDGeom key, const boost::any &value);
122 
124  size_t Remove(MDGeom key);
125 
126  size_t RemoveSensorGeometry();
127 
128  size_t RemoveProjectedGeometry();
129 
131  bool Has(MDGeom key) const;
132 
133  bool HasSensorGeometry() const;
134 
135  bool HasProjectedGeometry() const;
136 
137  // -------------------- Double utility function ----------------------------
138 
140  const double & operator[](MDNum key) const;
141 
143  void Add(MDNum key, const double &value);
144 
146  size_t Remove(MDNum key);
147 
149  bool Has(MDNum key) const;
150 
152  std::string GetKeyListNum() const;
153 
154  // -------------------- String utility function ----------------------------
155 
157  const std::string & operator[](MDStr key) const;
158 
160  void Add(MDStr key, const std::string &value);
161 
163  size_t Remove(MDStr key);
164 
166  bool Has(MDStr key) const;
167 
169  std::string GetKeyListStr() const;
170 
171  // -------------------- LUT1D utility function ----------------------------
172 
174  const MetaData::LUT1D & operator[](MDL1D key) const;
175 
177  void Add(MDL1D key, const MetaData::LUT1D &value);
178 
180  size_t Remove(MDL1D key);
181 
183  bool Has(MDL1D key) const;
184 
186  std::string GetKeyListL1D() const;
187 
188  // -------------------- 2D LUT utility function ----------------------------
189 
191  const MetaData::LUT2D & operator[](MDL2D key) const;
192 
194  void Add(MDL2D key, const MetaData::LUT2D &value);
195 
197  size_t Remove(MDL2D key);
198 
200  bool Has(MDL2D key) const;
201 
203 // std::string GetKeyListL2D() const;
204 
205  // -------------------- Time utility function ----------------------------
206 
208  const MetaData::TimePoint & operator[](MDTime key) const;
209 
211  void Add(MDTime key, const MetaData::TimePoint &value);
212 
214  size_t Remove(MDTime key);
215 
217  bool Has(MDTime key) const;
218 
220  std::string GetKeyListTime() const;
221 
222  // -------------------- Extra keys utility function --------------------------
223 
225  const std::string & operator[](const std::string & key) const;
226 
228  void Add(const std::string& key, const std::string &value);
229 
231  size_t Remove(const std::string& key);
232 
234  bool Has(const std::string& key) const;
235 
236  // -------------------- Other --------------------------
237 
239  void ToKeywordlist(Keywordlist&) const;
240 
242  std::string ToJSON(bool multiline=false) const;
243 
248  bool FromKeywordlist(const Keywordlist&);
249 
252  void Fuse(const ImageMetadataBase& );
253 
258  std::vector<unsigned int> GetDefaultDisplay() const;
259 
261  int GetSize() const;
262 
263 };
264 
265 
272 class OTBMetadata_EXPORT ImageMetadata: public ImageMetadataBase
273 {
274 public:
276  using KeywordlistVector = std::vector<ImageMetadata::Keywordlist>;
277 
279  using ImageMetadataBandsType = std::vector<ImageMetadataBase>;
281 
282  // Constructor
283  ImageMetadata() = default;
285  DictType<MDNum, double> numericKeys,
286  DictType<MDStr, std::string> stringKeys,
292 
293  // utility functions
295  ImageMetadata slice(int start, int end) const;
296 
299  void append(const ImageMetadata& );
300 
302  void compact();
303 
307  void Merge(const ImageMetadata& );
308 
313  void AppendToKeywordlists(KeywordlistVector&) const;
314 
318  void AppendToBandKeywordlists(KeywordlistVector&) const;
319 
326  bool FromKeywordlists(const KeywordlistVector&);
327 
331 
333  itk::VariableLengthVector<double> GetAsVector(MDNum key) const;
334 
336  bool HasBandMetadata(MDNum key) const;
337 
339  bool HasBandMetadata(MDL1D key) const;
340 
343  std::vector<std::string> GetBandNames() const;
344 
347  std::vector<std::string> GetEnhancedBandNames() const;
348 
350  int GetSize() const;
351 };
352 
353 extern OTBMetadata_EXPORT std::ostream& operator<<(std::ostream& os, const otb::ImageMetadataBase& imd);
354 
355 extern OTBMetadata_EXPORT std::ostream& operator<<(std::ostream& os, const otb::ImageMetadata& imd);
356 
357 OTBMetadata_EXPORT bool HasOpticalSensorMetadata(const ImageMetadata & imd);
358 OTBMetadata_EXPORT bool HasSARSensorMetadata(const ImageMetadata & imd);
359 
360 OTBMetadata_EXPORT void WriteImageMetadataToGeomFile(const ImageMetadata & imd, const std::string & filename);
361 
363 bool HasSameRPCModel(const ImageMetadataBase& a, const ImageMetadataBase& b);
364 bool HasSameSARModel(const ImageMetadataBase& a, const ImageMetadataBase& b);
367 
368 } // end namespace otb
369 
370 #endif
otbSpot5Metadata.h
otb::ImageMetadataBase::NumericKeys
DictType< MDNum, double > NumericKeys
Definition: otbImageMetadata.h:82
otb::ImageMetadataBase::Keywordlist
std::unordered_map< std::string, std::string > Keywordlist
Definition: otbImageMetadata.h:57
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:55
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:88
otb::MetaData::LUT
Definition: otbMetaDataKey.h:262
otb::SARParam
SAR sensors parameters.
Definition: otbSARMetadata.h:211
otb::ImageMetadataBase::LUT1DKeys
DictType< MDL1D, MetaData::LUT1D > LUT1DKeys
Definition: otbImageMetadata.h:86
otb::MDGeom
MDGeom
Definition: otbMetaDataKey.h:216
otb::ImageMetadataBase::ExtraKeys
DictType< std::string, std::string > ExtraKeys
Definition: otbImageMetadata.h:92
otb::ImageMetadataBase
Metadata hybrid dictionary.
Definition: otbImageMetadata.h:50
otb::ImageMetadataBase::Add
void Add(MDGeom key, const boost::any &value)
otbMetaDataKey.h
otb::ImageMetadataBase::TimeKeys
DictType< MDTime, MetaData::TimePoint > TimeKeys
Definition: otbImageMetadata.h:90
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:84
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:272
otb::MetaData::TimePoint
Represents a point in Time.
Definition: otbDateTime.h:94
otb::ImageMetadata::Bands
ImageMetadataBandsType Bands
Definition: otbImageMetadata.h:280
otb::HasOpticalSensorMetadata
OTBMetadata_EXPORT bool HasOpticalSensorMetadata(const ImageMetadata &imd)
otb::Spot5Param
Spot5 sensors parameters.
Definition: otbSpot5Metadata.h:68
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:80
otb::WriteImageMetadataToGeomFile
OTBMetadata_EXPORT void WriteImageMetadataToGeomFile(const ImageMetadata &imd, const std::string &filename)
otb::ImageMetadata::KeywordlistVector
std::vector< ImageMetadata::Keywordlist > KeywordlistVector
Definition: otbImageMetadata.h:276
otb::HasSameSARModel
bool HasSameSARModel(const ImageMetadataBase &a, const ImageMetadataBase &b)
otb::ImageMetadata::ImageMetadataBandsType
std::vector< ImageMetadataBase > ImageMetadataBandsType
Definition: otbImageMetadata.h:279