QGIS API Documentation  2.99.0-Master (69af2f5)
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 
37 class CORE_EXPORT QgsRasterFileWriter
38 {
39  public:
40  enum Mode
41  {
42  Raw = 0,
43  Image = 1
44  };
46  {
47  NoError = 0,
48  SourceProviderError = 1,
49  DestProviderError = 2,
50  CreateDatasourceError = 3,
51  WriteError = 4,
52  NoDataConflict = 5,
53  WriteCanceled = 6,
54  };
55 
56  QgsRasterFileWriter( const QString &outputUrl );
57 
65  QgsRasterDataProvider *createOneBandRaster( Qgis::DataType dataType,
66  int width, int height,
67  const QgsRectangle &extent,
69 
77  QgsRasterDataProvider *createMultiBandRaster( Qgis::DataType dataType,
78  int width, int height,
79  const QgsRectangle &extent,
81  int nBands ) SIP_FACTORY;
82 
91  WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
92  const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
93 
98  QString outputUrl() const { return mOutputUrl; }
99 
100  void setOutputFormat( const QString &format ) { mOutputFormat = format; }
101  QString outputFormat() const { return mOutputFormat; }
102 
103  void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
104  QString outputProviderKey() const { return mOutputProviderKey; }
105 
106  void setTiledMode( bool t ) { mTiledMode = t; }
107  bool tiledMode() const { return mTiledMode; }
108 
109  void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
110  int maxTileWidth() const { return mMaxTileWidth; }
111 
112  QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
113  void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
114 
115  QList< int > pyramidsList() const { return mPyramidsList; }
116  void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
117 
118  QString pyramidsResampling() const { return mPyramidsResampling; }
119  void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
120 
121  QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
122  void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
123 
124  void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
125  int maxTileHeight() const { return mMaxTileHeight; }
126 
127  void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
128  QStringList createOptions() const { return mCreateOptions; }
129 
130  void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
131  QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
132 
133  private:
134  QgsRasterFileWriter(); //forbidden
135  WriterError writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
136  const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
137 
138  // Helper method used by previous one
139  WriterError writeDataRaster( const QgsRasterPipe *pipe,
140  QgsRasterIterator *iter,
141  int nCols, int nRows,
142  const QgsRectangle &outputExtent,
143  const QgsCoordinateReferenceSystem &crs,
144  Qgis::DataType destDataType,
145  const QList<bool> &destHasNoDataValueList,
146  const QList<double> &destNoDataValueList,
147  QgsRasterDataProvider *destProvider,
148  QgsRasterBlockFeedback *feedback = nullptr );
149 
150  WriterError writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
151  const QgsCoordinateReferenceSystem &crs,
152  QgsRasterBlockFeedback *feedback = nullptr );
153 
163  void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
164  //write vrt document to disk
165  bool writeVRT( const QString &file );
166  //add file entry to vrt
167  void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
168  void buildPyramids( const QString &filename );
169 
171  QgsRasterDataProvider *createPartProvider( const QgsRectangle &extent, int nCols, int iterCols, int iterRows,
172  int iterLeft, int iterTop,
173  const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type,
174  const QgsCoordinateReferenceSystem &crs );
175 
186  QgsRasterDataProvider *initOutput( int nCols, int nRows,
187  const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
188  Qgis::DataType type,
189  const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
190 
192  void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
193 
194  QString partFileName( int fileIndex );
195  QString vrtFileName();
196 
197  Mode mMode;
198  QString mOutputUrl;
199  QString mOutputProviderKey;
200  QString mOutputFormat;
201  QStringList mCreateOptions;
202  QgsCoordinateReferenceSystem mOutputCRS;
203 
205  bool mTiledMode;
206  double mMaxTileWidth;
207  double mMaxTileHeight;
208 
209  QList< int > mPyramidsList;
210  QString mPyramidsResampling;
211  QgsRaster::RasterBuildPyramids mBuildPyramidsFlag;
212  QgsRaster::RasterPyramidsFormat mPyramidsFormat;
213  QStringList mPyramidsConfigOptions;
214 
215  QDomDocument mVRTDocument;
216  QList<QDomElement> mVRTBands;
217 
218  QgsRasterBlockFeedback *mFeedback = nullptr;
219 
220  const QgsRasterPipe *mPipe = nullptr;
221  const QgsRasterInterface *mInput = nullptr;
222 };
223 
224 #endif // QGSRASTERFILEWRITER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:38
Base class for processing modules.
Definition: qgsrasterpipe.h:45
Iterator for sequentially processing raster cells.
QStringList createOptions() const
void setCreateOptions(const QStringList &list)
DataType
Raster data types.
Definition: qgis.h:74
void setOutputFormat(const QString &format)
QString outputProviderKey() const
QString outputFormat() const
#define SIP_FACTORY
Definition: qgis_sip.h:57
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:73
QStringList pyramidsConfigOptions() const
QList< int > pyramidsList() const
void setPyramidsResampling(const QString &str)
RasterPyramidsFormat
Definition: qgsraster.h:80
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)