QGIS API Documentation  2.99.0-Master (c558d51)
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 
19 #include <QDomDocument>
20 #include <QDomElement>
21 #include <QString>
22 #include <QStringList>
23 
24 #include "qgsraster.h"
25 
26 class QProgressDialog;
27 class QgsRasterIterator;
28 class QgsRasterPipe;
29 class QgsRectangle;
31 class QgsRasterInterface;
32 
36 class CORE_EXPORT QgsRasterFileWriter
37 {
38  public:
39  enum Mode
40  {
41  Raw = 0, // Raw data
42  Image = 1 // Rendered image
43  };
45  {
46  NoError = 0,
47  SourceProviderError = 1,
48  DestProviderError = 2,
49  CreateDatasourceError = 3,
50  WriteError = 4,
51  // Internal error if a value used for 'no data' was found in input
52  NoDataConflict = 5
53  };
54 
55  QgsRasterFileWriter( const QString& outputUrl );
56 
64  WriterError writeRaster( const QgsRasterPipe* pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
65  const QgsCoordinateReferenceSystem& crs, QProgressDialog* p = nullptr );
66 
67  void setOutputFormat( const QString& format ) { mOutputFormat = format; }
68  QString outputFormat() const { return mOutputFormat; }
69 
70  void setOutputProviderKey( const QString& key ) { mOutputProviderKey = key; }
71  QString outputProviderKey() const { return mOutputProviderKey; }
72 
73  void setTiledMode( bool t ) { mTiledMode = t; }
74  bool tiledMode() const { return mTiledMode; }
75 
76  void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
77  int maxTileWidth() const { return mMaxTileWidth; }
78 
79  QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
80  void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
81 
82  QList< int > pyramidsList() const { return mPyramidsList; }
83  void setPyramidsList( const QList< int > & list ) { mPyramidsList = list; }
84 
85  QString pyramidsResampling() const { return mPyramidsResampling; }
86  void setPyramidsResampling( const QString & str ) { mPyramidsResampling = str; }
87 
88  QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
89  void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
90 
91  void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
92  int maxTileHeight() const { return mMaxTileHeight; }
93 
94  void setCreateOptions( const QStringList& list ) { mCreateOptions = list; }
95  QStringList createOptions() const { return mCreateOptions; }
96 
97  void setPyramidsConfigOptions( const QStringList& list ) { mPyramidsConfigOptions = list; }
98  QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
99 
100  private:
101  QgsRasterFileWriter(); //forbidden
102  WriterError writeDataRaster( const QgsRasterPipe* pipe, QgsRasterIterator* iter, int nCols, int nRows, const QgsRectangle& outputExtent,
103  const QgsCoordinateReferenceSystem& crs, QProgressDialog* progressDialog = nullptr );
104 
105  // Helper method used by previous one
106  WriterError writeDataRaster( const QgsRasterPipe* pipe,
107  QgsRasterIterator* iter,
108  int nCols, int nRows,
109  const QgsRectangle& outputExtent,
110  const QgsCoordinateReferenceSystem& crs,
111  Qgis::DataType destDataType,
112  const QList<bool>& destHasNoDataValueList,
113  const QList<double>& destNoDataValueList,
114  QgsRasterDataProvider* destProvider,
115  QProgressDialog* progressDialog );
116 
117  WriterError writeImageRaster( QgsRasterIterator* iter, int nCols, int nRows, const QgsRectangle& outputExtent,
118  const QgsCoordinateReferenceSystem& crs, QProgressDialog* progressDialog = nullptr );
119 
129  void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem& crs, double* geoTransform, Qgis::DataType type, const QList<bool>& destHasNoDataValueList, const QList<double>& destNoDataValueList );
130  //write vrt document to disk
131  bool writeVRT( const QString& file );
132  //add file entry to vrt
133  void addToVRT( const QString& filename, int band, int xSize, int ySize, int xOffset, int yOffset );
134  void buildPyramids( const QString& filename );
135 
137  QgsRasterDataProvider* createPartProvider( const QgsRectangle& extent, int nCols, int iterCols, int iterRows,
138  int iterLeft, int iterTop,
139  const QString& outputUrl, int fileIndex, int nBands, Qgis::DataType type,
140  const QgsCoordinateReferenceSystem& crs );
141 
152  QgsRasterDataProvider* initOutput( int nCols, int nRows,
153  const QgsCoordinateReferenceSystem& crs, double* geoTransform, int nBands,
154  Qgis::DataType type,
155  const QList<bool>& destHasNoDataValueList = QList<bool>(), const QList<double>& destNoDataValueList = QList<double>() );
156 
158  void globalOutputParameters( const QgsRectangle& extent, int nCols, int& nRows, double* geoTransform, double& pixelSize );
159 
160  QString partFileName( int fileIndex );
161  QString vrtFileName();
162 
163  Mode mMode;
164  QString mOutputUrl;
165  QString mOutputProviderKey;
166  QString mOutputFormat;
167  QStringList mCreateOptions;
168  QgsCoordinateReferenceSystem mOutputCRS;
169 
171  bool mTiledMode;
172  double mMaxTileWidth;
173  double mMaxTileHeight;
174 
175  QList< int > mPyramidsList;
176  QString mPyramidsResampling;
177  QgsRaster::RasterBuildPyramids mBuildPyramidsFlag;
178  QgsRaster::RasterPyramidsFormat mPyramidsFormat;
179  QStringList mPyramidsConfigOptions;
180 
181  QDomDocument mVRTDocument;
182  QList<QDomElement> mVRTBands;
183 
184  QProgressDialog* mProgressDialog;
185 
186  const QgsRasterPipe* mPipe;
187  const QgsRasterInterface* mInput;
188 };
189 
190 #endif // QGSRASTERFILEWRITER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for processing modules.
Definition: qgsrasterpipe.h:43
Iterator for sequentially processing raster cells.
QgsRaster::RasterPyramidsFormat pyramidsFormat() const
void setCreateOptions(const QStringList &list)
DataType
Raster data types.
Definition: qgis.h:60
void setOutputFormat(const QString &format)
QStringList pyramidsConfigOptions() const
QList< int > pyramidsList() const
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const
QString pyramidsResampling() const
QStringList createOptions() const
void setOutputProviderKey(const QString &key)
Base class for processing filters like renderers, reprojector, resampler etc.
void setPyramidsConfigOptions(const QStringList &list)
QString outputFormat() const
QString outputProviderKey() const
void setPyramidsFormat(QgsRaster::RasterPyramidsFormat f)
This class represents a coordinate reference system (CRS).
void setPyramidsList(const QList< int > &list)
RasterBuildPyramids
Definition: qgsraster.h:88
void setPyramidsResampling(const QString &str)
RasterPyramidsFormat
Definition: qgsraster.h:95
Base class for raster data providers.
The raster file writer which allows you to save a raster to a new file.
void setBuildPyramidsFlag(QgsRaster::RasterBuildPyramids f)