QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 );
53 
61  WriterError writeRaster( const QgsRasterPipe* pipe, int nCols, int nRows, QgsRectangle outputExtent,
62  const QgsCoordinateReferenceSystem& crs, QProgressDialog* p = 0 );
63 
64  void setOutputFormat( const QString& format ) { mOutputFormat = format; }
65  QString outputFormat() const { return mOutputFormat; }
66 
67  void setOutputProviderKey( const QString& key ) { mOutputProviderKey = key; }
68  QString outputProviderKey() const { return mOutputProviderKey; }
69 
70  void setTiledMode( bool t ) { mTiledMode = t; }
71  bool tiledMode() const { return mTiledMode; }
72 
73  void setMaxTileWidth( int w ) { mMaxTileWidth = w; }
74  int maxTileWidth() const { return mMaxTileWidth; }
75 
76  QgsRaster::RasterBuildPyramids buildPyramidsFlag() const { return mBuildPyramidsFlag; }
77  void setBuildPyramidsFlag( QgsRaster::RasterBuildPyramids f ) { mBuildPyramidsFlag = f; }
78 
79  QList< int > pyramidsList() const { return mPyramidsList; }
80  void setPyramidsList( const QList< int > & list ) { mPyramidsList = list; }
81 
82  QString pyramidsResampling() const { return mPyramidsResampling; }
83  void setPyramidsResampling( const QString & str ) { mPyramidsResampling = str; }
84 
85  QgsRaster::RasterPyramidsFormat pyramidsFormat() const { return mPyramidsFormat; }
86  void setPyramidsFormat( QgsRaster::RasterPyramidsFormat f ) { mPyramidsFormat = f; }
87 
88  void setMaxTileHeight( int h ) { mMaxTileHeight = h; }
89  int maxTileHeight() const { return mMaxTileHeight; }
90 
91  void setCreateOptions( const QStringList& list ) { mCreateOptions = list; }
92  QStringList createOptions() const { return mCreateOptions; }
93 
94  void setPyramidsConfigOptions( const QStringList& list ) { mPyramidsConfigOptions = list; }
95  QStringList pyramidsConfigOptions() const { return mPyramidsConfigOptions; }
96 
97  private:
98  QgsRasterFileWriter(); //forbidden
99  WriterError writeDataRaster( const QgsRasterPipe* pipe, QgsRasterIterator* iter, int nCols, int nRows, const QgsRectangle& outputExtent,
100  const QgsCoordinateReferenceSystem& crs, QProgressDialog* progressDialog = 0 );
101 
102  // Helper method used by previous one
103  WriterError writeDataRaster( const QgsRasterPipe* pipe,
104  QgsRasterIterator* iter,
105  int nCols, int nRows,
106  const QgsRectangle& outputExtent,
107  const QgsCoordinateReferenceSystem& crs,
108  QGis::DataType destDataType,
109  QList<bool> destHasNoDataValueList,
110  QList<double> destNoDataValueList,
111  QgsRasterDataProvider* destProvider,
112  QProgressDialog* progressDialog );
113 
114  WriterError writeImageRaster( QgsRasterIterator* iter, int nCols, int nRows, const QgsRectangle& outputExtent,
115  const QgsCoordinateReferenceSystem& crs, QProgressDialog* progressDialog = 0 );
116 
126  void createVRT( int xSize, int ySize, const QgsCoordinateReferenceSystem& crs, double* geoTransform, QGis::DataType type, QList<bool> destHasNoDataValueList, QList<double> destNoDataValueList );
127  //write vrt document to disk
128  bool writeVRT( const QString& file );
129  //add file entry to vrt
130  void addToVRT( const QString& filename, int band, int xSize, int ySize, int xOffset, int yOffset );
131  void buildPyramids( const QString& filename );
132 
134  QgsRasterDataProvider* createPartProvider( const QgsRectangle& extent, int nCols, int iterCols, int iterRows,
135  int iterLeft, int iterTop,
136  const QString& outputUrl, int fileIndex, int nBands, QGis::DataType type,
137  const QgsCoordinateReferenceSystem& crs );
138 
149  QgsRasterDataProvider* initOutput( int nCols, int nRows,
150  const QgsCoordinateReferenceSystem& crs, double* geoTransform, int nBands,
151  QGis::DataType type,
152  QList<bool> destHasNoDataValueList = QList<bool>(), QList<double> destNoDataValueList = QList<double>() );
153 
155  void globalOutputParameters( const QgsRectangle& extent, int nCols, int& nRows, double* geoTransform, double& pixelSize );
156 
157  QString partFileName( int fileIndex );
158  QString vrtFileName();
159 
161  QString mOutputUrl;
163  QString mOutputFormat;
164  QStringList mCreateOptions;
166 
171 
172  QList< int > mPyramidsList;
177 
178  QDomDocument mVRTDocument;
179  QList<QDomElement> mVRTBands;
180 
181  QProgressDialog* mProgressDialog;
182 
185 };
186 
187 #endif // QGSRASTERFILEWRITER_H