OTB  9.0.0
Orfeo Toolbox
otbGDALImageIO.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 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 
173  bool GDALPixelTypeIsComplex();
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 GetAttributId(std::string const&, std::string const&) const override
239  {
240  itkExceptionMacro(
241  "GetAttributId() not yet implemented in otbGDALImageIO");
242  }
243 
244 protected:
250  GDALImageIO();
251 
253  ~GDALImageIO() override;
254 
256  void KeywordlistToMetadata(ImageMetadataBase::Keywordlist, int band=-1);
257 
259  void GDALMetadataToKeywordlist(const char* const* , ImageMetadataBase::Keywordlist &);
260 
262  void GDALMetadataReadRPC();
263 
265  void GDALMetadataWriteRPC(GDALDataset*);
266 
267  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
269  void InternalReadImageInformation();
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 
307  void ExportMetadata();
308 
310  void ImportMetadata();
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
otb::GDALImageIO::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbGDALImageIO.h:88
otbMetadataStorageInterface.h
otb::GDALImageIO::m_epsgCode
unsigned int m_epsgCode
Definition: otbGDALImageIO.h:315
otb::ImageMetadataBase::Keywordlist
std::unordered_map< std::string, std::string > Keywordlist
Definition: otbImageMetadata.h:56
otb::GDALImageIO::NoDataListType
std::vector< std::pair< int, double > > NoDataListType
Definition: otbGDALImageIO.h:92
otb::GDALImageIO::SetOptions
void SetOptions(const GDALCreationOptionsType &opts)
Definition: otbGDALImageIO.h:123
otb::GDALImageIO::Superclass
otb::ImageIOBase Superclass
Definition: otbGDALImageIO.h:87
otb::GDALImageIO::m_DatasetNumber
unsigned int m_DatasetNumber
Definition: otbGDALImageIO.h:287
otb::GDALImageIO::m_ResolutionFactor
unsigned int m_ResolutionFactor
Definition: otbGDALImageIO.h:348
otb::GDALImageIO::m_NoDataList
NoDataListType m_NoDataList
Definition: otbGDALImageIO.h:361
otb::GDALImageIO::m_WriteRPCTags
bool m_WriteRPCTags
Definition: otbGDALImageIO.h:358
otb::Wrapper::XML::Write
OTBApplicationEngine_EXPORT void Write(const std::string &filename, Application::Pointer application)
otb::GDALImageIO::InputPixelType
unsigned char InputPixelType
Definition: otbGDALImageIO.h:83
otb::GDALImageIO::SetNoDataList
void SetNoDataList(const NoDataListType &noDataList)
Definition: otbGDALImageIO.h:134
otb::MetadataStorageInterface
Base class to store metadata information in files/images.
Definition: otbMetadataStorageInterface.h:43
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::GDALImageIO::GDALDatasetWrapperPointer
itk::SmartPointer< GDALDatasetWrapper > GDALDatasetWrapperPointer
Definition: otbGDALImageIO.h:313
otb::GDALImageIO::GetAttributId
unsigned int GetAttributId(std::string const &, std::string const &) const override
Definition: otbGDALImageIO.h:238
otbSpatialReference.h
otbImageIOBase.h
otb::GDALImageIO
ImageIO object for reading and writing images with GDAL.
Definition: otbGDALImageIO.h:77
otb::GDALImageIO::m_PxType
GDALDataTypeWrapper * m_PxType
Definition: otbGDALImageIO.h:317
otb::GDALImageIO::Self
GDALImageIO Self
Definition: otbGDALImageIO.h:86
otb::GDALImageIO::m_IsIndexed
bool m_IsIndexed
Definition: otbGDALImageIO.h:284
otb::MetadataSupplierInterface
Base class to access metadata information in files/images.
Definition: otbMetadataSupplierInterface.h:40
otb::GDALImageIO::m_BytePerPixel
int m_BytePerPixel
Definition: otbGDALImageIO.h:319
otb::GDALImageIO::GDALCreationOptionsType
std::vector< std::string > GDALCreationOptionsType
Definition: otbGDALImageIO.h:90
otb::GDALImageIO::m_CompressionLevel
int m_CompressionLevel
Definition: otbGDALImageIO.h:282
otb::GDALImageIO::m_OriginalDimensions
std::vector< unsigned int > m_OriginalDimensions
Definition: otbGDALImageIO.h:353
otb::GDALImageIO::GetOptions
GDALCreationOptionsType GetOptions(void)
Definition: otbGDALImageIO.h:128
otb::GDALImageIO::m_Dataset
GDALDatasetWrapperPointer m_Dataset
Definition: otbGDALImageIO.h:314
otb::GDALImageIO::GetNumberOf
unsigned int GetNumberOf(std::string const &) const override
Definition: otbGDALImageIO.h:231
otb::GDALImageIO::SetOutputImagePixelType
void SetOutputImagePixelType(bool isComplexInternalPixelType, bool isVectorImage) override
Definition: otbGDALImageIO.h:141
otb::GDALImageIO::m_NbBands
int m_NbBands
Definition: otbGDALImageIO.h:275
otb::GDALImageIO::m_FlagWriteImageInformation
bool m_FlagWriteImageInformation
Definition: otbGDALImageIO.h:323
otb::GDALImageIO::m_CreationOptions
GDALCreationOptionsType m_CreationOptions
Definition: otbGDALImageIO.h:336
otbMetadataSupplierInterface.h
otb::Wrapper::XML::Read
OTBApplicationEngine_EXPORT int Read(const std::string &filename, Application::Pointer application)
otb::GDALImageIO::m_NumberOfOverviews
unsigned int m_NumberOfOverviews
Definition: otbGDALImageIO.h:340
otb::ImageIOBase
Abstract superclass defines image IO interface.
Definition: otbImageIOBase.h:69
otb::GDALImageIO::m_IsVectorImage
bool m_IsVectorImage
Definition: otbGDALImageIO.h:332
otb::GDALImageIO::m_CanStreamWrite
bool m_CanStreamWrite
Definition: otbGDALImageIO.h:324
otb::GDALImageIO::m_OverviewsSize
std::vector< std::pair< unsigned int, unsigned int > > m_OverviewsSize
Definition: otbGDALImageIO.h:344
otb::GDALImageIO::m_IsComplex
bool m_IsComplex
Definition: otbGDALImageIO.h:328
otb::GDALImageIO::CanStreamRead
bool CanStreamRead() override
Definition: otbGDALImageIO.h:155