/
qgsrasterfilewriter.h
224 lines (189 loc) · 9.85 KB
/
qgsrasterfilewriter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/***************************************************************************
qgsrasterfilewriter.h
---------------------
begin : July 2012
copyright : (C) 2012 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSRASTERFILEWRITER_H
#define QGSRASTERFILEWRITER_H
#include "qgis_core.h"
#include "qgscoordinatereferencesystem.h"
#include <QDomDocument>
#include <QDomElement>
#include <QString>
#include <QStringList>
#include "qgsraster.h"
class QgsRasterBlockFeedback;
class QgsRasterIterator;
class QgsRasterPipe;
class QgsRectangle;
class QgsRasterDataProvider;
class QgsRasterInterface;
/** \ingroup core
* The raster file writer which allows you to save a raster to a new file.
*/
class CORE_EXPORT QgsRasterFileWriter
{
public:
enum Mode
{
Raw = 0, //!< Raw data
Image = 1 //!< Rendered image
};
enum WriterError
{
NoError = 0,
SourceProviderError = 1,
DestProviderError = 2,
CreateDatasourceError = 3,
WriteError = 4,
NoDataConflict = 5, //!< Internal error if a value used for 'no data' was found in input
WriteCanceled = 6, //!< Writing was manually canceled
};
QgsRasterFileWriter( const QString &outputUrl );
/** Create a raster file with one band without initializing the pixel data.
* Returned provider may be used to initialize the raster using writeBlock() calls.
* Ownership of the returned provider is passed to the caller.
* \note Does not work with tiled mode enabled.
* \returns Instance of data provider in editing mode (on success) or nullptr on error.
* \since QGIS 3.0
*/
QgsRasterDataProvider *createOneBandRaster( Qgis::DataType dataType,
int width, int height,
const QgsRectangle &extent,
const QgsCoordinateReferenceSystem &crs ) SIP_FACTORY;
/** Create a raster file with given number of bands without initializing the pixel data.
* Returned provider may be used to initialize the raster using writeBlock() calls.
* Ownership of the returned provider is passed to the caller.
* \note Does not work with tiled mode enabled.
* \returns Instance of data provider in editing mode (on success) or nullptr on error.
* \since QGIS 3.0
*/
QgsRasterDataProvider *createMultiBandRaster( Qgis::DataType dataType,
int width, int height,
const QgsRectangle &extent,
const QgsCoordinateReferenceSystem &crs,
int nBands ) SIP_FACTORY;
/** Write raster file
\param pipe raster pipe
\param nCols number of output columns
\param nRows number of output rows (or -1 to automatically calculate row number to have square pixels)
\param outputExtent extent to output
\param crs crs to reproject to
\param feedback optional feedback object for progress reports
*/
WriterError writeRaster( const QgsRasterPipe *pipe, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
/**
* Returns the output URL for the raster.
* \since QGIS 3.0
*/
QString outputUrl() const { return mOutputUrl; }
void setOutputFormat( const QString &format ) { mOutputFormat = format; }
QString outputFormat() const { return mOutputFormat; }
void setOutputProviderKey( const QString &key ) { mOutputProviderKey = key; }
QString outputProviderKey() const { return mOutputProviderKey; }
void setTiledMode( bool t ) { mTiledMode = t; }
bool tiledMode() const { return mTiledMode; }
void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
int maxTileWidth() const { return mMaxTileWidth; }
QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
QList< int > pyramidsList() const { return mPyramidsList; }
void setPyramidsList( const QList< int > &list ) { mPyramidsList = list; }
QString pyramidsResampling() const { return mPyramidsResampling; }
void setPyramidsResampling( const QString &str ) { mPyramidsResampling = str; }
QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
int maxTileHeight() const { return mMaxTileHeight; }
void setCreateOptions( const QStringList &list ) { mCreateOptions = list; }
QStringList createOptions() const { return mCreateOptions; }
void setPyramidsConfigOptions( const QStringList &list ) { mPyramidsConfigOptions = list; }
QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
private:
QgsRasterFileWriter(); //forbidden
WriterError writeDataRaster( const QgsRasterPipe *pipe, QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs, QgsRasterBlockFeedback *feedback = nullptr );
// Helper method used by previous one
WriterError writeDataRaster( const QgsRasterPipe *pipe,
QgsRasterIterator *iter,
int nCols, int nRows,
const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs,
Qgis::DataType destDataType,
const QList<bool> &destHasNoDataValueList,
const QList<double> &destNoDataValueList,
QgsRasterDataProvider *destProvider,
QgsRasterBlockFeedback *feedback = nullptr );
WriterError writeImageRaster( QgsRasterIterator *iter, int nCols, int nRows, const QgsRectangle &outputExtent,
const QgsCoordinateReferenceSystem &crs,
QgsRasterBlockFeedback *feedback = nullptr );
/** \brief Initialize vrt member variables
* \param xSize width of vrt
* \param ySize height of vrt
* \param crs coordinate system of vrt
* \param geoTransform optional array of transformation matrix values
* \param type datatype of vrt
* \param destHasNoDataValueList true if destination has no data value, indexed from 0
* \param destNoDataValueList no data value, indexed from 0
*/
void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem &crs, double *geoTransform, Qgis::DataType type, const QList<bool> &destHasNoDataValueList, const QList<double> &destNoDataValueList );
//write vrt document to disk
bool writeVRT( const QString &file );
//add file entry to vrt
void addToVRT( const QString &filename, int band, int xSize, int ySize, int xOffset, int yOffset );
void buildPyramids( const QString &filename );
//! Create provider and datasource for a part image (vrt mode)
QgsRasterDataProvider *createPartProvider( 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 );
/** \brief Init VRT (for tiled mode) or create global output provider (single-file mode)
* \param nCols number of tile columns
* \param nRows number of tile rows
* \param crs coordinate system of vrt
* \param geoTransform optional array of transformation matrix values
* \param nBands number of bands
* \param type datatype of vrt
* \param destHasNoDataValueList true if destination has no data value, indexed from 0
* \param destNoDataValueList no data value, indexed from 0
*/
QgsRasterDataProvider *initOutput( int nCols, int nRows,
const QgsCoordinateReferenceSystem &crs, double *geoTransform, int nBands,
Qgis::DataType type,
const QList<bool> &destHasNoDataValueList = QList<bool>(), const QList<double> &destNoDataValueList = QList<double>() );
//! Calculate nRows, geotransform and pixel size for output
void globalOutputParameters( const QgsRectangle &extent, int nCols, int &nRows, double *geoTransform, double &pixelSize );
QString partFileName( int fileIndex );
QString vrtFileName();
Mode mMode;
QString mOutputUrl;
QString mOutputProviderKey;
QString mOutputFormat;
QStringList mCreateOptions;
QgsCoordinateReferenceSystem mOutputCRS;
//! False: Write one file, true: create a directory and add the files numbered
bool mTiledMode;
double mMaxTileWidth;
double mMaxTileHeight;
QList< int > mPyramidsList;
QString mPyramidsResampling;
QgsRaster::RasterBuildPyramids mBuildPyramidsFlag;
QgsRaster::RasterPyramidsFormat mPyramidsFormat;
QStringList mPyramidsConfigOptions;
QDomDocument mVRTDocument;
QList<QDomElement> mVRTBands;
QgsRasterBlockFeedback *mFeedback = nullptr;
const QgsRasterPipe *mPipe = nullptr;
const QgsRasterInterface *mInput = nullptr;
};
#endif // QGSRASTERFILEWRITER_H