QGIS API Documentation  2.99.0-Master (9fdd060)
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 
57  QgsRasterFileWriter( const QString &outputUrl );
58 
67  QgsRasterDataProvider *createOneBandRaster( Qgis::DataType dataType,
68  int width, int height,
69  const QgsRectangle &extent,
71 
80  QgsRasterDataProvider *createMultiBandRaster( Qgis::DataType dataType,
81  int width, int height,
82  const QgsRectangle &extent,
84  int nBands ) SIP_FACTORY;
85 
95  WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
96  const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
97 
102  QString outputUrl() const { return mOutputUrl; }
103 
104  void setOutputFormat( const QString &format ) { mOutputFormat = format; }
105  QString outputFormat() const { return mOutputFormat; }
106 
107  void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
108  QString outputProviderKey() const { return mOutputProviderKey; }
109 
110  void setTiledMode( bool t ) { mTiledMode = t; }
111  bool tiledMode() const { return mTiledMode; }
112 
113  void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
114  int maxTileWidth() const { return mMaxTileWidth; }
115 
116  QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
117  void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
118 
119  QList< int > pyramidsList() const { return mPyramidsList; }
120  void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
121 
122  QString pyramidsResampling() const { return mPyramidsResampling; }
123  void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
124 
125  QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
126  void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
127 
128  void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
129  int maxTileHeight() const { return mMaxTileHeight; }
130 
131  void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
132  QStringList createOptions() const { return mCreateOptions; }
133 
134  void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
135  QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
136 
143  static QString driverForExtension( const QString &extension );
144 
145  private:
146  QgsRasterFileWriter(); //forbidden
147  WriterError writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
148  const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
149 
150  // Helper method used by previous one
151  WriterError writeDataRaster( const QgsRasterPipe *pipe,
152  QgsRasterIterator *iter,
153  int nCols, int nRows,
154  const QgsRectangle &outputExtent,
155  const QgsCoordinateReferenceSystem &crs,
156  Qgis::DataType destDataType,
157  const QList<bool> &destHasNoDataValueList,
158  const QList<double> &destNoDataValueList,
159  QgsRasterDataProvider *destProvider,
160  QgsRasterBlockFeedback *feedback = nullptr );
161 
162  WriterError writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
163  const QgsCoordinateReferenceSystem &crs,
164  QgsRasterBlockFeedback *feedback = nullptr );
165 
176  void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
177  //write vrt document to disk
178  bool writeVRT( const QString &file );
179  //add file entry to vrt
180  void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
181  void buildPyramids( const QString &filename );
182 
184  QgsRasterDataProvider *createPartProvider( const QgsRectangle &extent, int nCols, int iterCols, int iterRows,
185  int iterLeft, int iterTop,
186  const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type,
187  const QgsCoordinateReferenceSystem &crs );
188 
200  QgsRasterDataProvider *initOutput( int nCols, int nRows,
201  const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
202  Qgis::DataType type,
203  const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
204 
206  void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
207 
208  QString partFileName( int fileIndex );
209  QString vrtFileName();
210 
211  Mode mMode = Raw;
212  QString mOutputUrl;
213  QString mOutputProviderKey;
214  QString mOutputFormat;
215  QStringList mCreateOptions;
216  QgsCoordinateReferenceSystem mOutputCRS;
217 
219  bool mTiledMode = false;
220  double mMaxTileWidth = 500;
221  double mMaxTileHeight = 500;
222 
223  QList< int > mPyramidsList;
224  QString mPyramidsResampling;
227  QStringList mPyramidsConfigOptions;
228 
229  QDomDocument mVRTDocument;
230  QList<QDomElement> mVRTBands;
231 
232  QgsRasterBlockFeedback *mFeedback = nullptr;
233 
234  const QgsRasterPipe *mPipe = nullptr;
235  const QgsRasterInterface *mInput = nullptr;
236 };
237 
238 #endif // QGSRASTERFILEWRITER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:39
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:78
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:74
QStringList pyramidsConfigOptions() const
QList< int > pyramidsList() const
void setPyramidsResampling(const QString &str)
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)