QGIS API Documentation  2.6.0-Brighton
 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 
166  virtual double bandScale( int bandNo ) const { Q_UNUSED( bandNo ); return 1.0; }
169  virtual double bandOffset( int bandNo ) const { Q_UNUSED( bandNo ); return 0.0; }
170 
171  // TODO: remove or make protected all readBlock working with void*
172 
174  virtual QgsRasterBlock *block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight );
175 
176  /* Return true if source band has no data value */
177  virtual bool srcHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo -1 ); }
178 
180  virtual bool useSrcNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo -1 ); }
181 
183  virtual void setUseSrcNoDataValue( int bandNo, bool use );
184 
186  virtual double srcNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo -1 ); }
187 
188  virtual void setUserNoDataValue( int bandNo, QgsRasterRangeList noData );
189 
191  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
192 
193  virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
194  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
195 
198  virtual QStringList subLayers() const
199  {
200  return QStringList();
201  }
202 
205  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false )
206  {
207  Q_UNUSED( scale );
208  Q_UNUSED( forceRefresh );
209  return QImage();
210  }
211 
213  virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
214  const QString & theResamplingMethod = "NEAREST",
216  const QStringList & theConfigOptions = QStringList() )
217  {
218  Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod );
219  Q_UNUSED( theFormat ); Q_UNUSED( theConfigOptions );
220  return "FAILED_NOT_SUPPORTED";
221  };
222 
230  virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() )
231  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); };
232 
234  bool hasPyramids();
235 
240  virtual QString metadata() = 0;
241 
264  //virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
265  virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
266 
276  virtual QString lastErrorTitle() = 0;
277 
287  virtual QString lastError() = 0;
288 
290  virtual QString lastErrorFormat();
291 
293  int dpi() const { return mDpi; }
294 
296  void setDpi( int dpi ) { mDpi = dpi; }
297 
299  virtual QDateTime timestamp() const { return mTimestamp; }
300 
302  virtual QDateTime dataTimestamp() const { return QDateTime(); }
303 
305  // TODO: add data type (may be defferent from band type)
306  virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
307  {
308  Q_UNUSED( data );
309  Q_UNUSED( band );
310  Q_UNUSED( width );
311  Q_UNUSED( height );
312  Q_UNUSED( xOffset );
313  Q_UNUSED( yOffset );
314  return false;
315  }
316 
318  static QgsRasterDataProvider* create( const QString &providerKey,
319  const QString &uri,
320  const QString& format, int nBands,
321  QGis::DataType type,
322  int width, int height, double* geoTransform,
323  const QgsCoordinateReferenceSystem& crs,
324  QStringList createOptions = QStringList() );
325 
330  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
331 
333  virtual bool remove() { return false; }
334 
337  static QList<QPair<QString, QString> > pyramidResamplingMethods( QString providerKey );
338 
342  virtual QString validateCreationOptions( const QStringList& createOptions, QString format )
343  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
344 
347  virtual QString validatePyramidsConfigOptions( QgsRaster::RasterPyramidsFormat pyramidsFormat,
348  const QStringList & theConfigOptions, const QString & fileFormat )
349  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
350 
351  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
352  static QgsRaster::IdentifyFormat identifyFormatFromName( QString formatName );
353  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
354  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
355 
356  signals:
359  void progress( int theType, double theProgress, QString theMessage );
360  void progressUpdate( int theProgress );
361 
362  protected:
365  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
366  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
367 
370  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data )
371  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
372 
374  bool userNoDataValuesContains( int bandNo, double value ) const;
375 
377  void copyBaseSettings( const QgsRasterDataProvider& other );
378 
379  static QStringList cStringList2Q_( char ** stringList );
380 
381  static QString makeTableCell( const QString & value );
382  static QString makeTableCells( const QStringList & values );
383 
386  int mDpi;
387 
390  //bool hasNoDataValue ( int theBandNo );
391 
393  QList<double> mSrcNoDataValue;
394 
396  QList<bool> mSrcHasNoDataValue;
397 
401  QList<bool> mUseSrcNoDataValue;
402 
405  QList< QgsRasterRangeList > mUserNoDataValue;
406 
408 
409  static void initPyramidResamplingDefs();
410  static QStringList mPyramidResamplingListGdal;
412 
413 };
414 #endif