QGIS API Documentation  2.2.0-Valmiera
 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 #include <QImage>
28 
29 #include "qgscolorrampshader.h"
31 #include "qgsdataprovider.h"
32 #include "qgserror.h"
33 #include "qgsfeature.h"
34 #include "qgsfield.h"
35 #include "qgslogger.h"
36 #include "qgsrasterbandstats.h"
37 #include "qgsraster.h"
38 #include "qgsrasterhistogram.h"
39 #include "qgsrasterinterface.h"
40 #include "qgsrasterpyramid.h"
41 #include "qgsrasterrange.h"
42 #include "qgsrectangle.h"
43 
44 class QImage;
45 class QByteArray;
46 
47 class QgsPoint;
49 
53 class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRasterInterface
54 {
55  Q_OBJECT
56 
57  public:
59 
60  QgsRasterDataProvider( const QString & uri );
61 
62  virtual ~QgsRasterDataProvider() {};
63 
64  virtual QgsRasterInterface * clone() const = 0;
65 
66  /* It makes no sense to set input on provider */
67  bool setInput( QgsRasterInterface* input ) { Q_UNUSED( input ); return false; }
68 
76  virtual QImage* draw( const QgsRectangle & viewExtent, int pixelWidth, int pixelHeight ) = 0;
77 
80  virtual QgsRectangle extent() = 0;
81 
83  virtual QGis::DataType dataType( int bandNo ) const = 0;
84 
87  virtual QGis::DataType srcDataType( int bandNo ) const = 0;
88 
90  virtual int colorInterpretation( int theBandNo ) const
91  {
92  Q_UNUSED( theBandNo );
94  }
95 
96  QString colorName( int colorInterpretation ) const
97  {
98  // Modified copy from GDAL
99  switch ( colorInterpretation )
100  {
102  return "Undefined";
103 
105  return "Gray";
106 
108  return "Palette";
109 
110  case QgsRaster::RedBand:
111  return "Red";
112 
114  return "Green";
115 
116  case QgsRaster::BlueBand:
117  return "Blue";
118 
120  return "Alpha";
121 
122  case QgsRaster::HueBand:
123  return "Hue";
124 
126  return "Saturation";
127 
129  return "Lightness";
130 
131  case QgsRaster::CyanBand:
132  return "Cyan";
133 
135  return "Magenta";
136 
138  return "Yellow";
139 
141  return "Black";
142 
144  return "YCbCr_Y";
145 
147  return "YCbCr_Cb";
148 
150  return "YCbCr_Cr";
151 
152  default:
153  return "Unknown";
154  }
155  }
157  virtual bool reload() { return true; }
158 
159  virtual QString colorInterpretationName( int theBandNo ) const
160  {
161  return colorName( colorInterpretation( theBandNo ) );
162  }
163 
164  // TODO: remove or make protected all readBlock working with void*
165 
167  virtual QgsRasterBlock *block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight );
168 
169  /* Return true if source band has no data value */
170  virtual bool srcHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo -1 ); }
171 
173  virtual bool useSrcNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo -1 ); }
174 
176  virtual void setUseSrcNoDataValue( int bandNo, bool use );
177 
179  virtual double srcNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo -1 ); }
180 
181  virtual void setUserNoDataValue( int bandNo, QgsRasterRangeList noData );
182 
184  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
185 
186  virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
187  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
188 
191  virtual QStringList subLayers() const
192  {
193  return QStringList();
194  }
195 
198  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false )
199  {
200  Q_UNUSED( scale );
201  Q_UNUSED( forceRefresh );
202  return QImage();
203  }
204 
206  virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
207  const QString & theResamplingMethod = "NEAREST",
209  const QStringList & theConfigOptions = QStringList() )
210  {
211  Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod );
212  Q_UNUSED( theFormat ); Q_UNUSED( theConfigOptions );
213  return "FAILED_NOT_SUPPORTED";
214  };
215 
223  virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() )
224  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); };
225 
227  bool hasPyramids();
228 
233  virtual QString metadata() = 0;
234 
257  //virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
258  virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
259 
269  virtual QString lastErrorTitle() = 0;
270 
280  virtual QString lastError() = 0;
281 
287  virtual QString lastErrorFormat();
288 
291  int dpi() const {return mDpi;}
292 
295  void setDpi( int dpi ) {mDpi = dpi;}
296 
298  virtual QDateTime timestamp() const { return mTimestamp; }
299 
301  virtual QDateTime dataTimestamp() const { return QDateTime(); }
302 
304  // TODO: add data type (may be defferent from band type)
305  virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
306  {
307  Q_UNUSED( data );
308  Q_UNUSED( band );
309  Q_UNUSED( width );
310  Q_UNUSED( height );
311  Q_UNUSED( xOffset );
312  Q_UNUSED( yOffset );
313  return false;
314  }
315 
317  static QgsRasterDataProvider* create( const QString &providerKey,
318  const QString &uri,
319  const QString& format, int nBands,
320  QGis::DataType type,
321  int width, int height, double* geoTransform,
322  const QgsCoordinateReferenceSystem& crs,
323  QStringList createOptions = QStringList() );
324 
329  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
330 
332  // TODO: this should be static and call C functions in provider library
333  //static QStringList createFormats();
334 
336  virtual bool remove() { return false; }
337 
340  static QList<QPair<QString, QString> > pyramidResamplingMethods( QString providerKey );
341 
345  virtual QString validateCreationOptions( const QStringList& createOptions, QString format )
346  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
347 
350  virtual QString validatePyramidsConfigOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
351  const QStringList & theConfigOptions, const QString & fileFormat )
352  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
353 
354  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
355  static QgsRaster::IdentifyFormat identifyFormatFromName( QString formatName );
356  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
357  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
358 
359  signals:
362  void progress( int theType, double theProgress, QString theMessage );
363  void progressUpdate( int theProgress );
364 
365  protected:
368  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
369  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
370 
373  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data )
374  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
375 
377  bool userNoDataValuesContains( int bandNo, double value ) const;
378 
379  static QStringList cStringList2Q_( char ** stringList );
380 
381  static QString makeTableCell( const QString & value );
382  static QString makeTableCells( const QStringList & values );
383 
387  int mDpi;
388 
391  //bool hasNoDataValue ( int theBandNo );
392 
394  QList<double> mSrcNoDataValue;
395 
397  QList<bool> mSrcHasNoDataValue;
398 
402  QList<bool> mUseSrcNoDataValue;
403 
406  QList< QgsRasterRangeList > mUserNoDataValue;
407 
409 
410  static void initPyramidResamplingDefs();
411  static QStringList mPyramidResamplingListGdal;
413 
414 };
415 #endif