QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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
30class QgsRasterPipe;
31class QgsRectangle;
34
39class 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
151 Qgis::RasterBuildPyramidOption buildPyramidsFlag() const { return mBuildPyramidsFlag; }
152
158 void setBuildPyramidsFlag( Qgis::RasterBuildPyramidOption f ) { mBuildPyramidsFlag = f; }
159
160 QList< int > pyramidsList() const { return mPyramidsList; }
161 void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
162
163 QString pyramidsResampling() const { return mPyramidsResampling; }
164 void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
165
171 Qgis::RasterPyramidFormat pyramidsFormat() const { return mPyramidsFormat; }
172
178 void setPyramidsFormat( Qgis::RasterPyramidFormat f ) { mPyramidsFormat = f; }
179
180 void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
181 int maxTileHeight() const { return mMaxTileHeight; }
182
183 void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
184 QStringList createOptions() const { return mCreateOptions; }
185
186 void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
187 QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
188
190 static QString filterForDriver( const QString &driverName );
191
197 {
199 QString driverName;
200
203 };
204
214 static QList< QgsRasterFileWriter::FilterFormatDetails > supportedFiltersAndFormats( RasterFormatOptions options = SortRecommended );
215
225 static QStringList supportedFormatExtensions( RasterFormatOptions options = SortRecommended );
226
237 static QString driverForExtension( const QString &extension );
238
250 static QStringList extensionsForFormat( const QString &format );
251
252 private:
253 QgsRasterFileWriter(); //forbidden
254 WriterError writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
255 const QgsCoordinateReferenceSystem &crs, const QgsCoordinateTransformContext &transformContext,
256 QgsRasterBlockFeedback *feedback = nullptr );
257
258 // Helper method used by previous one
259 WriterError writeDataRaster( const QgsRasterPipe *pipe,
260 QgsRasterIterator *iter,
261 int nCols, int nRows,
262 const QgsRectangle &outputExtent,
264 Qgis::DataType destDataType,
265 const QList<bool> &destHasNoDataValueList,
266 const QList<double> &destNoDataValueList,
267 QgsRasterDataProvider *destProvider,
268 QgsRasterBlockFeedback *feedback = nullptr );
269
270 WriterError writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
272 QgsRasterBlockFeedback *feedback = nullptr );
273
284 void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
285 //write vrt document to disk
286 bool writeVRT( const QString &file );
287 //add file entry to vrt
288 void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
289 void buildPyramids( const QString &filename, QgsRasterDataProvider *destProviderIn = nullptr );
290
292 QgsRasterDataProvider *createPartProvider( const QgsRectangle &extent, int nCols, int iterCols, int iterRows,
293 int iterLeft, int iterTop,
294 const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type,
296
308 QgsRasterDataProvider *initOutput( int nCols, int nRows,
309 const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
310 Qgis::DataType type,
311 const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
312
314 void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
315
316 QString partFileName( int fileIndex );
317 QString vrtFileName();
318
319 Mode mMode = Raw;
320 QString mOutputUrl;
321 QString mOutputProviderKey = QStringLiteral( "gdal" );
322 QString mOutputFormat = QStringLiteral( "GTiff" );
323 QStringList mCreateOptions;
325
327 bool mTiledMode = false;
328 int mMaxTileWidth = 500;
329 int mMaxTileHeight = 500;
330
331 QList< int > mPyramidsList;
332 QString mPyramidsResampling = QStringLiteral( "AVERAGE" );
333 Qgis::RasterBuildPyramidOption mBuildPyramidsFlag = Qgis::RasterBuildPyramidOption::No;
334 Qgis::RasterPyramidFormat mPyramidsFormat = Qgis::RasterPyramidFormat::GeoTiff;
335 QStringList mPyramidsConfigOptions;
336
337 QDomDocument mVRTDocument;
338 QList<QDomElement> mVRTBands;
339
340 QgsRasterBlockFeedback *mFeedback = nullptr;
341
342 const QgsRasterPipe *mPipe = nullptr;
343 const QgsRasterInterface *mInput = nullptr;
344};
345
346#endif // QGSRASTERFILEWRITER_H
RasterPyramidFormat
Raster pyramid formats.
Definition: qgis.h:2918
DataType
Raster data types.
Definition: qgis.h:242
RasterBuildPyramidOption
Raster pyramid building options.
Definition: qgis.h:2933
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)
void setPyramidsResampling(const QString &str)
QStringList pyramidsConfigOptions() const
Qgis::RasterBuildPyramidOption buildPyramidsFlag() const
Returns the pyramid building option.
void setOutputProviderKey(const QString &key)
Qgis::RasterPyramidFormat pyramidsFormat() const
Returns the raster pyramid format.
QString outputFormat() const
QStringList createOptions() const
QString outputProviderKey() const
QString pyramidsResampling() const
QList< int > pyramidsList() const
void setPyramidsFormat(Qgis::RasterPyramidFormat f)
Sets the raster pyramid format.
RasterFormatOption
Options for sorting and filtering raster formats.
void setOutputFormat(const QString &format)
void setCreateOptions(const QStringList &list)
void setPyramidsConfigOptions(const QStringList &list)
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:37
#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.