OTB  6.7.0
Orfeo Toolbox
otbGDALImageIO.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2018 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"
31 
32 #include "OTBIOGDALExport.h"
33 
34 namespace otb
35 {
36 class GDALDatasetWrapper;
37 class GDALDataTypeWrapper;
38 
72 class OTBIOGDAL_EXPORT GDALImageIO : public otb::ImageIOBase
73 {
74 public:
75 
76  typedef unsigned char InputPixelType;
77 
79  typedef GDALImageIO Self;
82 
83  typedef std::vector<std::string> GDALCreationOptionsType;
84 
85  typedef std::vector<
86  std::pair<int, double>
88 
90  itkNewMacro(Self);
91 
93  itkTypeMacro(GDALImageIO, otb::ImageIOBase);
94 
97  itkSetMacro(CompressionLevel, int);
98  itkGetMacro(CompressionLevel, int);
100 
102  itkSetMacro(IsComplex, bool);
103  itkGetMacro(IsComplex, bool);
105 
107  itkSetMacro(IsVectorImage, bool);
108  itkGetMacro(IsVectorImage, bool);
110 
112  itkSetMacro(WriteRPCTags,bool);
113  itkGetMacro(WriteRPCTags,bool);
115 
116 
119  {
120  m_CreationOptions = opts;
121  }
122 
124  {
125  return m_CreationOptions;
126  }
127 
129  void SetNoDataList(const NoDataListType& noDataList)
130  {
131  m_NoDataList = noDataList;
132  }
133 
136  void SetOutputImagePixelType( bool isComplexInternalPixelType,
137  bool isVectorImage) override
138  {
139  this->SetIsComplex(isComplexInternalPixelType);
140  this->SetIsVectorImage(isVectorImage);
141  }
143 
144  /*-------- This part of the interface deals with reading data. ------ */
145 
148  bool CanReadFile(const char*) override;
149 
151  bool CanStreamRead() override
152  {
153  return true;
154  }
155 
157  void ReadImageInformation() override;
158 
160  void Read(void* buffer) override;
161 
163  virtual void ReadVolume(void* buffer);
164 
166  bool GetSubDatasetInfo(std::vector<std::string>& names, std::vector<std::string>& desc);
167 
169  bool GDALPixelTypeIsComplex();
170 
171  /*-------- This part of the interfaces deals with writing data. ----- */
172 
175  bool CanWriteFile(const char*) override;
176 
178  bool CanStreamWrite() override;
179 
182  void WriteImageInformation() override;
183 
186  void Write(const void* buffer) override;
187 
189  bool GetAvailableResolutions(std::vector<unsigned int>& res);
190 
192  bool GetResolutionInfo(std::vector<unsigned int>& res, std::vector<std::string>& desc);
193 
199  unsigned int GetOverviewsCount() override;
200 
202  std::vector<std::string> GetOverviewsInfo() override;
203 
205  std::string GetGdalPixelTypeAsString() const;
206 
207  itkGetMacro(NbBands, int);
208 
209 protected:
215  GDALImageIO();
216 
218  ~GDALImageIO() override;
219 
220  void PrintSelf(std::ostream& os, itk::Indent indent) const override;
222  void InternalReadImageInformation();
223 
225  void InternalWriteImageInformation(const void* buffer);
226 
229 
231  //float **pafimas;
232 
236 
238 
240  unsigned int m_DatasetNumber;
241 
242 private:
243  GDALImageIO(const Self &) = delete;
244  void operator =(const Self&) = delete;
245 
247  std::string GetGdalWriteImageFileName(const std::string& gdalDriverShortName, const std::string& filename) const;
248 
249  std::string FilenameToGdalDriverShortName(const std::string& name) const;
250 
252  bool GetOriginFromGMLBox(std::vector<double> &origin);
253 
257  bool CreationOptionContains(std::string partialOption) const;
258 
262 
263  GDALDataTypeWrapper* m_PxType;
266 
267  bool GDALInfoReportCorner(const char * corner_name, double x, double y,
268  double& dfGeoX, double& dfGeoY) const;
269 
272 
276 
280 
284 
287  unsigned int m_NumberOfOverviews;
288 
291  std::vector<std::pair<unsigned int, unsigned int> > m_OverviewsSize;
292 
295  unsigned int m_ResolutionFactor;
296 
300  std::vector<unsigned int> m_OriginalDimensions;
301 
306 
307 
309 
310 };
311 
312 } // end namespace otb
313 
314 #endif // otbGDALImageIO_h
itk::SmartPointer< GDALDatasetWrapper > GDALDatasetWrapperPointer
std::vector< std::string > GDALCreationOptionsType
OTBApplicationEngine_EXPORT int Read(const std::string &filename, Application::Pointer application)
itk::SmartPointer< Self > Pointer
unsigned char InputPixelType
otb::ImageIOBase Superclass
unsigned int m_ResolutionFactor
NoDataListType m_NoDataList
void SetNoDataList(const NoDataListType &noDataList)
Abstract superclass defines image IO interface.
GDALCreationOptionsType GetOptions(void)
void SetOptions(const GDALCreationOptionsType &opts)
bool CanStreamRead() override
GDALDatasetWrapperPointer m_Dataset
GDALImageIO Self
unsigned int m_DatasetNumber
GDALDataTypeWrapper * m_PxType
OTBApplicationEngine_EXPORT void Write(const std::string &filename, Application::Pointer application)
GDALCreationOptionsType m_CreationOptions
std::vector< std::pair< unsigned int, unsigned int > > m_OverviewsSize
void SetOutputImagePixelType(bool isComplexInternalPixelType, bool isVectorImage) override
unsigned int m_NumberOfOverviews
ImageIO object for reading and writing images with GDAL.
std::vector< unsigned int > m_OriginalDimensions
bool m_FlagWriteImageInformation
std::vector< std::pair< int, double > > NoDataListType