OTB  10.0.0
Orfeo Toolbox
otbGDALImageIO.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2018-2020 CS Systemes d'Information (CS SI)
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 #ifndef otbGDALImageIO_h
23 #define otbGDALImageIO_h
24 
25 
26 /* C++ Libraries */
27 #include <string>
28 
29 /* ITK Libraries */
30 #include "otbImageIOBase.h"
33 
34 #include "OTBIOGDALExport.h"
35 #include "otbSpatialReference.h"
36 
37 class GDALDataset;
38 
39 namespace otb
40 {
41 class GDALDatasetWrapper;
42 class GDALDataTypeWrapper;
43 
77 class OTBIOGDAL_EXPORT GDALImageIO
78  : public otb::ImageIOBase
81 {
82 public:
83  typedef unsigned char InputPixelType;
84 
86  typedef GDALImageIO Self;
88  typedef itk::SmartPointer<Self> Pointer;
89 
90  typedef std::vector<std::string> GDALCreationOptionsType;
91 
92  typedef std::vector<std::pair<int, double>> NoDataListType;
93 
95  itkNewMacro(Self);
96 
98  itkTypeMacro(GDALImageIO, otb::ImageIOBase);
99 
102  itkSetMacro(CompressionLevel, int);
103  itkGetMacro(CompressionLevel, int);
105 
107  itkSetMacro(IsComplex, bool);
108  itkGetMacro(IsComplex, bool);
110 
112  itkSetMacro(IsVectorImage, bool);
113  itkGetMacro(IsVectorImage, bool);
115 
117  itkSetMacro(WriteRPCTags, bool);
118  itkGetMacro(WriteRPCTags, bool);
120 
121 
124  {
125  m_CreationOptions = opts;
126  }
127 
129  {
130  return m_CreationOptions;
131  }
132 
134  void SetNoDataList(const NoDataListType& noDataList)
135  {
136  m_NoDataList = noDataList;
137  }
138 
141  void SetOutputImagePixelType(bool isComplexInternalPixelType, bool isVectorImage) override
142  {
143  this->SetIsComplex(isComplexInternalPixelType);
144  this->SetIsVectorImage(isVectorImage);
145  }
147 
148  /*-------- This part of the interface deals with reading data. ------ */
149 
152  bool CanReadFile(const char*) override;
153 
155  bool CanStreamRead() override
156  {
157  return true;
158  }
159 
161  void ReadImageInformation() override;
162 
164  void Read(void* buffer) override;
165 
167  virtual void ReadVolume(void* buffer);
168 
170  bool GetSubDatasetInfo(std::vector<std::string>& names, std::vector<std::string>& desc);
171 
174 
175  /*-------- This part of the interfaces deals with writing data. ----- */
176 
179  bool CanWriteFile(const char*) override;
180 
182  bool CanStreamWrite() override;
183 
186  void WriteImageInformation() override;
187 
190  void Write(const void* buffer) override;
191 
193  bool GetAvailableResolutions(std::vector<unsigned int>& res);
194 
196  bool GetResolutionInfo(std::vector<unsigned int>& res, std::vector<std::string>& desc);
197 
203  unsigned int GetOverviewsCount() override;
204 
206  std::vector<std::string> GetOverviewsInfo() override;
207 
209  std::string GetGdalPixelTypeAsString() const;
210 
211  int GetNbBands() const override;
212 
213  // MetadataSupplierInterface overrides
214 
216  std::string GetResourceFile(std::string const& s="") const override;
217  std::vector<std::string> GetResourceFiles() const override;
219 
221  std::string GetMetadataValue(std::string const& path, bool& hasValue, int band = -1) const override;
222 
225  void SetMetadataValue(const char * path, const char * value, int band=-1) override;
226 
228  void SetEpsgCode(const unsigned int wellKnownCRS);
229 
231  unsigned int GetNumberOf(std::string const&) const override
232  {
233  itkExceptionMacro(
234  "GetNumberOf() not yet implemented in otbGDALImageIO");
235  }
236 
238  unsigned int GetAttributeId(std::string const&, std::string const&) const override
239  {
240  itkExceptionMacro(
241  "GetAttributeId() not yet implemented in otbGDALImageIO");
242  }
243 
244 protected:
251 
253  ~GDALImageIO() override;
254 
257 
260 
263 
265  void GDALMetadataWriteRPC(GDALDataset*);
266 
267  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
270 
272  void InternalWriteImageInformation(const void* buffer);
273 
276 
278  // float **pafimas;
279 
283 
285 
287  unsigned int m_DatasetNumber;
288 
289 private:
290  GDALImageIO(const Self&) = delete;
291  void operator=(const Self&) = delete;
292 
294  std::string GetGdalWriteImageFileName(const std::string& gdalDriverShortName, const std::string& filename) const;
295 
296  std::string FilenameToGdalDriverShortName(const std::string& name) const;
297 
299  bool GetOriginFromGMLBox(std::vector<double>& origin);
300 
304  bool CreationOptionContains(std::string partialOption) const;
305 
308 
311 
313  typedef itk::SmartPointer<GDALDatasetWrapper> GDALDatasetWrapperPointer;
315  unsigned int m_epsgCode;
316 
317  GDALDataTypeWrapper* m_PxType;
320 
321  bool GDALInfoReportCorner(const char* corner_name, double x, double y, double& dfGeoX, double& dfGeoY) const;
322 
325 
329 
333 
337 
340  unsigned int m_NumberOfOverviews;
341 
344  std::vector<std::pair<unsigned int, unsigned int>> m_OverviewsSize;
345 
348  unsigned int m_ResolutionFactor;
349 
353  std::vector<unsigned int> m_OriginalDimensions;
354 
359 
360 
362 };
363 
364 } // end namespace otb
365 
366 #endif // otbGDALImageIO_h
ImageIO object for reading and writing images with GDAL.
std::vector< std::pair< unsigned int, unsigned int > > m_OverviewsSize
bool CanWriteFile(const char *) override
void InternalWriteImageInformation(const void *buffer)
bool GetAvailableResolutions(std::vector< unsigned int > &res)
GDALCreationOptionsType m_CreationOptions
void WriteImageInformation() override
std::string FilenameToGdalDriverShortName(const std::string &name) const
unsigned char InputPixelType
void ReadImageInformation() override
unsigned int m_epsgCode
bool GetSubDatasetInfo(std::vector< std::string > &names, std::vector< std::string > &desc)
int GetNbBands() const override
unsigned int GetAttributeId(std::string const &, std::string const &) const override
std::vector< std::string > GetOverviewsInfo() override
unsigned int m_ResolutionFactor
bool GetOriginFromGMLBox(std::vector< double > &origin)
NoDataListType m_NoDataList
bool GDALInfoReportCorner(const char *corner_name, double x, double y, double &dfGeoX, double &dfGeoY) const
void Write(const void *buffer) override
void operator=(const Self &)=delete
otb::ImageIOBase Superclass
bool GDALPixelTypeIsComplex()
unsigned int m_DatasetNumber
void InternalReadImageInformation()
bool CanStreamWrite() override
itk::SmartPointer< GDALDatasetWrapper > GDALDatasetWrapperPointer
~GDALImageIO() override
void SetOutputImagePixelType(bool isComplexInternalPixelType, bool isVectorImage) override
bool CreationOptionContains(std::string partialOption) const
std::string GetGdalPixelTypeAsString() const
GDALDatasetWrapperPointer m_Dataset
GDALCreationOptionsType GetOptions(void)
void SetNoDataList(const NoDataListType &noDataList)
std::vector< std::pair< int, double > > NoDataListType
std::string GetMetadataValue(std::string const &path, bool &hasValue, int band=-1) const override
bool CanStreamRead() override
void GDALMetadataToKeywordlist(const char *const *, ImageMetadataBase::Keywordlist &)
unsigned int m_NumberOfOverviews
GDALImageIO Self
std::vector< unsigned int > m_OriginalDimensions
GDALDataTypeWrapper * m_PxType
unsigned int GetOverviewsCount() override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void SetOptions(const GDALCreationOptionsType &opts)
std::vector< std::string > GDALCreationOptionsType
std::string GetGdalWriteImageFileName(const std::string &gdalDriverShortName, const std::string &filename) const
unsigned int GetNumberOf(std::string const &) const override
bool m_FlagWriteImageInformation
itk::SmartPointer< Self > Pointer
bool GetResolutionInfo(std::vector< unsigned int > &res, std::vector< std::string > &desc)
void SetEpsgCode(const unsigned int wellKnownCRS)
void KeywordlistToMetadata(ImageMetadataBase::Keywordlist, int band=-1)
virtual void ReadVolume(void *buffer)
void SetMetadataValue(const char *path, const char *value, int band=-1) override
std::vector< std::string > GetResourceFiles() const override
void GDALMetadataReadRPC()
GDALImageIO(const Self &)=delete
void Read(void *buffer) override
void GDALMetadataWriteRPC(GDALDataset *)
std::string GetResourceFile(std::string const &s="") const override
bool CanReadFile(const char *) override
Abstract superclass defines image IO interface.
std::unordered_map< std::string, std::string > Keywordlist
Base class to store metadata information in files/images.
Base class to access metadata information in files/images.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.