QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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:
49 enum RasterFormatOption SIP_ENUM_BASETYPE( IntFlag )
50 {
51 SortRecommended = 1 << 1,
52 };
53 Q_DECLARE_FLAGS( RasterFormatOptions, RasterFormatOption )
54
55
58 QgsRasterFileWriter( const QString &outputUrl );
59
67 QgsRasterDataProvider *createOneBandRaster( Qgis::DataType dataType, int width, int height, const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs ) SIP_FACTORY;
68
76 QgsRasterDataProvider *createMultiBandRaster( Qgis::DataType dataType, int width, int height, const QgsRectangle &extent, const QgsCoordinateReferenceSystem &crs, int nBands ) SIP_FACTORY;
77
78
90 const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr
92
104 Qgis::RasterFileWriterResult writeRaster(
105 const QgsRasterPipe *pipe,
106 int nCols,
107 int nRows,
108 const QgsRectangle &outputExtent,
110 const QgsCoordinateTransformContext &transformContext,
111 QgsRasterBlockFeedback *feedback = nullptr
112 );
113
117 QString outputUrl() const { return mOutputUrl; }
118
126 void setOutputFormat( const QString &format );
127
135 QString outputFormat() const { return mOutputFormat; }
136
144 void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
145
151 QString outputProviderKey() const { return mOutputProviderKey; }
152
161 void setTiledMode( bool t ) { mTiledMode = t; }
162
168 bool tiledMode() const { return mTiledMode; }
169
177 void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
178
186 int maxTileWidth() const { return mMaxTileWidth; }
187
193 Qgis::RasterBuildPyramidOption buildPyramidsFlag() const { return mBuildPyramidsFlag; }
194
200 void setBuildPyramidsFlag( Qgis::RasterBuildPyramidOption flag );
201
207 QList< int > pyramidsList() const { return mPyramidsList; }
208
214 void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
215
216 QString pyramidsResampling() const { return mPyramidsResampling; }
217 void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
218
224 Qgis::RasterPyramidFormat pyramidsFormat() const { return mPyramidsFormat; }
225
231 void setPyramidsFormat( Qgis::RasterPyramidFormat f ) { mPyramidsFormat = f; }
232
240 void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
241
249 int maxTileHeight() const { return mMaxTileHeight; }
250
251 // TODO QGIS 5.0: rename list to options to have more semantic argument name
252
260 Q_DECL_DEPRECATED void setCreateOptions( const QStringList &list ) SIP_DEPRECATED { setCreationOptions( list ); }
261
269 Q_DECL_DEPRECATED QStringList createOptions() const SIP_DEPRECATED { return creationOptions(); }
270
278 QStringList creationOptions() const { return mCreationOptions; }
279
287 void setCreationOptions( const QStringList &options ) { mCreationOptions = options; }
288
289 // TODO QGIS 5.0: rename list to options to have more semantic argument name
290
297 void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
298
305 QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
306
308 static QString filterForDriver( const QString &driverName );
309
314 {
316 QString driverName;
317
320 };
321
331 static QList< QgsRasterFileWriter::FilterFormatDetails > supportedFiltersAndFormats( RasterFormatOptions options = SortRecommended );
332
341 static QStringList supportedFormatExtensions( RasterFormatOptions options = SortRecommended );
342
352 static QString driverForExtension( const QString &extension );
353
364 static QStringList extensionsForFormat( const QString &format );
365
366 private:
367 QgsRasterFileWriter(); //forbidden
368 Qgis::RasterFileWriterResult writeDataRaster(
369 const QgsRasterPipe *pipe,
370 QgsRasterIterator *iter,
371 int nCols,
372 int nRows,
373 const QgsRectangle &outputExtent,
375 const QgsCoordinateTransformContext &transformContext,
376 QgsRasterBlockFeedback *feedback = nullptr
377 );
378
379 // Helper method used by previous one
380 Qgis::RasterFileWriterResult writeDataRaster(
381 const QgsRasterPipe *pipe,
382 QgsRasterIterator *iter,
383 int nCols,
384 int nRows,
385 const QgsRectangle &outputExtent,
387 Qgis::DataType destDataType,
388 const QList<bool> &destHasNoDataValueList,
389 const QList<double> &destNoDataValueList,
390 // This method can nullify the passed destProvider
391 std::unique_ptr<QgsRasterDataProvider> &destProvider,
392 QgsRasterBlockFeedback *feedback = nullptr
393 );
394
395 Qgis::RasterFileWriterResult writeImageRaster(
396 QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent, const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr
397 );
398
409 void createVRT(
410 int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList
411 );
412 //write vrt document to disk
413 bool writeVRT( const QString &file );
414 //add file entry to vrt
415 void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
416 bool buildPyramids( const QString &filename, QgsRasterDataProvider *destProviderIn = nullptr );
417
419 QgsRasterDataProvider *createPartProvider(
420 const QgsRectangle &extent, int nCols, int iterCols, int iterRows, int iterLeft, int iterTop, const QString &outputUrl, int fileIndex, int nBands, Qgis::DataType type, const QgsCoordinateReferenceSystem &crs
421 );
422
434 QgsRasterDataProvider *initOutput(
435 int nCols,
436 int nRows,
438 double *geoTransform,
439 int nBands,
440 Qgis::DataType type,
441 const QList<bool> &destHasNoDataValueList = QList<bool>(),
442 const QList<double> &destNoDataValueList = QList<double>()
443 );
444
446 void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
447
448 QString partFileName( int fileIndex );
449 QString vrtFileName();
450
452 QString mOutputUrl;
453 QString mOutputProviderKey = u"gdal"_s;
454 QString mOutputFormat = u"GTiff"_s;
455 QStringList mCreationOptions;
457
459 bool mTiledMode = false;
460 int mMaxTileWidth = 500;
461 int mMaxTileHeight = 500;
462
463 QList< int > mPyramidsList;
464 QString mPyramidsResampling = u"AVERAGE"_s;
465 bool mBuildPyramidsFlagSet = false;
468 QStringList mPyramidsConfigOptions;
469
470 QDomDocument mVRTDocument;
471 QList<QDomElement> mVRTBands;
472
473 QgsRasterBlockFeedback *mFeedback = nullptr;
474
475 const QgsRasterPipe *mPipe = nullptr;
476 const QgsRasterInterface *mInput = nullptr;
477};
478
479#endif // QGSRASTERFILEWRITER_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
RasterPyramidFormat
Raster pyramid formats.
Definition qgis.h:4959
@ GeoTiff
Geotiff .ovr (external).
Definition qgis.h:4960
RasterFileWriterResult
Raster file export results.
Definition qgis.h:1721
DataType
Raster data types.
Definition qgis.h:393
RasterBuildPyramidOption
Raster pyramid building options.
Definition qgis.h:4974
RasterExportType
Raster file export types.
Definition qgis.h:1708
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:113
#define SIP_FACTORY
Definition qgis_sip.h:83
Details of available filters and formats.
QString filterString
Filter string for file picker dialogs.