QGIS API Documentation  2.15.0-Master (02a0ebe)
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 
19 #include "qgsrasterdataprovider.h"
20 #include "qgsrasterpipe.h"
21 #include "qgsrectangle.h"
22 #include <QDomDocument>
23 #include <QDomElement>
24 #include <QString>
25 
26 class QProgressDialog;
27 class QgsRasterIterator;
28 
32 class CORE_EXPORT QgsRasterFileWriter
33 {
34  public:
35  enum Mode
36  {
37  Raw = 0, // Raw data
38  Image = 1 // Rendered image
39  };
41  {
42  NoError = 0,
43  SourceProviderError = 1,
44  DestProviderError = 2,
45  CreateDatasourceError = 3,
46  WriteError = 4,
47  // Internal error if a value used for 'no data' was found in input
48  NoDataConflict = 5
49  };
50 
51  QgsRasterFileWriter( const QString& outputUrl );
52 
60  WriterError writeRaster( const QgsRasterPipe* pipe, int nCols, int nRows, QgsRectangle outputExtent,
61  const QgsCoordinateReferenceSystem& crs, QProgressDialog* p = nullptr );
62 
63  void setOutputFormat( const QString& format ) { mOutputFormat = format; }
64  QString outputFormat() const { return mOutputFormat; }
65 
66  void setOutputProviderKey( const QString& key ) { mOutputProviderKey = key; }
67  QString outputProviderKey() const { return mOutputProviderKey; }
68 
69  void setTiledMode( bool t ) { mTiledMode = t; }
70  bool tiledMode() const { return mTiledMode; }
71 
72  void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
73  int maxTileWidth() const { return mMaxTileWidth; }
74 
75  QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
76  void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
77 
78  QList< int > pyramidsList() const { return mPyramidsList; }
79  void setPyramidsList( const QList< int > & list ) { mPyramidsList = list; }
80 
81  QString pyramidsResampling() const { return mPyramidsResampling; }
82  void setPyramidsResampling( const QString & str ) { mPyramidsResampling = str; }
83 
84  QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
85  void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
86 
87  void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
88  int maxTileHeight() const { return mMaxTileHeight; }
89 
90  void setCreateOptions( const QStringList& list ) { mCreateOptions = list; }
91  QStringList createOptions() const { return mCreateOptions; }
92 
93  void setPyramidsConfigOptions( const QStringList& list ) { mPyramidsConfigOptions = list; }
94  QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
95 
96  private:
97  QgsRasterFileWriter(); //forbidden
98  WriterError writeDataRaster( const QgsRasterPipe* pipe, QgsRasterIterator* iter, int nCols, int nRows, const QgsRectangle& outputExtent,
99  const QgsCoordinateReferenceSystem& crs, QProgressDialog* progressDialog = nullptr );
100 
101  // Helper method used by previous one
102  WriterError writeDataRaster( const QgsRasterPipe* pipe,
103  QgsRasterIterator* iter,
104  int nCols, int nRows,
105  const QgsRectangle& outputExtent,
106  const QgsCoordinateReferenceSystem& crs,
107  QGis::DataType destDataType,
108  const QList<bool>& destHasNoDataValueList,
109  const QList<double>& destNoDataValueList,
110  QgsRasterDataProvider* destProvider,
111  QProgressDialog* progressDialog );
112 
113  WriterError writeImageRaster( QgsRasterIterator* iter, int nCols, int nRows, const QgsRectangle& outputExtent,
114  const QgsCoordinateReferenceSystem& crs, QProgressDialog* progressDialog = nullptr );
115 
125  void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem& crs, double* geoTransform, QGis::DataType type, const QList<bool>& destHasNoDataValueList, const QList<double>& destNoDataValueList );
126  //write vrt document to disk
127  bool writeVRT( const QString& file );
128  //add file entry to vrt
129  void addToVRT( const QString& filename, int band, int xSize, int ySize, int xOffset, int yOffset );
130  void buildPyramids( const QString& filename );
131 
133  QgsRasterDataProvider* createPartProvider( const QgsRectangle& extent, int nCols, int iterCols, int iterRows,
134  int iterLeft, int iterTop,
135  const QString& outputUrl, int fileIndex, int nBands, QGis::DataType type,
136  const QgsCoordinateReferenceSystem& crs );
137 
148  QgsRasterDataProvider* initOutput( int nCols, int nRows,
149  const QgsCoordinateReferenceSystem& crs, double* geoTransform, int nBands,
150  QGis::DataType type,
151  const QList<bool>& destHasNoDataValueList = QList<bool>(), const QList<double>& destNoDataValueList = QList<double>() );
152 
154  void globalOutputParameters( const QgsRectangle& extent, int nCols, int& nRows, double* geoTransform, double& pixelSize );
155 
156  QString partFileName( int fileIndex );
157  QString vrtFileName();
158 
159  Mode mMode;
160  QString mOutputUrl;
161  QString mOutputProviderKey;
162  QString mOutputFormat;
163  QStringList mCreateOptions;
164  QgsCoordinateReferenceSystem mOutputCRS;
165 
167  bool mTiledMode;
168  double mMaxTileWidth;
169  double mMaxTileHeight;
170 
171  QList< int > mPyramidsList;
172  QString mPyramidsResampling;
173  QgsRaster::RasterBuildPyramids mBuildPyramidsFlag;
174  QgsRaster::RasterPyramidsFormat mPyramidsFormat;
175  QStringList mPyramidsConfigOptions;
176 
177  QDomDocument mVRTDocument;
178  QList<QDomElement> mVRTBands;
179 
180  QProgressDialog* mProgressDialog;
181 
182  const QgsRasterPipe* mPipe;
183  const QgsRasterInterface* mInput;
184 };
185 
186 #endif // QGSRASTERFILEWRITER_H
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Base class for processing modules.
Definition: qgsrasterpipe.h:41
Iterator for sequentially processing raster cells.
QgsRaster::RasterPyramidsFormat pyramidsFormat() const
void setCreateOptions(const QStringList &list)
void setOutputFormat(const QString &format)
QStringList pyramidsConfigOptions() const
QList< int > pyramidsList() const
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const
QString pyramidsResampling() const
QStringList createOptions() const
void setOutputProviderKey(const QString &key)
Base class for processing filters like renderers, reprojector, resampler etc.
void setPyramidsConfigOptions(const QStringList &list)
QString outputFormat() const
QString outputProviderKey() const
void setPyramidsFormat(QgsRaster::RasterPyramidsFormat f)
Class for storing a coordinate reference system (CRS)
DataType
Raster data types.
Definition: qgis.h:133
void setPyramidsList(const QList< int > &list)
RasterBuildPyramids
Definition: qgsraster.h:71
void setPyramidsResampling(const QString &str)
RasterPyramidsFormat
Definition: qgsraster.h:78
Base class for raster data providers.
The raster file writer which allows you to save a raster to a new file.
void setBuildPyramidsFlag(QgsRaster::RasterBuildPyramids f)