QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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
22#include <QDomDocument>
23#include <QDomElement>
24#include <QString>
25#include <QStringList>
26
27using namespace Qt::StringLiterals;
28
31class QgsRasterPipe;
32class QgsRectangle;
35
43class CORE_EXPORT QgsRasterFileWriter
44{
45 public:
46
50 enum RasterFormatOption SIP_ENUM_BASETYPE( IntFlag )
51 {
52 SortRecommended = 1 << 1,
53 };
54 Q_DECLARE_FLAGS( RasterFormatOptions, RasterFormatOption )
55
56
59 QgsRasterFileWriter( const QString &outputUrl );
60
69 int width, int height,
70 const QgsRectangle &extent,
72
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
119 QString outputUrl() const { return mOutputUrl; }
120
128 void setOutputFormat( const QString &format );
129
137 QString outputFormat() const { return mOutputFormat; }
138
146 void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
147
153 QString outputProviderKey() const { return mOutputProviderKey; }
154
163 void setTiledMode( bool t ) { mTiledMode = t; }
164
170 bool tiledMode() const { return mTiledMode; }
171
179 void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
180
188 int maxTileWidth() const { return mMaxTileWidth; }
189
195 Qgis::RasterBuildPyramidOption buildPyramidsFlag() const { return mBuildPyramidsFlag; }
196
202 void setBuildPyramidsFlag( Qgis::RasterBuildPyramidOption flag );
203
209 QList< int > pyramidsList() const { return mPyramidsList; }
210
216 void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
217
218 QString pyramidsResampling() const { return mPyramidsResampling; }
219 void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
220
226 Qgis::RasterPyramidFormat pyramidsFormat() const { return mPyramidsFormat; }
227
233 void setPyramidsFormat( Qgis::RasterPyramidFormat f ) { mPyramidsFormat = f; }
234
242 void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
243
251 int maxTileHeight() const { return mMaxTileHeight; }
252
253 // TODO QGIS 5.0: rename list to options to have more semantic argument name
254
262 Q_DECL_DEPRECATED void setCreateOptions( const QStringList &list ) SIP_DEPRECATED { setCreationOptions( list ); }
263
271 Q_DECL_DEPRECATED QStringList createOptions() const SIP_DEPRECATED { return creationOptions(); }
272
280 QStringList creationOptions() const { return mCreationOptions; }
281
289 void setCreationOptions( const QStringList &options ) { mCreationOptions = options; }
290
291 // TODO QGIS 5.0: rename list to options to have more semantic argument name
292
299 void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
300
307 QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
308
310 static QString filterForDriver( const QString &driverName );
311
316 {
318 QString driverName;
319
322 };
323
333 static QList< QgsRasterFileWriter::FilterFormatDetails > supportedFiltersAndFormats( RasterFormatOptions options = SortRecommended );
334
343 static QStringList supportedFormatExtensions( RasterFormatOptions options = SortRecommended );
344
354 static QString driverForExtension( const QString &extension );
355
366 static QStringList extensionsForFormat( const QString &format );
367
368 private:
369 QgsRasterFileWriter(); //forbidden
370 Qgis::RasterFileWriterResult writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
371 const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext,
372 QgsRasterBlockFeedback *feedback = nullptr );
373
374 // Helper method used by previous one
375 Qgis::RasterFileWriterResult writeDataRaster( const QgsRasterPipe *pipe,
376 QgsRasterIterator *iter,
377 int nCols, int nRows,
378 const QgsRectangle &outputExtent,
380 Qgis::DataType destDataType,
381 const QList<bool> &destHasNoDataValueList,
382 const QList<double> &destNoDataValueList,
383 // This method can nullify the passed destProvider
384 std::unique_ptr<QgsRasterDataProvider> &destProvider,
385 QgsRasterBlockFeedback *feedback = nullptr );
386
387 Qgis::RasterFileWriterResult writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
389 QgsRasterBlockFeedback *feedback = nullptr );
390
401 void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
402 //write vrt document to disk
403 bool writeVRT( const QString &file );
404 //add file entry to vrt
405 void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
406 bool buildPyramids( const QString &filename, QgsRasterDataProvider *destProviderIn = nullptr );
407
409 QgsRasterDataProvider *createPartProvider( const QgsRectangle &extent, int nCols, int iterCols, int iterRows,
410 int iterLeft, int iterTop,
411 const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type,
412 const QgsCoordinateReferenceSystem &crs );
413
425 QgsRasterDataProvider *initOutput( int nCols, int nRows,
426 const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
427 Qgis::DataType type,
428 const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
429
431 void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
432
433 QString partFileName( int fileIndex );
434 QString vrtFileName();
435
437 QString mOutputUrl;
438 QString mOutputProviderKey = u"gdal"_s;
439 QString mOutputFormat = u"GTiff"_s;
440 QStringList mCreationOptions;
442
444 bool mTiledMode = false;
445 int mMaxTileWidth = 500;
446 int mMaxTileHeight = 500;
447
448 QList< int > mPyramidsList;
449 QString mPyramidsResampling = u"AVERAGE"_s;
450 bool mBuildPyramidsFlagSet = false;
453 QStringList mPyramidsConfigOptions;
454
455 QDomDocument mVRTDocument;
456 QList<QDomElement> mVRTBands;
457
458 QgsRasterBlockFeedback *mFeedback = nullptr;
459
460 const QgsRasterPipe *mPipe = nullptr;
461 const QgsRasterInterface *mInput = nullptr;
462};
463
464#endif // QGSRASTERFILEWRITER_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:59
RasterPyramidFormat
Raster pyramid formats.
Definition qgis.h:4874
@ GeoTiff
Geotiff .ovr (external).
Definition qgis.h:4875
RasterFileWriterResult
Raster file export results.
Definition qgis.h:1700
DataType
Raster data types.
Definition qgis.h:379
RasterBuildPyramidOption
Raster pyramid building options.
Definition qgis.h:4889
RasterExportType
Raster file export types.
Definition qgis.h:1687
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.
void setPyramidsList(const QList< int > &list)
Sets the list of pyramids which will be created for the output file.
enum RasterFormatOption SIP_ENUM_BASETYPE(IntFlag)
Options for sorting and filtering raster formats.
Q_DECL_DEPRECATED Qgis::RasterFileWriterResult writeRaster(const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback=nullptr) SIP_DEPRECATED
Write raster file.
void setPyramidsResampling(const QString &str)
int maxTileHeight() const
Returns the maximum tile height (in pixels) for tiled outputs.
static QStringList extensionsForFormat(const QString &format)
Returns a list of known file extensions for the given GDAL driver format.
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.
static QString driverForExtension(const QString &extension)
Returns the GDAL driver name for a specified file extension.
Q_DECL_DEPRECATED QStringList createOptions() const SIP_DEPRECATED
Returns the list of data source creation options which will be used when creating the output raster f...
Qgis::RasterBuildPyramidOption buildPyramidsFlag() const
Returns the pyramid building option.
QgsRasterFileWriter(const QString &outputUrl)
Constructor for QgsRasterFileWriter, writing to the specified output URL/filename.
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.
static QStringList supportedFormatExtensions(RasterFormatOptions options=SortRecommended)
Returns a list of file extensions for supported formats.
QString outputUrl() const
Returns the output URL (filename) for the raster.
QFlags< RasterFormatOption > RasterFormatOptions
Qgis::RasterPyramidFormat pyramidsFormat() const
Returns the raster pyramid format.
QString outputFormat() const
Returns the output format.
QString outputProviderKey() const
Returns the name of the data provider for the raster output.
QString pyramidsResampling() const
void setCreationOptions(const QStringList &options)
Sets a list of data source creation options to use when creating the output raster file.
QgsRasterDataProvider * createMultiBandRaster(Qgis::DataType dataType, int width, int height, const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs, int nBands) SIP_FACTORY
Create a raster file with given number of bands without initializing the pixel data.
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.
QStringList creationOptions() const
Returns the list of data source creation options which will be used when creating the output raster f...
int maxTileWidth() const
Returns the maximum tile width (in pixels) for tiled outputs.
Q_DECL_DEPRECATED void setCreateOptions(const QStringList &list) SIP_DEPRECATED
Sets a list of data source creation options to use when creating the output raster file.
static QList< QgsRasterFileWriter::FilterFormatDetails > supportedFiltersAndFormats(RasterFormatOptions options=SortRecommended)
Returns a list or pairs, with format filter string as first element and GDAL format key as second ele...
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.
QgsRasterDataProvider * createOneBandRaster(Qgis::DataType dataType, int width, int height, const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs) SIP_FACTORY
Create a raster file with one band without initializing the pixel data.
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.
A rectangle specified with double values.
#define SIP_DEPRECATED
Definition qgis_sip.h:114
#define SIP_FACTORY
Definition qgis_sip.h:84
Details of available filters and formats.
QString filterString
Filter string for file picker dialogs.