OTB  10.0.0
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 
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 
127 
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 
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 
240 
242  std::string ToJSON(bool multiline=false) const;
243 
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 
314 
319 
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 
367 
368 } // end namespace otb
369 
370 #endif
Metadata hybrid dictionary.
vcl_size_t Remove(MDTime key)
vcl_size_t RemoveSensorGeometry()
const Projection::GCPParam & GetGCPParam() const
bool Has(MDTime key) const
void Add(MDL2D key, const MetaData::LUT2D &value)
const boost::any & operator[](MDGeom key) const
const MetaData::LUT1D & operator[](MDL1D key) const
void Add(MDNum key, const double &value)
DictType< MDStr, std::string > StringKeys
vcl_size_t Remove(MDNum key)
vcl_size_t RemoveProjectedGeometry()
std::string GetKeyListTime() const
vcl_size_t Remove(MDL1D key)
vcl_size_t Remove(MDGeom key)
std::string GetKeyListStr() const
const double & operator[](MDNum key) const
vcl_size_t Remove(const std::string &key)
const SARParam & GetSARParam() const
ImageMetadataBase(DictType< MDGeom, boost::any > geometryKeys, DictType< MDNum, double > numericKeys, DictType< MDStr, std::string > stringKeys, DictType< MDL1D, MetaData::LUT1D > lut1DKeys, DictType< MDL2D, MetaData::LUT2D > lut2DKeys, DictType< MDTime, MetaData::TimePoint > timeKeys, DictType< std::string, std::string > extraKeys)
bool FromKeywordlist(const Keywordlist &)
std::string GetKeyListL1D() const
void Add(const std::string &key, const std::string &value)
DictType< MDL1D, MetaData::LUT1D > LUT1DKeys
void Add(MDL1D key, const MetaData::LUT1D &value)
const MetaData::LUT2D & operator[](MDL2D key) const
std::string GetProjectionWKT() const
DictType< MDGeom, boost::any > GeometryKeys
bool HasProjectedGeometry() const
bool Has(MDL2D key) const
const std::string & operator[](const std::string &key) const
void Add(MDTime key, const MetaData::TimePoint &value)
void Fuse(const ImageMetadataBase &)
vcl_size_t Remove(MDL2D key)
const std::string & operator[](MDStr key) const
void Add(MDStr key, const std::string &value)
std::string GetKeyListNum() const
const MetaData::TimePoint & operator[](MDTime key) const
void Add(MDGeom key, const boost::any &value)
void ToKeywordlist(Keywordlist &) const
bool Has(MDStr key) const
DictType< MDNum, double > NumericKeys
DictType< MDTime, MetaData::TimePoint > TimeKeys
std::string GetProjectedGeometry() const
std::map< TKey, TVal > DictType
bool Has(MDNum key) const
bool HasSensorGeometry() const
bool Has(MDGeom key) const
std::string ToJSON(bool multiline=false) const
vcl_size_t Remove(MDStr key)
const Projection::RPCParam & GetRPCParam() const
std::vector< unsigned int > GetDefaultDisplay() const
std::string GetProjectionProj() const
DictType< MDL2D, MetaData::LUT2D > LUT2DKeys
std::unordered_map< std::string, std::string > Keywordlist
DictType< std::string, std::string > ExtraKeys
bool Has(MDL1D key) const
const Spot5Param & GetSpot5Param() const
bool Has(const std::string &key) const
Generic class containing image metadata used in OTB.
ImageMetadata()=default
void Merge(const ImageMetadata &)
void Add(MDNum, const MetaDataKey::VariableLengthVectorType)
std::vector< ImageMetadata::Keywordlist > KeywordlistVector
std::vector< std::string > GetEnhancedBandNames() const
std::vector< std::string > GetBandNames() const
ImageMetadata(DictType< MDGeom, boost::any > geometryKeys, DictType< MDNum, double > numericKeys, DictType< MDStr, std::string > stringKeys, DictType< MDL1D, MetaData::LUT1D > lut1DKeys, DictType< MDL2D, MetaData::LUT2D > lut2DKeys, DictType< MDTime, MetaData::TimePoint > timeKeys, DictType< std::string, std::string > extraKeys, ImageMetadataBandsType bands)
std::vector< ImageMetadataBase > ImageMetadataBandsType
void AppendToBandKeywordlists(KeywordlistVector &) const
itk::VariableLengthVector< double > GetAsVector(MDNum key) const
void append(const ImageMetadata &)
void AppendToKeywordlists(KeywordlistVector &) const
int GetSize() const
bool FromKeywordlists(const KeywordlistVector &)
ImageMetadata slice(int start, int end) const
ImageMetadataBandsType Bands
bool HasBandMetadata(MDL1D key) const
bool HasBandMetadata(MDNum key) const
Represents a point in Time.
Definition: otbDateTime.h:98
itk::VariableLengthVector< double > VariableLengthVectorType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
OTBMetadata_EXPORT bool HasSARSensorMetadata(const ImageMetadata &imd)
OTBCommon_EXPORT std::ostream & operator<<(std::ostream &os, const otb::StringToHTML &str)
OTBMetadata_EXPORT void WriteImageMetadataToGeomFile(const ImageMetadata &imd, const std::string &filename)
bool HasSameSARModel(const ImageMetadataBase &a, const ImageMetadataBase &b)
bool HasSameSensorModel(const ImageMetadataBase &a, const ImageMetadataBase &b)
OTBMetadata_EXPORT bool HasOpticalSensorMetadata(const ImageMetadata &imd)
bool HasSameRPCModel(const ImageMetadataBase &a, const ImageMetadataBase &b)
This structure handles the list of the GCP parameters.
Coefficients for RPC model (quite similar to GDALRPCInfo)
SAR sensors parameters.
Spot5 sensors parameters.