QGIS API Documentation  2.13.0-Master
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 
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, const QgsRasterRangeList& noData );
217 
219  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
220 
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 = nullptr )
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 nullptr;
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 );
273  Q_UNUSED( theResamplingMethod );
274  Q_UNUSED( theFormat );
275  Q_UNUSED( theConfigOptions );
276  return "FAILED_NOT_SUPPORTED";
277  }
278 
287  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }
288 
290  bool hasPyramids();
291 
296  virtual QString metadata() = 0;
297 
320  //virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
321  virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
322 
332  virtual QString lastErrorTitle() = 0;
333 
343  virtual QString lastError() = 0;
344 
346  virtual QString lastErrorFormat();
347 
349  int dpi() const { return mDpi; }
350 
352  void setDpi( int dpi ) { mDpi = dpi; }
353 
355  virtual QDateTime timestamp() const override { return mTimestamp; }
356 
358  virtual QDateTime dataTimestamp() const override { return QDateTime(); }
359 
361  // TODO: add data type (may be defferent from band type)
362  virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
363  {
364  Q_UNUSED( data );
365  Q_UNUSED( band );
366  Q_UNUSED( width );
367  Q_UNUSED( height );
368  Q_UNUSED( xOffset );
369  Q_UNUSED( yOffset );
370  return false;
371  }
372 
374  static QgsRasterDataProvider* create( const QString &providerKey,
375  const QString &uri,
376  const QString& format, int nBands,
377  QGis::DataType type,
378  int width, int height, double* geoTransform,
379  const QgsCoordinateReferenceSystem& crs,
380  const QStringList& createOptions = QStringList() );
381 
386  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
387 
389  virtual bool remove() { return false; }
390 
393  static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString& providerKey );
394 
398  virtual QString validateCreationOptions( const QStringList& createOptions, const QString& format )
399  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
400 
404  const QStringList & theConfigOptions, const QString & fileFormat )
405  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
406 
407  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
408  static QgsRaster::IdentifyFormat identifyFormatFromName( const QString& formatName );
409  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
410  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
411 
412  signals:
415  void progress( int theType, double theProgress, const QString& theMessage );
416  void progressUpdate( int theProgress );
417 
420  void statusChanged( const QString& );
421 
422  protected:
425  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
426  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
427 
430  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data )
431  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
432 
434  bool userNoDataValuesContains( int bandNo, double value ) const;
435 
437  void copyBaseSettings( const QgsRasterDataProvider& other );
438 
440  static QStringList cStringList2Q_( char ** stringList );
441 
442  static QString makeTableCell( const QString & value );
443  static QString makeTableCells( const QStringList & values );
444 
447  int mDpi;
448 
451  //bool hasNoDataValue ( int theBandNo );
452 
455 
458 
463 
467 
469 
472 
473 };
474 #endif
virtual void readBlock(int bandNo, int xBlock, int yBlock, void *data)
Read block of data.
IdentifyFormat
Definition: qgsraster.h:54
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.
Black band of CMLY image.
Definition: qgsraster.h:47
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.
Red band of RGBA image.
Definition: qgsraster.h:37
Capability
If you add to this, please also add to capabilitiesString()
virtual QImage getLegendGraphic(double scale=0, bool forceRefresh=false, const QgsRectangle *visibleExtent=nullptr)
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.
Hue band of HLS image.
Definition: qgsraster.h:41
T value(int i) const
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.
Lightness band of HLS image.
Definition: qgsraster.h:43
Paletted (see associated color table)
Definition: qgsraster.h:36
Alpha (0=transparent, 255=opaque)
Definition: qgsraster.h:40
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.
Green band of RGBA image.
Definition: qgsraster.h:38
virtual QList< QgsRasterPyramid > buildPyramidList(QList< int > overviewList=QList< int >())
Accessor for ths raster layers pyramid list.
Y Luminance.
Definition: qgsraster.h:48
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.
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:65
Saturation band of HLS image.
Definition: qgsraster.h:42
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.
Blue band of RGBA image.
Definition: qgsraster.h:39
QString colorName(int colorInterpretation) const
virtual QgsRectangle extent()=0
Get the extent of the layer.
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...
Class for storing a coordinate reference system (CRS)
DataType
Raster data types.
Definition: qgis.h:129
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)=0
Read block of data using given extent and size.
Greyscale.
Definition: qgsraster.h:35
virtual QString buildPyramids(const QList< QgsRasterPyramid > &thePyramidList, const QString &theResamplingMethod="NEAREST", QgsRaster::RasterPyramidsFormat theFormat=QgsRaster::PyramidsGTiff, const QStringList &theConfigOptions=QStringList())
Create pyramid overviews.
Magenta band of CMYK image.
Definition: qgsraster.h:45
virtual QString validateCreationOptions(const QStringList &createOptions, const QString &format)
Validates creation options for a specific dataset and destination format.
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
Return true if source band has no data value.
int dpi() const
Returns the dpi of the output device.
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
RasterPyramidsFormat
Definition: qgsraster.h:78
void setDpi(int dpi)
Sets the output device resolution.
Cyan band of CMYK image.
Definition: qgsraster.h:44
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.
Yellow band of CMYK image.
Definition: qgsraster.h:46