QGIS API Documentation  2.99.0-Master (ba079d8)
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 
78  WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
79  const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
80 
85  QString outputUrl() const { return mOutputUrl; }
86 
87  void setOutputFormat( const QString &format ) { mOutputFormat = format; }
88  QString outputFormat() const { return mOutputFormat; }
89 
90  void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
91  QString outputProviderKey() const { return mOutputProviderKey; }
92 
93  void setTiledMode( bool t ) { mTiledMode = t; }
94  bool tiledMode() const { return mTiledMode; }
95 
96  void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
97  int maxTileWidth() const { return mMaxTileWidth; }
98 
99  QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
100  void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
101 
102  QList< int > pyramidsList() const { return mPyramidsList; }
103  void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
104 
105  QString pyramidsResampling() const { return mPyramidsResampling; }
106  void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
107 
108  QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
109  void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
110 
111  void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
112  int maxTileHeight() const { return mMaxTileHeight; }
113 
114  void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
115  QStringList createOptions() const { return mCreateOptions; }
116 
117  void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
118  QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
119 
120  private:
121  QgsRasterFileWriter(); //forbidden
122  WriterError writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
123  const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
124 
125  // Helper method used by previous one
126  WriterError writeDataRaster( const QgsRasterPipe *pipe,
127  QgsRasterIterator *iter,
128  int nCols, int nRows,
129  const QgsRectangle &outputExtent,
130  const QgsCoordinateReferenceSystem &crs,
131  Qgis::DataType destDataType,
132  const QList<bool> &destHasNoDataValueList,
133  const QList<double> &destNoDataValueList,
134  QgsRasterDataProvider *destProvider,
135  QgsRasterBlockFeedback *feedback = nullptr );
136 
137  WriterError writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
138  const QgsCoordinateReferenceSystem &crs,
139  QgsRasterBlockFeedback *feedback = nullptr );
140 
150  void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
151  //write vrt document to disk
152  bool writeVRT( const QString &file );
153  //add file entry to vrt
154  void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
155  void buildPyramids( const QString &filename );
156 
158  QgsRasterDataProvider *createPartProvider( const QgsRectangle &extent, int nCols, int iterCols, int iterRows,
159  int iterLeft, int iterTop,
160  const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type,
161  const QgsCoordinateReferenceSystem &crs );
162 
173  QgsRasterDataProvider *initOutput( int nCols, int nRows,
174  const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
175  Qgis::DataType type,
176  const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
177 
179  void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
180 
181  QString partFileName( int fileIndex );
182  QString vrtFileName();
183 
184  Mode mMode;
185  QString mOutputUrl;
186  QString mOutputProviderKey;
187  QString mOutputFormat;
188  QStringList mCreateOptions;
189  QgsCoordinateReferenceSystem mOutputCRS;
190 
192  bool mTiledMode;
193  double mMaxTileWidth;
194  double mMaxTileHeight;
195 
196  QList< int > mPyramidsList;
197  QString mPyramidsResampling;
198  QgsRaster::RasterBuildPyramids mBuildPyramidsFlag;
199  QgsRaster::RasterPyramidsFormat mPyramidsFormat;
200  QStringList mPyramidsConfigOptions;
201 
202  QDomDocument mVRTDocument;
203  QList<QDomElement> mVRTBands;
204 
205  QgsRasterBlockFeedback *mFeedback = nullptr;
206 
207  const QgsRasterPipe *mPipe = nullptr;
208  const QgsRasterInterface *mInput = nullptr;
209 };
210 
211 #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:64
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:90
QStringList pyramidsConfigOptions() const
QList< int > pyramidsList() const
void setPyramidsResampling(const QString &str)
RasterPyramidsFormat
Definition: qgsraster.h:97
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)