QGIS API Documentation  3.2.0-Bonn (bc43194)
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 
38 class CORE_EXPORT QgsRasterFileWriter
39 {
40  public:
41  enum Mode
42  {
43  Raw = 0,
44  Image = 1
45  };
47  {
48  NoError = 0,
49  SourceProviderError = 1,
50  DestProviderError = 2,
51  CreateDatasourceError = 3,
52  WriteError = 4,
53  NoDataConflict = 5,
54  WriteCanceled = 6,
55  };
56 
62  {
63  SortRecommended = 1 << 1,
64  };
65  Q_DECLARE_FLAGS( RasterFormatOptions, RasterFormatOption )
66 
67  QgsRasterFileWriter( const QString &outputUrl );
68 
77  QgsRasterDataProvider *createOneBandRaster( Qgis::DataType dataType,
78  int width, int height,
79  const QgsRectangle &extent,
81 
90  QgsRasterDataProvider *createMultiBandRaster( Qgis::DataType dataType,
91  int width, int height,
92  const QgsRectangle &extent,
94  int nBands ) SIP_FACTORY;
95 
105  WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
106  const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
107 
112  QString outputUrl() const { return mOutputUrl; }
113 
114  void setOutputFormat( const QString &format ) { mOutputFormat = format; }
115  QString outputFormat() const { return mOutputFormat; }
116 
117  void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
118  QString outputProviderKey() const { return mOutputProviderKey; }
119 
120  void setTiledMode( bool t ) { mTiledMode = t; }
121  bool tiledMode() const { return mTiledMode; }
122 
123  void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
124  int maxTileWidth() const { return mMaxTileWidth; }
125 
126  QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
127  void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
128 
129  QList< int > pyramidsList() const { return mPyramidsList; }
130  void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
131 
132  QString pyramidsResampling() const { return mPyramidsResampling; }
133  void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
134 
135  QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
136  void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
137 
138  void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
139  int maxTileHeight() const { return mMaxTileHeight; }
140 
141  void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
142  QStringList createOptions() const { return mCreateOptions; }
143 
144  void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
145  QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
146 
148  static QString filterForDriver( const QString &driverName );
149 
155  {
157  QString driverName;
158 
160  QString filterString;
161  };
162 
172  static QList< QgsRasterFileWriter::FilterFormatDetails > supportedFiltersAndFormats( RasterFormatOptions options = SortRecommended );
173 
183  static QStringList supportedFormatExtensions( RasterFormatOptions options = SortRecommended );
184 
195  static QString driverForExtension( const QString &extension );
196 
208  static QStringList extensionsForFormat( const QString &format );
209 
210  private:
211  QgsRasterFileWriter(); //forbidden
212  WriterError writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
213  const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
214 
215  // Helper method used by previous one
216  WriterError writeDataRaster( const QgsRasterPipe *pipe,
217  QgsRasterIterator *iter,
218  int nCols, int nRows,
219  const QgsRectangle &outputExtent,
220  const QgsCoordinateReferenceSystem &crs,
221  Qgis::DataType destDataType,
222  const QList<bool> &destHasNoDataValueList,
223  const QList<double> &destNoDataValueList,
224  QgsRasterDataProvider *destProvider,
225  QgsRasterBlockFeedback *feedback = nullptr );
226 
227  WriterError writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
228  const QgsCoordinateReferenceSystem &crs,
229  QgsRasterBlockFeedback *feedback = nullptr );
230 
241  void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
242  //write vrt document to disk
243  bool writeVRT( const QString &file );
244  //add file entry to vrt
245  void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
246  void buildPyramids( const QString &filename );
247 
249  QgsRasterDataProvider *createPartProvider( const QgsRectangle &extent, int nCols, int iterCols, int iterRows,
250  int iterLeft, int iterTop,
251  const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type,
252  const QgsCoordinateReferenceSystem &crs );
253 
265  QgsRasterDataProvider *initOutput( int nCols, int nRows,
266  const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
267  Qgis::DataType type,
268  const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
269 
271  void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
272 
273  QString partFileName( int fileIndex );
274  QString vrtFileName();
275 
276  Mode mMode = Raw;
277  QString mOutputUrl;
278  QString mOutputProviderKey;
279  QString mOutputFormat;
280  QStringList mCreateOptions;
281  QgsCoordinateReferenceSystem mOutputCRS;
282 
284  bool mTiledMode = false;
285  double mMaxTileWidth = 500;
286  double mMaxTileHeight = 500;
287 
288  QList< int > mPyramidsList;
289  QString mPyramidsResampling;
292  QStringList mPyramidsConfigOptions;
293 
294  QDomDocument mVRTDocument;
295  QList<QDomElement> mVRTBands;
296 
297  QgsRasterBlockFeedback *mFeedback = nullptr;
298 
299  const QgsRasterPipe *mPipe = nullptr;
300  const QgsRasterInterface *mInput = nullptr;
301 };
302 
303 #endif // QGSRASTERFILEWRITER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:40
Base class for processing modules.
Definition: qgsrasterpipe.h:46
Iterator for sequentially processing raster cells.
QStringList createOptions() const
void setCreateOptions(const QStringList &list)
DataType
Raster data types.
Definition: qgis.h:91
void setOutputFormat(const QString &format)
QString outputProviderKey() const
QString outputFormat() const
RasterFormatOption
Options for sorting and filtering raster formats.
#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:74
QStringList pyramidsConfigOptions() const
QList< int > pyramidsList() const
void setPyramidsResampling(const QString &str)
Details of available filters and formats.
QString filterString
Filter string for file picker dialogs.
RasterPyramidsFormat
Definition: qgsraster.h:81
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)