QGIS API Documentation  2.99.0-Master (b8fd1fd)
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 
27 class QProgressDialog;
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, // Raw data
43  Image = 1 // Rendered image
44  };
46  {
47  NoError = 0,
48  SourceProviderError = 1,
49  DestProviderError = 2,
50  CreateDatasourceError = 3,
51  WriteError = 4,
52  // Internal error if a value used for 'no data' was found in input
53  NoDataConflict = 5
54  };
55 
56  QgsRasterFileWriter( const QString &outputUrl );
57 
65  QgsRasterDataProvider *createOneBandRaster( Qgis::DataType dataType,
66  int width, int height,
67  const QgsRectangle &extent,
68  const QgsCoordinateReferenceSystem &crs );
69 
77  WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
78  const QgsCoordinateReferenceSystem &crs, QProgressDialog *p = nullptr );
79 
80  void setOutputFormat( const QString &format ) { mOutputFormat = format; }
81  QString outputFormat() const { return mOutputFormat; }
82 
83  void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
84  QString outputProviderKey() const { return mOutputProviderKey; }
85 
86  void setTiledMode( bool t ) { mTiledMode = t; }
87  bool tiledMode() const { return mTiledMode; }
88 
89  void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
90  int maxTileWidth() const { return mMaxTileWidth; }
91 
92  QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
93  void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
94 
95  QList< int > pyramidsList() const { return mPyramidsList; }
96  void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
97 
98  QString pyramidsResampling() const { return mPyramidsResampling; }
99  void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
100 
101  QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
102  void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
103 
104  void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
105  int maxTileHeight() const { return mMaxTileHeight; }
106 
107  void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
108  QStringList createOptions() const { return mCreateOptions; }
109 
110  void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
111  QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
112 
113  private:
114  QgsRasterFileWriter(); //forbidden
115  WriterError writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
116  const QgsCoordinateReferenceSystem &crs, QProgressDialog *progressDialog = nullptr );
117 
118  // Helper method used by previous one
119  WriterError writeDataRaster( const QgsRasterPipe *pipe,
120  QgsRasterIterator *iter,
121  int nCols, int nRows,
122  const QgsRectangle &outputExtent,
123  const QgsCoordinateReferenceSystem &crs,
124  Qgis::DataType destDataType,
125  const QList<bool> &destHasNoDataValueList,
126  const QList<double> &destNoDataValueList,
127  QgsRasterDataProvider *destProvider,
128  QProgressDialog *progressDialog );
129 
130  WriterError writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
131  const QgsCoordinateReferenceSystem &crs, QProgressDialog *progressDialog = nullptr );
132 
142  void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
143  //write vrt document to disk
144  bool writeVRT( const QString &file );
145  //add file entry to vrt
146  void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
147  void buildPyramids( const QString &filename );
148 
150  QgsRasterDataProvider *createPartProvider( const QgsRectangle &extent, int nCols, int iterCols, int iterRows,
151  int iterLeft, int iterTop,
152  const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type,
153  const QgsCoordinateReferenceSystem &crs );
154 
165  QgsRasterDataProvider *initOutput( int nCols, int nRows,
166  const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
167  Qgis::DataType type,
168  const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
169 
171  void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
172 
173  QString partFileName( int fileIndex );
174  QString vrtFileName();
175 
176  Mode mMode;
177  QString mOutputUrl;
178  QString mOutputProviderKey;
179  QString mOutputFormat;
180  QStringList mCreateOptions;
181  QgsCoordinateReferenceSystem mOutputCRS;
182 
184  bool mTiledMode;
185  double mMaxTileWidth;
186  double mMaxTileHeight;
187 
188  QList< int > mPyramidsList;
189  QString mPyramidsResampling;
190  QgsRaster::RasterBuildPyramids mBuildPyramidsFlag;
191  QgsRaster::RasterPyramidsFormat mPyramidsFormat;
192  QStringList mPyramidsConfigOptions;
193 
194  QDomDocument mVRTDocument;
195  QList<QDomElement> mVRTBands;
196 
197  QProgressDialog *mProgressDialog = nullptr;
198 
199  const QgsRasterPipe *mPipe = nullptr;
200  const QgsRasterInterface *mInput = nullptr;
201 };
202 
203 #endif // QGSRASTERFILEWRITER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:36
Base class for processing modules.
Definition: qgsrasterpipe.h:44
Iterator for sequentially processing raster cells.
QStringList createOptions() const
void setCreateOptions(const QStringList &list)
DataType
Raster data types.
Definition: qgis.h:61
void setOutputFormat(const QString &format)
QString outputProviderKey() const
QString outputFormat() const
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:89
QStringList pyramidsConfigOptions() const
QList< int > pyramidsList() const
void setPyramidsResampling(const QString &str)
RasterPyramidsFormat
Definition: qgsraster.h:96
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)