QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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"
21 #include <QDomDocument>
22 #include <QDomElement>
23 #include <QString>
24 #include <QStringList>
25 
26 #include "qgsraster.h"
27 
29 class QgsRasterIterator;
30 class QgsRasterPipe;
31 class QgsRectangle;
33 class QgsRasterInterface;
34 
39 class CORE_EXPORT QgsRasterFileWriter
40 {
41  public:
42  enum Mode
43  {
44  Raw = 0,
45  Image = 1
46  };
48  {
49  NoError = 0,
50  SourceProviderError = 1,
51  DestProviderError = 2,
52  CreateDatasourceError = 3,
53  WriteError = 4,
54  NoDataConflict = 5,
55  WriteCanceled = 6,
56  };
57 
63  {
64  SortRecommended = 1 << 1,
65  };
66  Q_DECLARE_FLAGS( RasterFormatOptions, RasterFormatOption )
67 
68  QgsRasterFileWriter( const QString &outputUrl );
69 
78  QgsRasterDataProvider *createOneBandRaster( Qgis::DataType dataType,
79  int width, int height,
80  const QgsRectangle &extent,
82 
91  QgsRasterDataProvider *createMultiBandRaster( Qgis::DataType dataType,
92  int width, int height,
93  const QgsRectangle &extent,
95  int nBands ) SIP_FACTORY;
96 
97 
108  Q_DECL_DEPRECATED WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
110 
122  WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
124  const QgsCoordinateTransformContext &transformContext,
125  QgsRasterBlockFeedback *feedback = nullptr );
126 
127 
132  QString outputUrl() const { return mOutputUrl; }
133 
134  void setOutputFormat( const QString &format ) { mOutputFormat = format; }
135  QString outputFormat() const { return mOutputFormat; }
136 
137  void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
138  QString outputProviderKey() const { return mOutputProviderKey; }
139 
140  void setTiledMode( bool t ) { mTiledMode = t; }
141  bool tiledMode() const { return mTiledMode; }
142 
143  void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
144  int maxTileWidth() const { return mMaxTileWidth; }
145 
146  QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
147  void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
148 
149  QList< int > pyramidsList() const { return mPyramidsList; }
150  void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
151 
152  QString pyramidsResampling() const { return mPyramidsResampling; }
153  void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
154 
155  QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
156  void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
157 
158  void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
159  int maxTileHeight() const { return mMaxTileHeight; }
160 
161  void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
162  QStringList createOptions() const { return mCreateOptions; }
163 
164  void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
165  QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
166 
168  static QString filterForDriver( const QString &driverName );
169 
175  {
177  QString driverName;
178 
180  QString filterString;
181  };
182 
192  static QList< QgsRasterFileWriter::FilterFormatDetails > supportedFiltersAndFormats( RasterFormatOptions options = SortRecommended );
193 
203  static QStringList supportedFormatExtensions( RasterFormatOptions options = SortRecommended );
204 
215  static QString driverForExtension( const QString &extension );
216 
228  static QStringList extensionsForFormat( const QString &format );
229 
230  private:
231  QgsRasterFileWriter(); //forbidden
232  WriterError writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
233  const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext,
234  QgsRasterBlockFeedback *feedback = nullptr );
235 
236  // Helper method used by previous one
237  WriterError writeDataRaster( const QgsRasterPipe *pipe,
238  QgsRasterIterator *iter,
239  int nCols, int nRows,
240  const QgsRectangle &outputExtent,
242  Qgis::DataType destDataType,
243  const QList<bool> &destHasNoDataValueList,
244  const QList<double> &destNoDataValueList,
245  QgsRasterDataProvider *destProvider,
246  QgsRasterBlockFeedback *feedback = nullptr );
247 
248  WriterError writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
250  QgsRasterBlockFeedback *feedback = nullptr );
251 
262  void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
263  //write vrt document to disk
264  bool writeVRT( const QString &file );
265  //add file entry to vrt
266  void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
267  void buildPyramids( const QString &filename, QgsRasterDataProvider *destProviderIn = nullptr );
268 
270  QgsRasterDataProvider *createPartProvider( const QgsRectangle &extent, int nCols, int iterCols, int iterRows,
271  int iterLeft, int iterTop,
272  const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type,
274 
286  QgsRasterDataProvider *initOutput( int nCols, int nRows,
287  const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
288  Qgis::DataType type,
289  const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
290 
292  void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
293 
294  QString partFileName( int fileIndex );
295  QString vrtFileName();
296 
297  Mode mMode = Raw;
298  QString mOutputUrl;
299  QString mOutputProviderKey = QStringLiteral( "gdal" );
300  QString mOutputFormat = QStringLiteral( "GTiff" );
301  QStringList mCreateOptions;
302  QgsCoordinateReferenceSystem mOutputCRS;
303 
305  bool mTiledMode = false;
306  int mMaxTileWidth = 500;
307  int mMaxTileHeight = 500;
308 
309  QList< int > mPyramidsList;
310  QString mPyramidsResampling = QStringLiteral( "AVERAGE" );
313  QStringList mPyramidsConfigOptions;
314 
315  QDomDocument mVRTDocument;
316  QList<QDomElement> mVRTBands;
317 
318  QgsRasterBlockFeedback *mFeedback = nullptr;
319 
320  const QgsRasterPipe *mPipe = nullptr;
321  const QgsRasterInterface *mInput = nullptr;
322 };
323 
324 #endif // QGSRASTERFILEWRITER_H
DataType
Raster data types.
Definition: qgis.h:102
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Feedback object tailored for raster block reading.
Base class for raster data providers.
The raster file writer which allows you to save a raster to a new file.
void setPyramidsList(const QList< int > &list)
void setPyramidsResampling(const QString &str)
void setPyramidsFormat(QgsRaster::RasterPyramidsFormat f)
QStringList pyramidsConfigOptions() const
void setOutputProviderKey(const QString &key)
QString outputFormat() const
QStringList createOptions() const
QString outputProviderKey() const
QString pyramidsResampling() const
void setBuildPyramidsFlag(QgsRaster::RasterBuildPyramids f)
QList< int > pyramidsList() const
RasterFormatOption
Options for sorting and filtering raster formats.
void setOutputFormat(const QString &format)
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const
void setCreateOptions(const QStringList &list)
void setPyramidsConfigOptions(const QStringList &list)
QgsRaster::RasterPyramidsFormat pyramidsFormat() const
Base class for processing filters like renderers, reprojector, resampler etc.
Iterator for sequentially processing raster cells.
Base class for processing modules.
Definition: qgsrasterpipe.h:47
RasterPyramidsFormat
Definition: qgsraster.h:82
@ PyramidsGTiff
Definition: qgsraster.h:83
RasterBuildPyramids
Definition: qgsraster.h:75
@ PyramidsFlagNo
Definition: qgsraster.h:76
A rectangle specified with double values.
Definition: qgsrectangle.h:42
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_FACTORY
Definition: qgis_sip.h:76
const QgsCoordinateReferenceSystem & crs
Details of available filters and formats.
QString filterString
Filter string for file picker dialogs.