QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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 
294  virtual QString lastErrorFormat();
295 
298  int dpi() const { return mDpi; }
299 
302  void setDpi( int dpi ) { mDpi = dpi; }
303 
305  virtual QDateTime timestamp() const { return mTimestamp; }
306 
308  virtual QDateTime dataTimestamp() const { return QDateTime(); }
309 
311  // TODO: add data type (may be defferent from band type)
312  virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
313  {
314  Q_UNUSED( data );
315  Q_UNUSED( band );
316  Q_UNUSED( width );
317  Q_UNUSED( height );
318  Q_UNUSED( xOffset );
319  Q_UNUSED( yOffset );
320  return false;
321  }
322 
324  static QgsRasterDataProvider* create( const QString &providerKey,
325  const QString &uri,
326  const QString& format, int nBands,
327  QGis::DataType type,
328  int width, int height, double* geoTransform,
329  const QgsCoordinateReferenceSystem& crs,
330  QStringList createOptions = QStringList() );
331 
336  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
337 
339  virtual bool remove() { return false; }
340 
343  static QList<QPair<QString, QString> > pyramidResamplingMethods( QString providerKey );
344 
348  virtual QString validateCreationOptions( const QStringList& createOptions, QString format )
349  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
350 
354  const QStringList & theConfigOptions, const QString & fileFormat )
355  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
356 
357  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
358  static QgsRaster::IdentifyFormat identifyFormatFromName( QString formatName );
359  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
360  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
361 
362  signals:
365  void progress( int theType, double theProgress, QString theMessage );
366  void progressUpdate( int theProgress );
367 
368  protected:
371  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
372  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
373 
376  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data )
377  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
378 
380  bool userNoDataValuesContains( int bandNo, double value ) const;
381 
383  void copyBaseSettings( const QgsRasterDataProvider& other );
384 
385  static QStringList cStringList2Q_( char ** stringList );
386 
387  static QString makeTableCell( const QString & value );
388  static QString makeTableCells( const QStringList & values );
389 
393  int mDpi;
394 
397  //bool hasNoDataValue ( int theBandNo );
398 
400  QList<double> mSrcNoDataValue;
401 
403  QList<bool> mSrcHasNoDataValue;
404 
408  QList<bool> mUseSrcNoDataValue;
409 
412  QList< QgsRasterRangeList > mUserNoDataValue;
413 
415 
416  static void initPyramidResamplingDefs();
417  static QStringList mPyramidResamplingListGdal;
419 
420 };
421 #endif
virtual void readBlock(int bandNo, int xBlock, int yBlock, void *data)
Read block of data.
Definition: qgsrasterdataprovider.h:371
virtual QStringList subLayers() const
Returns the sublayers of this layer - useful for providers that manage their own layers, such as WMS.
Definition: qgsrasterdataprovider.h:198
A rectangle specified with double values.
Definition: qgsrectangle.h:35
Definition: qgsraster.h:44
Definition: qgsraster.h:50
virtual QString validatePyramidsConfigOptions(QgsRaster::RasterPyramidsFormat pyramidsFormat, const QStringList &theConfigOptions, const QString &fileFormat)
Validates pyramid creation options for a specific dataset and destination format. ...
Definition: qgsrasterdataprovider.h:353
static QStringList mPyramidResamplingListGdal
Definition: qgsrasterdataprovider.h:417
Definition: qgsraster.h:40
Definition: qgsraster.h:35
virtual ~QgsRasterDataProvider()
Definition: qgsrasterdataprovider.h:62
virtual double bandOffset(int bandNo) const
Read band offset for raster value @note added in 2.3.
Definition: qgsrasterdataprovider.h:169
virtual double srcNoDataValue(int bandNo) const
Value representing no data value.
Definition: qgsrasterdataprovider.h:186
QDateTime mTimestamp
Timestamp of data in the moment when the data were loaded by provider.
Definition: qgsdataprovider.h:329
QgsRectangle mExtent
Definition: qgsrasterdataprovider.h:414
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Get list of user no data value ranges.
Definition: qgsrasterdataprovider.h:191
virtual bool setNoDataValue(int bandNo, double noDataValue)
Set no data value on created dataset.
Definition: qgsrasterdataprovider.h:336
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:46
Definition: qgsraster.h:36
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
int mDpi
Dots per inch.
Definition: qgsrasterdataprovider.h:393
Definition: qgsraster.h:42
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
Definition: qgsrasterdataprovider.h:308
Definition: qgsraster.h:46
virtual bool useSrcNoDataValue(int bandNo) const
Get source nodata value usage.
Definition: qgsrasterdataprovider.h:180
Raster identify results container.
Definition: qgsrasteridentifyresult.h:29
Definition: qgsraster.h:47
Definition: qgsraster.h:45
Raster data container.
Definition: qgsrasterblock.h:32
virtual void readBlock(int bandNo, QgsRectangle const &viewExtent, int width, int height, void *data)
Read block of data using give extent and size.
Definition: qgsrasterdataprovider.h:376
virtual QList< QgsRasterPyramid > buildPyramidList(QList< int > overviewList=QList< int >())
Accessor for ths raster layers pyramid list.
Definition: qgsrasterdataprovider.h:230
Definition: qgsraster.h:80
Definition: qgsraster.h:41
virtual bool reload()
Reload data (data could change)
Definition: qgsrasterdataprovider.h:157
QList< bool > mSrcHasNoDataValue
Source no data value exists.
Definition: qgsrasterdataprovider.h:403
IdentifyFormat
Definition: qgsraster.h:54
Definition: qgsraster.h:49
Definition: qgsraster.h:43
Definition: qgsraster.h:39
DataType
Raster data types.
Definition: qgis.h:204
RasterPyramidsFormat
Definition: qgsraster.h:78
bool setInput(QgsRasterInterface *input)
Set input.
Definition: qgsrasterdataprovider.h:67
virtual QGis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
Base class for processing filters like renderers, reprojector, resampler etc.
Definition: qgsrasterinterface.h:35
A class to represent a point geometry.
Definition: qgspoint.h:63
virtual QString colorInterpretationName(int theBandNo) const
Definition: qgsrasterdataprovider.h:159
Definition: qgsraster.h:37
QList< double > mSrcNoDataValue
Source no data value is available and is set to be used or internal no data is available.
Definition: qgsrasterdataprovider.h:400
virtual int colorInterpretation(int theBandNo) const
Returns data type for the band specified by number.
Definition: qgsrasterdataprovider.h:90
virtual double bandScale(int bandNo) const
Read band scale for raster value @note added in 2.3.
Definition: qgsrasterdataprovider.h:166
virtual QImage getLegendGraphic(double scale=0, bool forceRefresh=false)
Returns the legend rendered as pixmap useful for that layer that need to get legend layer remotly as ...
Definition: qgsrasterdataprovider.h:205
QString colorName(int colorInterpretation) const
Definition: qgsrasterdataprovider.h:96
virtual QgsRectangle extent()=0
Get the extent of the layer.
QList< QgsRasterRange > QgsRasterRangeList
Definition: qgsrasterrange.h:23
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
Definition: qgsraster.h:38
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
Definition: qgsrasterdataprovider.h:305
Definition: qgsraster.h:34
virtual QGis::DataType srcDataType(int bandNo) const
Returns source data type for the band specified by number, source data type may be shorter than dataT...
Definition: qgsrasterinterface.h:78
virtual QString validateCreationOptions(const QStringList &createOptions, QString format)
Validates creation options for a specific dataset and destination format.
Definition: qgsrasterdataprovider.h:348
Class for storing a coordinate reference system (CRS)
Definition: qgscoordinatereferencesystem.h:50
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)=0
Read block of data using given extent and size.
virtual QString buildPyramids(const QList< QgsRasterPyramid > &thePyramidList, const QString &theResamplingMethod="NEAREST", QgsRaster::RasterPyramidsFormat theFormat=QgsRaster::PyramidsGTiff, const QStringList &theConfigOptions=QStringList())
Create pyramid overviews.
Definition: qgsrasterdataprovider.h:213
Definition: qgsraster.h:48
virtual bool write(void *data, int band, int width, int height, int xOffset, int yOffset)
Writes into the provider datasource.
Definition: qgsrasterdataprovider.h:312
virtual bool srcHasNoDataValue(int bandNo) const
Definition: qgsrasterdataprovider.h:177
int dpi() const
Returns the dpi of the output device.
Definition: qgsrasterdataprovider.h:298
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
Definition: qgsrasterdataprovider.h:193
void setDpi(int dpi)
Sets the output device resolution.
Definition: qgsrasterdataprovider.h:302
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:53
QList< QgsRasterRangeList > mUserNoDataValue
List of lists of user defined additional no data values for each band, indexed from 0...
Definition: qgsrasterdataprovider.h:412
static QgsStringMap mPyramidResamplingMapGdal
Definition: qgsrasterdataprovider.h:418
QList< bool > mUseSrcNoDataValue
Use source nodata value.
Definition: qgsrasterdataprovider.h:408