QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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"
21 #include <QDomDocument>
22 #include <QDomElement>
23 #include <QString>
24 #include <QStringList>
25 
26 #include "qgsraster.h"
27 
29 class QgsRasterIterator;
30 class QgsRasterPipe;
31 class QgsRectangle;
33 class QgsRasterInterface;
34 
39 class CORE_EXPORT QgsRasterFileWriter
40 {
41  public:
42  enum Mode
43  {
44  Raw = 0,
45  Image = 1
46  };
48  {
49  NoError = 0,
50  SourceProviderError = 1,
51  DestProviderError = 2,
52  CreateDatasourceError = 3,
53  WriteError = 4,
54  NoDataConflict = 5,
55  WriteCanceled = 6,
56  };
57 
63  {
64  SortRecommended = 1 << 1,
65  };
66  Q_DECLARE_FLAGS( RasterFormatOptions, RasterFormatOption )
67 
68  QgsRasterFileWriter( const QString &outputUrl );
69 
78  QgsRasterDataProvider *createOneBandRaster( Qgis::DataType dataType,
79  int width, int height,
80  const QgsRectangle &extent,
82 
91  QgsRasterDataProvider *createMultiBandRaster( Qgis::DataType dataType,
92  int width, int height,
93  const QgsRectangle &extent,
95  int nBands ) SIP_FACTORY;
96 
97 
108  Q_DECL_DEPRECATED WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
110 
122  WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
124  const QgsCoordinateTransformContext &transformContext,
125  QgsRasterBlockFeedback *feedback = nullptr );
126 
127 
132  QString outputUrl() const { return mOutputUrl; }
133 
134  void setOutputFormat( const QString &format ) { mOutputFormat = format; }
135  QString outputFormat() const { return mOutputFormat; }
136 
137  void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
138  QString outputProviderKey() const { return mOutputProviderKey; }
139 
140  void setTiledMode( bool t ) { mTiledMode = t; }
141  bool tiledMode() const { return mTiledMode; }
142 
143  void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
144  int maxTileWidth() const { return mMaxTileWidth; }
145 
146  QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
147  void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
148 
149  QList< int > pyramidsList() const { return mPyramidsList; }
150  void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
151 
152  QString pyramidsResampling() const { return mPyramidsResampling; }
153  void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
154 
155  QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
156  void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
157 
158  void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
159  int maxTileHeight() const { return mMaxTileHeight; }
160 
161  void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
162  QStringList createOptions() const { return mCreateOptions; }
163 
164  void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
165  QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
166 
168  static QString filterForDriver( const QString &driverName );
169 
175  {
177  QString driverName;
178 
180  QString filterString;
181  };
182 
192  static QList< QgsRasterFileWriter::FilterFormatDetails > supportedFiltersAndFormats( RasterFormatOptions options = SortRecommended );
193 
203  static QStringList supportedFormatExtensions( RasterFormatOptions options = SortRecommended );
204 
215  static QString driverForExtension( const QString &extension );
216 
228  static QStringList extensionsForFormat( const QString &format );
229 
230  private:
231  QgsRasterFileWriter(); //forbidden
232  WriterError writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
233  const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext,
234  QgsRasterBlockFeedback *feedback = nullptr );
235 
236  // Helper method used by previous one
237  WriterError writeDataRaster( const QgsRasterPipe *pipe,
238  QgsRasterIterator *iter,
239  int nCols, int nRows,
240  const QgsRectangle &outputExtent,
242  Qgis::DataType destDataType,
243  const QList<bool> &destHasNoDataValueList,
244  const QList<double> &destNoDataValueList,
245  QgsRasterDataProvider *destProvider,
246  QgsRasterBlockFeedback *feedback = nullptr );
247 
248  WriterError writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
250  QgsRasterBlockFeedback *feedback = nullptr );
251 
262  void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
263  //write vrt document to disk
264  bool writeVRT( const QString &file );
265  //add file entry to vrt
266  void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
267  void buildPyramids( const QString &filename, QgsRasterDataProvider *destProviderIn = nullptr );
268 
270  QgsRasterDataProvider *createPartProvider( const QgsRectangle &extent, int nCols, int iterCols, int iterRows,
271  int iterLeft, int iterTop,
272  const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type,
274 
286  QgsRasterDataProvider *initOutput( int nCols, int nRows,
287  const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
288  Qgis::DataType type,
289  const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
290 
292  void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
293 
294  QString partFileName( int fileIndex );
295  QString vrtFileName();
296 
297  Mode mMode = Raw;
298  QString mOutputUrl;
299  QString mOutputProviderKey = QStringLiteral( "gdal" );
300  QString mOutputFormat = QStringLiteral( "GTiff" );
301  QStringList mCreateOptions;
302  QgsCoordinateReferenceSystem mOutputCRS;
303 
305  bool mTiledMode = false;
306  int mMaxTileWidth = 500;
307  int mMaxTileHeight = 500;
308 
309  QList< int > mPyramidsList;
310  QString mPyramidsResampling = QStringLiteral( "AVERAGE" );
313  QStringList mPyramidsConfigOptions;
314 
315  QDomDocument mVRTDocument;
316  QList<QDomElement> mVRTBands;
317 
318  QgsRasterBlockFeedback *mFeedback = nullptr;
319 
320  const QgsRasterPipe *mPipe = nullptr;
321  const QgsRasterInterface *mInput = nullptr;
322 };
323 
324 #endif // QGSRASTERFILEWRITER_H
QgsRasterFileWriter::Mode
Mode
Definition: qgsrasterfilewriter.h:42
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:114
QgsRasterFileWriter::FilterFormatDetails
Details of available filters and formats.
Definition: qgsrasterfilewriter.h:174
QgsCoordinateTransformContext
Definition: qgscoordinatetransformcontext.h:57
QgsRasterFileWriter::setBuildPyramidsFlag
void setBuildPyramidsFlag(QgsRaster::RasterBuildPyramids f)
Definition: qgsrasterfilewriter.h:147
qgscoordinatetransformcontext.h
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsRasterFileWriter::maxTileHeight
int maxTileHeight() const
Definition: qgsrasterfilewriter.h:159
QgsRaster::RasterPyramidsFormat
RasterPyramidsFormat
Definition: qgsraster.h:94
QgsRasterFileWriter::setPyramidsFormat
void setPyramidsFormat(QgsRaster::RasterPyramidsFormat f)
Definition: qgsrasterfilewriter.h:156
QgsRasterPipe
Definition: qgsrasterpipe.h:46
QgsRectangle
Definition: qgsrectangle.h:41
QgsRasterFileWriter::WriterError
WriterError
Definition: qgsrasterfilewriter.h:47
QgsRaster::PyramidsFlagNo
@ PyramidsFlagNo
Definition: qgsraster.h:89
QgsRasterFileWriter::pyramidsConfigOptions
QStringList pyramidsConfigOptions() const
Definition: qgsrasterfilewriter.h:165
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsRasterFileWriter::setMaxTileWidth
void setMaxTileWidth(int w)
Definition: qgsrasterfilewriter.h:143
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
QgsRasterFileWriter::setPyramidsResampling
void setPyramidsResampling(const QString &str)
Definition: qgsrasterfilewriter.h:153
QgsRaster::RasterBuildPyramids
RasterBuildPyramids
Definition: qgsraster.h:87
QgsRasterFileWriter::buildPyramidsFlag
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const
Definition: qgsrasterfilewriter.h:146
qgsraster.h
QgsRasterFileWriter::maxTileWidth
int maxTileWidth() const
Definition: qgsrasterfilewriter.h:144
QgsRasterFileWriter::RasterFormatOption
RasterFormatOption
Options for sorting and filtering raster formats.
Definition: qgsrasterfilewriter.h:62
QgsRasterFileWriter::outputProviderKey
QString outputProviderKey() const
Definition: qgsrasterfilewriter.h:138
QgsRasterFileWriter::setTiledMode
void setTiledMode(bool t)
Definition: qgsrasterfilewriter.h:140
QgsRasterFileWriter::setCreateOptions
void setCreateOptions(const QStringList &list)
Definition: qgsrasterfilewriter.h:161
QgsRasterFileWriter::pyramidsList
QList< int > pyramidsList() const
Definition: qgsrasterfilewriter.h:149
QgsRasterFileWriter::setPyramidsList
void setPyramidsList(const QList< int > &list)
Definition: qgsrasterfilewriter.h:150
QgsRasterIterator
Definition: qgsrasteriterator.h:34
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsRasterFileWriter::setPyramidsConfigOptions
void setPyramidsConfigOptions(const QStringList &list)
Definition: qgsrasterfilewriter.h:164
QgsRasterFileWriter::outputFormat
QString outputFormat() const
Definition: qgsrasterfilewriter.h:135
QgsRasterFileWriter
Definition: qgsrasterfilewriter.h:39
QgsRasterInterface
Definition: qgsrasterinterface.h:116
QgsRasterFileWriter::FilterFormatDetails::driverName
QString driverName
Unique driver name.
Definition: qgsrasterfilewriter.h:177
QgsRasterFileWriter::pyramidsFormat
QgsRaster::RasterPyramidsFormat pyramidsFormat() const
Definition: qgsrasterfilewriter.h:155
QgsRasterFileWriter::setMaxTileHeight
void setMaxTileHeight(int h)
Definition: qgsrasterfilewriter.h:158
QgsRasterFileWriter::FilterFormatDetails::filterString
QString filterString
Filter string for file picker dialogs.
Definition: qgsrasterfilewriter.h:180
QgsRasterBlockFeedback
Definition: qgsrasterinterface.h:40
QgsRasterFileWriter::createOptions
QStringList createOptions() const
Definition: qgsrasterfilewriter.h:162
QgsRasterFileWriter::pyramidsResampling
QString pyramidsResampling() const
Definition: qgsrasterfilewriter.h:152
QgsRasterFileWriter::tiledMode
bool tiledMode() const
Definition: qgsrasterfilewriter.h:141
QgsRaster::PyramidsGTiff
@ PyramidsGTiff
Definition: qgsraster.h:96
qgscoordinatereferencesystem.h
QgsRasterDataProvider
Definition: qgsrasterdataprovider.h:88
QgsRasterFileWriter::setOutputProviderKey
void setOutputProviderKey(const QString &key)
Definition: qgsrasterfilewriter.h:137
QgsRasterFileWriter::setOutputFormat
void setOutputFormat(const QString &format)
Definition: qgsrasterfilewriter.h:134