QGIS API Documentation  2.99.0-Master (9caa722)
qgsrasterfilewriter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterfilewriter.h
3  ---------------------
4  begin : July 2012
5  copyright : (C) 2012 by Marco Hugentobler
6  email : marco dot hugentobler at sourcepole dot ch
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSRASTERFILEWRITER_H
16 #define QGSRASTERFILEWRITER_H
17 
18 #include "qgis_core.h"
20 #include <QDomDocument>
21 #include <QDomElement>
22 #include <QString>
23 #include <QStringList>
24 
25 #include "qgsraster.h"
26 
28 class QgsRasterIterator;
29 class QgsRasterPipe;
30 class QgsRectangle;
32 class QgsRasterInterface;
33 
37 class CORE_EXPORT QgsRasterFileWriter
38 {
39  public:
40  enum Mode
41  {
42  Raw = 0,
43  Image = 1
44  };
46  {
47  NoError = 0,
48  SourceProviderError = 1,
49  DestProviderError = 2,
50  CreateDatasourceError = 3,
51  WriteError = 4,
52  NoDataConflict = 5,
53  WriteCanceled = 6,
54  };
55 
56  QgsRasterFileWriter( const QString &outputUrl );
57 
65  QgsRasterDataProvider *createOneBandRaster( Qgis::DataType dataType,
66  int width, int height,
67  const QgsRectangle &extent,
69 
77  QgsRasterDataProvider *createMultiBandRaster( Qgis::DataType dataType,
78  int width, int height,
79  const QgsRectangle &extent,
81  int nBands ) SIP_FACTORY;
82 
91  WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
92  const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
93 
98  QString outputUrl() const { return mOutputUrl; }
99 
100  void setOutputFormat( const QString &format ) { mOutputFormat = format; }
101  QString outputFormat() const { return mOutputFormat; }
102 
103  void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
104  QString outputProviderKey() const { return mOutputProviderKey; }
105 
106  void setTiledMode( bool t ) { mTiledMode = t; }
107  bool tiledMode() const { return mTiledMode; }
108 
109  void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
110  int maxTileWidth() const { return mMaxTileWidth; }
111 
112  QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
113  void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
114 
115  QList< int > pyramidsList() const { return mPyramidsList; }
116  void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
117 
118  QString pyramidsResampling() const { return mPyramidsResampling; }
119  void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
120 
121  QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
122  void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
123 
124  void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
125  int maxTileHeight() const { return mMaxTileHeight; }
126 
127  void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
128  QStringList createOptions() const { return mCreateOptions; }
129 
130  void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
131  QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
132 
139  static QString driverForExtension( const QString &extension );
140 
141  private:
142  QgsRasterFileWriter(); //forbidden
143  WriterError writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
144  const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
145 
146  // Helper method used by previous one
147  WriterError writeDataRaster( const QgsRasterPipe *pipe,
148  QgsRasterIterator *iter,
149  int nCols, int nRows,
150  const QgsRectangle &outputExtent,
151  const QgsCoordinateReferenceSystem &crs,
152  Qgis::DataType destDataType,
153  const QList<bool> &destHasNoDataValueList,
154  const QList<double> &destNoDataValueList,
155  QgsRasterDataProvider *destProvider,
156  QgsRasterBlockFeedback *feedback = nullptr );
157 
158  WriterError writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
159  const QgsCoordinateReferenceSystem &crs,
160  QgsRasterBlockFeedback *feedback = nullptr );
161 
171  void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
172  //write vrt document to disk
173  bool writeVRT( const QString &file );
174  //add file entry to vrt
175  void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
176  void buildPyramids( const QString &filename );
177 
179  QgsRasterDataProvider *createPartProvider( const QgsRectangle &extent, int nCols, int iterCols, int iterRows,
180  int iterLeft, int iterTop,
181  const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type,
182  const QgsCoordinateReferenceSystem &crs );
183 
194  QgsRasterDataProvider *initOutput( int nCols, int nRows,
195  const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
196  Qgis::DataType type,
197  const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
198 
200  void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
201 
202  QString partFileName( int fileIndex );
203  QString vrtFileName();
204 
205  Mode mMode;
206  QString mOutputUrl;
207  QString mOutputProviderKey;
208  QString mOutputFormat;
209  QStringList mCreateOptions;
210  QgsCoordinateReferenceSystem mOutputCRS;
211 
213  bool mTiledMode;
214  double mMaxTileWidth;
215  double mMaxTileHeight;
216 
217  QList< int > mPyramidsList;
218  QString mPyramidsResampling;
219  QgsRaster::RasterBuildPyramids mBuildPyramidsFlag;
220  QgsRaster::RasterPyramidsFormat mPyramidsFormat;
221  QStringList mPyramidsConfigOptions;
222 
223  QDomDocument mVRTDocument;
224  QList<QDomElement> mVRTBands;
225 
226  QgsRasterBlockFeedback *mFeedback = nullptr;
227 
228  const QgsRasterPipe *mPipe = nullptr;
229  const QgsRasterInterface *mInput = nullptr;
230 };
231 
232 #endif // QGSRASTERFILEWRITER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:38
Base class for processing modules.
Definition: qgsrasterpipe.h:45
Iterator for sequentially processing raster cells.
QStringList createOptions() const
void setCreateOptions(const QStringList &list)
DataType
Raster data types.
Definition: qgis.h:74
void setOutputFormat(const QString &format)
QString outputProviderKey() const
QString outputFormat() const
#define SIP_FACTORY
Definition: qgis_sip.h:69
void setOutputProviderKey(const QString &key)
Base class for processing filters like renderers, reprojector, resampler etc.
void setPyramidsConfigOptions(const QStringList &list)
QString pyramidsResampling() const
void setPyramidsFormat(QgsRaster::RasterPyramidsFormat f)
This class represents a coordinate reference system (CRS).
void setPyramidsList(const QList< int > &list)
RasterBuildPyramids
Definition: qgsraster.h:73
QStringList pyramidsConfigOptions() const
QList< int > pyramidsList() const
void setPyramidsResampling(const QString &str)
RasterPyramidsFormat
Definition: qgsraster.h:80
Feedback object tailored for raster block reading.
QString outputUrl() const
Returns the output URL for the raster.
QgsRaster::RasterPyramidsFormat pyramidsFormat() const
Base class for raster data providers.
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const
The raster file writer which allows you to save a raster to a new file.
void setBuildPyramidsFlag(QgsRaster::RasterBuildPyramids f)