QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsrasterdataprovider.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterdataprovider.h - DataProvider Interface for raster layers
3  --------------------------------------
4  Date : Mar 11, 2005
5  Copyright : (C) 2005 by Brendan Morley
6  email : morb at ozemail dot com dot au
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 /* Thank you to Marco Hugentobler for the original vector DataProvider */
19 
20 #ifndef QGSRASTERDATAPROVIDER_H
21 #define QGSRASTERDATAPROVIDER_H
22 
23 #include <cmath>
24 
25 #include <QDateTime>
26 #include <QVariant>
27 
28 #include "qgscolorrampshader.h"
30 #include "qgsdataprovider.h"
31 #include "qgserror.h"
32 #include "qgsfeature.h"
33 #include "qgsfield.h"
34 #include "qgslogger.h"
35 #include "qgsrasterbandstats.h"
36 #include "qgsraster.h"
37 #include "qgsrasterhistogram.h"
38 #include "qgsrasterinterface.h"
39 #include "qgsrasterpyramid.h"
40 #include "qgsrasterrange.h"
41 #include "qgsrectangle.h"
42 
43 class QImage;
44 class QByteArray;
45 
46 class QgsPoint;
48 
52 class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRasterInterface
53 {
54  Q_OBJECT
55 
56  public:
58 
59  QgsRasterDataProvider( const QString & uri );
60 
61  virtual ~QgsRasterDataProvider() {};
62 
63  virtual QgsRasterInterface * clone() const = 0;
64 
65  /* It makes no sense to set input on provider */
66  bool setInput( QgsRasterInterface* input ) { Q_UNUSED( input ); return false; }
67 
69  virtual QImage* draw( const QgsRectangle & viewExtent, int pixelWidth, int pixelHeight ) = 0;
70 
73  virtual QgsRectangle extent() = 0;
74 
76  virtual QGis::DataType dataType( int bandNo ) const = 0;
77 
80  virtual QGis::DataType srcDataType( int bandNo ) const = 0;
81 
83  virtual int colorInterpretation( int theBandNo ) const
84  {
85  Q_UNUSED( theBandNo );
87  }
88 
89  QString colorName( int colorInterpretation ) const
90  {
91  // Modified copy from GDAL
92  switch ( colorInterpretation )
93  {
95  return "Undefined";
96 
98  return "Gray";
99 
101  return "Palette";
102 
103  case QgsRaster::RedBand:
104  return "Red";
105 
107  return "Green";
108 
109  case QgsRaster::BlueBand:
110  return "Blue";
111 
113  return "Alpha";
114 
115  case QgsRaster::HueBand:
116  return "Hue";
117 
119  return "Saturation";
120 
122  return "Lightness";
123 
124  case QgsRaster::CyanBand:
125  return "Cyan";
126 
128  return "Magenta";
129 
131  return "Yellow";
132 
134  return "Black";
135 
137  return "YCbCr_Y";
138 
140  return "YCbCr_Cb";
141 
143  return "YCbCr_Cr";
144 
145  default:
146  return "Unknown";
147  }
148  }
150  virtual bool reload() { return true; }
151 
152  virtual QString colorInterpretationName( int theBandNo ) const
153  {
154  return colorName( colorInterpretation( theBandNo ) );
155  }
156 
157  // TODO: remove or make protected all readBlock working with void*
158 
160  virtual QgsRasterBlock *block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight );
161 
162  /* Return true if source band has no data value */
163  virtual bool srcHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo -1 ); }
164 
166  virtual bool useSrcNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo -1 ); }
167 
169  virtual void setUseSrcNoDataValue( int bandNo, bool use );
170 
172  virtual double srcNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo -1 ); }
173 
174  virtual void setUserNoDataValue( int bandNo, QgsRasterRangeList noData );
175 
177  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
178 
179  virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
180  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
181 
184  virtual QStringList subLayers() const
185  {
186  return QStringList();
187  }
188 
190  virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
191  const QString & theResamplingMethod = "NEAREST",
193  const QStringList & theConfigOptions = QStringList() )
194  {
195  Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod );
196  Q_UNUSED( theFormat ); Q_UNUSED( theConfigOptions );
197  return "FAILED_NOT_SUPPORTED";
198  };
199 
207  virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() )
208  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); };
209 
211  bool hasPyramids();
212 
217  virtual QString metadata() = 0;
218 
241  //virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
242  virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
243 
253  virtual QString lastErrorTitle() = 0;
254 
264  virtual QString lastError() = 0;
265 
271  virtual QString lastErrorFormat();
272 
275  int dpi() const {return mDpi;}
276 
279  void setDpi( int dpi ) {mDpi = dpi;}
280 
282  virtual QDateTime timestamp() const { return mTimestamp; }
283 
285  virtual QDateTime dataTimestamp() const { return QDateTime(); }
286 
288  // TODO: add data type (may be defferent from band type)
289  virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
290  {
291  Q_UNUSED( data );
292  Q_UNUSED( band );
293  Q_UNUSED( width );
294  Q_UNUSED( height );
295  Q_UNUSED( xOffset );
296  Q_UNUSED( yOffset );
297  return false;
298  }
299 
301  static QgsRasterDataProvider* create( const QString &providerKey,
302  const QString &uri,
303  const QString& format, int nBands,
304  QGis::DataType type,
305  int width, int height, double* geoTransform,
306  const QgsCoordinateReferenceSystem& crs,
307  QStringList createOptions = QStringList() );
308 
313  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
314 
316  // TODO: this should be static and call C functions in provider library
317  //static QStringList createFormats();
318 
320  virtual bool remove() { return false; }
321 
324  static QList<QPair<QString, QString> > pyramidResamplingMethods( QString providerKey );
325 
329  virtual QString validateCreationOptions( const QStringList& createOptions, QString format )
330  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
331 
334  virtual QString validatePyramidsConfigOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
335  const QStringList & theConfigOptions, const QString & fileFormat )
336  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
337 
338  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
339  static QgsRaster::IdentifyFormat identifyFormatFromName( QString formatName );
340  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
341  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
342 
343  signals:
346  void progress( int theType, double theProgress, QString theMessage );
347  void progressUpdate( int theProgress );
348 
349  protected:
352  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
353  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
354 
357  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data )
358  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
359 
361  bool userNoDataValuesContains( int bandNo, double value ) const;
362 
363  static QStringList cStringList2Q_( char ** stringList );
364 
365  static QString makeTableCell( const QString & value );
366  static QString makeTableCells( const QStringList & values );
367 
371  int mDpi;
372 
375  //bool hasNoDataValue ( int theBandNo );
376 
378  QList<double> mSrcNoDataValue;
379 
381  QList<bool> mSrcHasNoDataValue;
382 
386  QList<bool> mUseSrcNoDataValue;
387 
390  QList< QgsRasterRangeList > mUserNoDataValue;
391 
393 
394  static void initPyramidResamplingDefs();
395  static QStringList mPyramidResamplingListGdal;
397 
398 };
399 #endif