QGIS API Documentation  2.9.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  async legend fetcher : Sandro Santilli < strk at keybit dot net >
9 
10  ***************************************************************************/
11 
12 /***************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  ***************************************************************************/
20 
21 /* Thank you to Marco Hugentobler for the original vector DataProvider */
22 
23 #ifndef QGSRASTERDATAPROVIDER_H
24 #define QGSRASTERDATAPROVIDER_H
25 
26 #include <cmath>
27 
28 #include <QDateTime>
29 #include <QVariant>
30 #include <QImage>
31 
32 #include "qgscolorrampshader.h"
34 #include "qgsdataprovider.h"
35 #include "qgserror.h"
36 #include "qgsfeature.h"
37 #include "qgsfield.h"
38 #include "qgslogger.h"
39 #include "qgsrasterbandstats.h"
40 #include "qgsraster.h"
41 #include "qgsrasterhistogram.h"
42 #include "qgsrasterinterface.h"
43 #include "qgsrasterpyramid.h"
44 #include "qgsrasterrange.h"
45 #include "qgsrectangle.h"
46 
47 class QImage;
48 class QByteArray;
49 
50 class QgsPoint;
52 class QgsMapSettings;
53 
59 class CORE_EXPORT QgsImageFetcher : public QObject
60 {
61  Q_OBJECT
62  public:
63 
65  virtual ~QgsImageFetcher( ) {}
66 
67  // Make sure to connect to "finish" and "error" before starting
68  virtual void start() = 0;
69 
70  signals:
71 
72  void finish( const QImage& legend );
73  void progress( qint64 received, qint64 total );
74  void error( const QString& msg );
75 };
76 
77 
81 class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRasterInterface
82 {
83  Q_OBJECT
84 
85  public:
87 
88  QgsRasterDataProvider( const QString & uri );
89 
91 
92  virtual QgsRasterInterface * clone() const override = 0;
93 
94  /* It makes no sense to set input on provider */
95  bool setInput( QgsRasterInterface* input ) override { Q_UNUSED( input ); return false; }
96 
104  virtual QImage* draw( const QgsRectangle & viewExtent, int pixelWidth, int pixelHeight ) = 0;
105 
108  virtual QgsRectangle extent() override = 0;
109 
111  virtual QGis::DataType dataType( int bandNo ) const override = 0;
112 
115  virtual QGis::DataType srcDataType( int bandNo ) const override = 0;
116 
118  virtual int colorInterpretation( int theBandNo ) const
119  {
120  Q_UNUSED( theBandNo );
122  }
123 
124  QString colorName( int colorInterpretation ) const
125  {
126  // Modified copy from GDAL
127  switch ( colorInterpretation )
128  {
130  return "Undefined";
131 
133  return "Gray";
134 
136  return "Palette";
137 
138  case QgsRaster::RedBand:
139  return "Red";
140 
142  return "Green";
143 
144  case QgsRaster::BlueBand:
145  return "Blue";
146 
148  return "Alpha";
149 
150  case QgsRaster::HueBand:
151  return "Hue";
152 
154  return "Saturation";
155 
157  return "Lightness";
158 
159  case QgsRaster::CyanBand:
160  return "Cyan";
161 
163  return "Magenta";
164 
166  return "Yellow";
167 
169  return "Black";
170 
172  return "YCbCr_Y";
173 
175  return "YCbCr_Cb";
176 
178  return "YCbCr_Cr";
179 
180  default:
181  return "Unknown";
182  }
183  }
185  virtual bool reload() { return true; }
186 
187  virtual QString colorInterpretationName( int theBandNo ) const
188  {
189  return colorName( colorInterpretation( theBandNo ) );
190  }
191 
194  virtual double bandScale( int bandNo ) const { Q_UNUSED( bandNo ); return 1.0; }
197  virtual double bandOffset( int bandNo ) const { Q_UNUSED( bandNo ); return 0.0; }
198 
199  // TODO: remove or make protected all readBlock working with void*
200 
202  virtual QgsRasterBlock *block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight ) override;
203 
204  /* Return true if source band has no data value */
205  virtual bool srcHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo -1 ); }
206 
208  virtual bool useSrcNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo -1 ); }
209 
211  virtual void setUseSrcNoDataValue( int bandNo, bool use );
212 
214  virtual double srcNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo -1 ); }
215 
216  virtual void setUserNoDataValue( int bandNo, QgsRasterRangeList noData );
217 
219  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
220 
221  virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
222  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
223 
226  virtual QStringList subLayers() const override
227  {
228  return QStringList();
229  }
230 
239  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle * visibleExtent = 0 )
240  {
241  Q_UNUSED( scale );
242  Q_UNUSED( forceRefresh );
243  Q_UNUSED( visibleExtent );
244  return QImage();
245  }
246 
261  {
262  Q_UNUSED( mapSettings );
263  return 0;
264  }
265 
267  virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
268  const QString & theResamplingMethod = "NEAREST",
270  const QStringList & theConfigOptions = QStringList() )
271  {
272  Q_UNUSED( thePyramidList ); Q_UNUSED( theResamplingMethod );
273  Q_UNUSED( theFormat ); Q_UNUSED( theConfigOptions );
274  return "FAILED_NOT_SUPPORTED";
275  }
276 
284  virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() )
285  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }
286 
288  bool hasPyramids();
289 
294  virtual QString metadata() = 0;
295 
318  //virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
319  virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
320 
330  virtual QString lastErrorTitle() = 0;
331 
341  virtual QString lastError() = 0;
342 
344  virtual QString lastErrorFormat();
345 
347  int dpi() const { return mDpi; }
348 
350  void setDpi( int dpi ) { mDpi = dpi; }
351 
353  virtual QDateTime timestamp() const override { return mTimestamp; }
354 
356  virtual QDateTime dataTimestamp() const override { return QDateTime(); }
357 
359  // TODO: add data type (may be defferent from band type)
360  virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
361  {
362  Q_UNUSED( data );
363  Q_UNUSED( band );
364  Q_UNUSED( width );
365  Q_UNUSED( height );
366  Q_UNUSED( xOffset );
367  Q_UNUSED( yOffset );
368  return false;
369  }
370 
372  static QgsRasterDataProvider* create( const QString &providerKey,
373  const QString &uri,
374  const QString& format, int nBands,
375  QGis::DataType type,
376  int width, int height, double* geoTransform,
377  const QgsCoordinateReferenceSystem& crs,
378  QStringList createOptions = QStringList() );
379 
384  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
385 
387  virtual bool remove() { return false; }
388 
391  static QList<QPair<QString, QString> > pyramidResamplingMethods( QString providerKey );
392 
396  virtual QString validateCreationOptions( const QStringList& createOptions, QString format )
397  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
398 
402  const QStringList & theConfigOptions, const QString & fileFormat )
403  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
404 
405  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
406  static QgsRaster::IdentifyFormat identifyFormatFromName( QString formatName );
407  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
408  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
409 
410  signals:
413  void progress( int theType, double theProgress, QString theMessage );
414  void progressUpdate( int theProgress );
415 
416  protected:
419  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
420  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
421 
424  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data )
425  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
426 
428  bool userNoDataValuesContains( int bandNo, double value ) const;
429 
431  void copyBaseSettings( const QgsRasterDataProvider& other );
432 
433  static QStringList cStringList2Q_( char ** stringList );
434 
435  static QString makeTableCell( const QString & value );
436  static QString makeTableCells( const QStringList & values );
437 
440  int mDpi;
441 
444  //bool hasNoDataValue ( int theBandNo );
445 
447  QList<double> mSrcNoDataValue;
448 
450  QList<bool> mSrcHasNoDataValue;
451 
455  QList<bool> mUseSrcNoDataValue;
456 
459  QList< QgsRasterRangeList > mUserNoDataValue;
460 
462 
463  static void initPyramidResamplingDefs();
464  static QStringList mPyramidResamplingListGdal;
466 
467 };
468 #endif
virtual void readBlock(int bandNo, int xBlock, int yBlock, void *data)
Read block of data.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
bool setInput(QgsRasterInterface *input) override
Set input.
virtual QDateTime timestamp() const override
Time stamp of data source in the moment when data/metadata were loaded by provider.
Handles asynchronous download of images.
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 QgsImageFetcher * getLegendGraphicFetcher(const QgsMapSettings *mapSettings)
Get an image downloader for the raster legend.
virtual QImage getLegendGraphic(double scale=0, bool forceRefresh=false, const QgsRectangle *visibleExtent=0)
Returns the legend rendered as pixmap.
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:438
The QgsMapSettings class contains configuration for rendering of the map.
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 QStringList subLayers() const override
Returns the sublayers of this layer - useful for providers that manage their own layers, such as WMS.
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
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.
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.
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 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.
virtual QDateTime dataTimestamp() const override
Current time stamp of data source.
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.