QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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
28class QgsRasterPipe;
29class QgsRectangle;
32
40class CORE_EXPORT QgsRasterFileWriter
41{
42 public:
43
49 {
50 SortRecommended = 1 << 1,
51 };
52 Q_DECLARE_FLAGS( RasterFormatOptions, RasterFormatOption )
53
54
57 QgsRasterFileWriter( const QString &outputUrl );
58
67 QgsRasterDataProvider *createOneBandRaster( Qgis::DataType dataType,
68 int width, int height,
69 const QgsRectangle &extent,
71
80 QgsRasterDataProvider *createMultiBandRaster( Qgis::DataType dataType,
81 int width, int height,
82 const QgsRectangle &extent,
84 int nBands ) SIP_FACTORY;
85
86
97 Q_DECL_DEPRECATED Qgis::RasterFileWriterResult writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
99
111 Qgis::RasterFileWriterResult writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
113 const QgsCoordinateTransformContext &transformContext,
114 QgsRasterBlockFeedback *feedback = nullptr );
115
120 QString outputUrl() const { return mOutputUrl; }
121
129 void setOutputFormat( const QString &format ) { mOutputFormat = format; }
130
138 QString outputFormat() const { return mOutputFormat; }
139
147 void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
148
154 QString outputProviderKey() const { return mOutputProviderKey; }
155
164 void setTiledMode( bool t ) { mTiledMode = t; }
165
171 bool tiledMode() const { return mTiledMode; }
172
180 void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
181
189 int maxTileWidth() const { return mMaxTileWidth; }
190
196 Qgis::RasterBuildPyramidOption buildPyramidsFlag() const { return mBuildPyramidsFlag; }
197
203 void setBuildPyramidsFlag( Qgis::RasterBuildPyramidOption f ) { mBuildPyramidsFlag = f; }
204
210 QList< int > pyramidsList() const { return mPyramidsList; }
211
217 void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
218
219 QString pyramidsResampling() const { return mPyramidsResampling; }
220 void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
221
227 Qgis::RasterPyramidFormat pyramidsFormat() const { return mPyramidsFormat; }
228
234 void setPyramidsFormat( Qgis::RasterPyramidFormat f ) { mPyramidsFormat = f; }
235
243 void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
244
252 int maxTileHeight() const { return mMaxTileHeight; }
253
260 void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
261
268 QStringList createOptions() const { return mCreateOptions; }
269
276 void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
277
284 QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
285
287 static QString filterForDriver( const QString &driverName );
288
294 {
296 QString driverName;
297
300 };
301
311 static QList< QgsRasterFileWriter::FilterFormatDetails > supportedFiltersAndFormats( RasterFormatOptions options = SortRecommended );
312
322 static QStringList supportedFormatExtensions( RasterFormatOptions options = SortRecommended );
323
334 static QString driverForExtension( const QString &extension );
335
347 static QStringList extensionsForFormat( const QString &format );
348
349 private:
350 QgsRasterFileWriter(); //forbidden
351 Qgis::RasterFileWriterResult writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
352 const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext,
353 QgsRasterBlockFeedback *feedback = nullptr );
354
355 // Helper method used by previous one
356 Qgis::RasterFileWriterResult writeDataRaster( const QgsRasterPipe *pipe,
357 QgsRasterIterator *iter,
358 int nCols, int nRows,
359 const QgsRectangle &outputExtent,
361 Qgis::DataType destDataType,
362 const QList<bool> &destHasNoDataValueList,
363 const QList<double> &destNoDataValueList,
364 QgsRasterDataProvider *destProvider,
365 QgsRasterBlockFeedback *feedback = nullptr );
366
367 Qgis::RasterFileWriterResult writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
369 QgsRasterBlockFeedback *feedback = nullptr );
370
381 void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
382 //write vrt document to disk
383 bool writeVRT( const QString &file );
384 //add file entry to vrt
385 void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
386 void buildPyramids( const QString &filename, QgsRasterDataProvider *destProviderIn = nullptr );
387
389 QgsRasterDataProvider *createPartProvider( const QgsRectangle &extent, int nCols, int iterCols, int iterRows,
390 int iterLeft, int iterTop,
391 const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type,
393
405 QgsRasterDataProvider *initOutput( int nCols, int nRows,
406 const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
407 Qgis::DataType type,
408 const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
409
411 void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
412
413 QString partFileName( int fileIndex );
414 QString vrtFileName();
415
417 QString mOutputUrl;
418 QString mOutputProviderKey = QStringLiteral( "gdal" );
419 QString mOutputFormat = QStringLiteral( "GTiff" );
420 QStringList mCreateOptions;
422
424 bool mTiledMode = false;
425 int mMaxTileWidth = 500;
426 int mMaxTileHeight = 500;
427
428 QList< int > mPyramidsList;
429 QString mPyramidsResampling = QStringLiteral( "AVERAGE" );
430 Qgis::RasterBuildPyramidOption mBuildPyramidsFlag = Qgis::RasterBuildPyramidOption::No;
431 Qgis::RasterPyramidFormat mPyramidsFormat = Qgis::RasterPyramidFormat::GeoTiff;
432 QStringList mPyramidsConfigOptions;
433
434 QDomDocument mVRTDocument;
435 QList<QDomElement> mVRTBands;
436
437 QgsRasterBlockFeedback *mFeedback = nullptr;
438
439 const QgsRasterPipe *mPipe = nullptr;
440 const QgsRasterInterface *mInput = nullptr;
441};
442
443#endif // QGSRASTERFILEWRITER_H
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:54
RasterPyramidFormat
Raster pyramid formats.
Definition: qgis.h:3167
RasterFileWriterResult
Raster file export results.
Definition: qgis.h:1094
DataType
Raster data types.
Definition: qgis.h:241
RasterBuildPyramidOption
Raster pyramid building options.
Definition: qgis.h:3182
RasterExportType
Raster file export types.
Definition: qgis.h:1081
This class represents a coordinate reference system (CRS).
Contains information about the context in which a coordinate transform is executed.
Feedback object tailored for raster block reading.
Base class for raster data providers.
The raster file writer which allows you to save a raster to a new file.
void setPyramidsList(const QList< int > &list)
Sets the list of pyramids which will be created for the output file.
void setPyramidsResampling(const QString &str)
int maxTileHeight() const
Returns the maximum tile height (in pixels) for tiled outputs.
void setMaxTileWidth(int w)
Sets the maximum tile width (in pixels) for tiled outputs.
void setTiledMode(bool t)
Sets whether the output should be tiled.
QStringList pyramidsConfigOptions() const
Returns the list of configuration options used when creating the pyramids for the output raster file.
Qgis::RasterBuildPyramidOption buildPyramidsFlag() const
Returns the pyramid building option.
void setOutputProviderKey(const QString &key)
Sets the name of the data provider for the raster output.
void setMaxTileHeight(int h)
Sets the maximum tile height (in pixels) for tiled outputs.
Qgis::RasterPyramidFormat pyramidsFormat() const
Returns the raster pyramid format.
QString outputFormat() const
Returns the output format.
QStringList createOptions() const
Returns the list of data source creation options which will be used when creating the output raster f...
QString outputProviderKey() const
Returns the name of the data provider for the raster output.
QString pyramidsResampling() const
QList< int > pyramidsList() const
Returns the list of pyramids which will be created for the output file.
void setPyramidsFormat(Qgis::RasterPyramidFormat f)
Sets the raster pyramid format.
RasterFormatOption
Options for sorting and filtering raster formats.
void setOutputFormat(const QString &format)
Sets the output format.
int maxTileWidth() const
Returns the maximum tile width (in pixels) for tiled outputs.
void setCreateOptions(const QStringList &list)
Sets a list of data source creation options to use when creating the output raster file.
bool tiledMode() const
Returns whether the output will be tiled.
void setPyramidsConfigOptions(const QStringList &list)
Sets a list of configuration options to use when creating the pyramids for the output raster file.
void setBuildPyramidsFlag(Qgis::RasterBuildPyramidOption f)
Sets the pyramid building option.
Base class for processing filters like renderers, reprojector, resampler etc.
Iterator for sequentially processing raster cells.
Contains a pipeline of raster interfaces for sequential raster processing.
Definition: qgsrasterpipe.h:50
A rectangle specified with double values.
Definition: qgsrectangle.h:42
#define str(x)
Definition: qgis.cpp:38
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_FACTORY
Definition: qgis_sip.h:76
const QgsCoordinateReferenceSystem & crs
Details of available filters and formats.
QString filterString
Filter string for file picker dialogs.