QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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.
virtual QStringList subLayers() const
Returns the sublayers of this layer - useful for providers that manage their own layers, such as WMS.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
virtual QString validatePyramidsConfigOptions(QgsRaster::RasterPyramidsFormat pyramidsFormat, const QStringList &theConfigOptions, const QString &fileFormat)
Validates pyramid creation options for a specific dataset and destination format. ...
static QStringList mPyramidResamplingListGdal
virtual double bandOffset(int bandNo) const
Read band offset for raster value @note added in 2.3.
virtual double srcNoDataValue(int bandNo) const
Value representing no data value.
QDateTime mTimestamp
Timestamp of data in the moment when the data were loaded by provider.
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Get list of user no data value ranges.
virtual bool setNoDataValue(int bandNo, double noDataValue)
Set no data value on created dataset.
Abstract base class for spatial data provider implementations.
QMap< QString, QString > QgsStringMap
Definition: qgis.h:416
virtual QDateTime dataTimestamp() const
Current time stamp of data source.
virtual bool useSrcNoDataValue(int bandNo) const
Get source nodata value usage.
Raster identify results container.
Raster data container.
virtual void readBlock(int bandNo, QgsRectangle const &viewExtent, int width, int height, void *data)
Read block of data using give extent and size.
virtual QList< QgsRasterPyramid > buildPyramidList(QList< int > overviewList=QList< int >())
Accessor for ths raster layers pyramid list.
virtual bool reload()
Reload data (data could change)
QList< bool > mSrcHasNoDataValue
Source no data value exists.
IdentifyFormat
Definition: qgsraster.h:54
DataType
Raster data types.
Definition: qgis.h:204
RasterPyramidsFormat
Definition: qgsraster.h:78
bool setInput(QgsRasterInterface *input)
Set input.
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.
A class to represent a point geometry.
Definition: qgspoint.h:63
virtual QString colorInterpretationName(int theBandNo) const
QList< double > mSrcNoDataValue
Source no data value is available and is set to be used or internal no data is available.
virtual int colorInterpretation(int theBandNo) const
Returns data type for the band specified by number.
virtual double bandScale(int bandNo) const
Read band scale for raster value @note added in 2.3.
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 ...
QString colorName(int colorInterpretation) const
virtual QgsRectangle extent()=0
Get the extent of the layer.
QList< QgsRasterRange > QgsRasterRangeList
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
virtual QDateTime timestamp() const
Time stamp of data source in the moment when data/metadata were loaded by provider.
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...
virtual QString validateCreationOptions(const QStringList &createOptions, QString format)
Validates creation options for a specific dataset and destination format.
Class for storing a coordinate reference system (CRS)
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.
virtual bool write(void *data, int band, int width, int height, int xOffset, int yOffset)
Writes into the provider datasource.
virtual bool srcHasNoDataValue(int bandNo) const
int dpi() const
Returns the dpi of the output device.
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
void setDpi(int dpi)
Sets the output device resolution.
Base class for raster data providers.
QList< QgsRasterRangeList > mUserNoDataValue
List of lists of user defined additional no data values for each band, indexed from 0...
static QgsStringMap mPyramidResamplingMapGdal
QList< bool > mUseSrcNoDataValue
Use source nodata value.