QGIS API Documentation  2.99.0-Master (ba079d8)
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 "qgis_core.h"
27 #include "qgis_sip.h"
28 #include <cmath>
29 
30 #include <QDateTime>
31 #include <QVariant>
32 #include <QImage>
33 
34 #include "qgscolorrampshader.h"
35 #include "qgsdataprovider.h"
36 #include "qgsfields.h"
37 #include "qgsraster.h"
38 #include "qgsrasterinterface.h"
39 #include "qgsrasterpyramid.h"
40 #include "qgsrasterrange.h"
41 #include "qgsrectangle.h"
42 #include "qgsrasteriterator.h"
43 
44 class QImage;
45 class QByteArray;
46 
47 class QgsPoint;
49 class QgsMapSettings;
50 
56 class CORE_EXPORT QgsImageFetcher : public QObject
57 {
58  Q_OBJECT
59  public:
61  QgsImageFetcher( QObject *parent = 0 ) : QObject( parent ) {}
62 
65  virtual void start() = 0;
66 
67  signals:
68 
71  void finish( const QImage &legend );
73  void progress( qint64 received, qint64 total );
75  void error( const QString &msg );
76 };
77 
78 
82 class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRasterInterface
83 {
84  Q_OBJECT
85 
86  public:
88 
89  QgsRasterDataProvider( const QString &uri );
90 
91  virtual QgsRasterInterface *clone() const override = 0;
92 
93  /* It makes no sense to set input on provider */
94  bool setInput( QgsRasterInterface *input ) override { Q_UNUSED( input ); return false; }
95 
96  virtual QgsRectangle extent() const override = 0;
97 
99  virtual Qgis::DataType dataType( int bandNo ) const override = 0;
100 
104  virtual Qgis::DataType sourceDataType( int bandNo ) const override = 0;
105 
107  virtual int colorInterpretation( int bandNo ) const
108  {
109  Q_UNUSED( bandNo );
111  }
112 
113  QString colorName( int colorInterpretation ) const
114  {
115  // Modified copy from GDAL
116  switch ( colorInterpretation )
117  {
119  return QStringLiteral( "Undefined" );
120 
122  return QStringLiteral( "Gray" );
123 
125  return QStringLiteral( "Palette" );
126 
127  case QgsRaster::RedBand:
128  return QStringLiteral( "Red" );
129 
131  return QStringLiteral( "Green" );
132 
133  case QgsRaster::BlueBand:
134  return QStringLiteral( "Blue" );
135 
137  return QStringLiteral( "Alpha" );
138 
139  case QgsRaster::HueBand:
140  return QStringLiteral( "Hue" );
141 
143  return QStringLiteral( "Saturation" );
144 
146  return QStringLiteral( "Lightness" );
147 
148  case QgsRaster::CyanBand:
149  return QStringLiteral( "Cyan" );
150 
152  return QStringLiteral( "Magenta" );
153 
155  return QStringLiteral( "Yellow" );
156 
158  return QStringLiteral( "Black" );
159 
161  return QStringLiteral( "YCbCr_Y" );
162 
164  return QStringLiteral( "YCbCr_Cb" );
165 
167  return QStringLiteral( "YCbCr_Cr" );
168 
169  default:
170  return QStringLiteral( "Unknown" );
171  }
172  }
174  virtual bool reload() { return true; }
175 
176  virtual QString colorInterpretationName( int bandNo ) const
177  {
178  return colorName( colorInterpretation( bandNo ) );
179  }
180 
184  virtual double bandScale( int bandNo ) const { Q_UNUSED( bandNo ); return 1.0; }
185 
189  virtual double bandOffset( int bandNo ) const { Q_UNUSED( bandNo ); return 0.0; }
190 
191  // TODO: remove or make protected all readBlock working with void*
192 
194  virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override;
195 
197  virtual bool sourceHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo - 1 ); }
198 
200  virtual bool useSourceNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo - 1 ); }
201 
203  virtual void setUseSourceNoDataValue( int bandNo, bool use );
204 
206  virtual double sourceNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo - 1 ); }
207 
208  virtual void setUserNoDataValue( int bandNo, const QgsRasterRangeList &noData );
209 
211  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo - 1 ); }
212 
213  virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
214  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
215 
218  virtual QStringList subLayers() const override
219  {
220  return QStringList();
221  }
222 
224  virtual bool supportsLegendGraphic() const { return false; }
225 
235  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle *visibleExtent = nullptr ) SIP_SKIP
236  {
237  Q_UNUSED( scale );
238  Q_UNUSED( forceRefresh );
239  Q_UNUSED( visibleExtent );
240  return QImage();
241  }
242 
257  {
258  Q_UNUSED( mapSettings );
259  return nullptr;
260  }
261 
263  virtual QString buildPyramids( const QList<QgsRasterPyramid> &pyramidList,
264  const QString &resamplingMethod = "NEAREST",
266  const QStringList &configOptions = QStringList(),
267  QgsRasterBlockFeedback *feedback = nullptr )
268  {
269  Q_UNUSED( pyramidList );
270  Q_UNUSED( resamplingMethod );
271  Q_UNUSED( format );
272  Q_UNUSED( configOptions );
273  Q_UNUSED( feedback );
274  return QStringLiteral( "FAILED_NOT_SUPPORTED" );
275  }
276 
284  virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() ) // clazy:exclude=function-args-by-ref
285  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }
286 
288  bool hasPyramids();
289 
294  virtual QString metadata() = 0;
295 
319  //virtual QMap<int, QVariant> identify( const QgsPoint & point, QgsRaster::IdentifyFormat format, const QgsRectangle &extent = QgsRectangle(), int width = 0, int height = 0 );
320  virtual QgsRasterIdentifyResult identify( const QgsPoint &point, QgsRaster::IdentifyFormat format, const QgsRectangle &boundingBox = QgsRectangle(), int width = 0, int height = 0, int dpi = 96 );
321 
331  virtual QString lastErrorTitle() = 0;
332 
342  virtual QString lastError() = 0;
343 
345  virtual QString lastErrorFormat();
346 
348  int dpi() const { return mDpi; }
349 
351  void setDpi( int dpi ) { mDpi = dpi; }
352 
354  virtual QDateTime timestamp() const override { return mTimestamp; }
355 
357  virtual QDateTime dataTimestamp() const override { return QDateTime(); }
358 
364  virtual bool isEditable() const { return false; }
365 
375  virtual bool setEditable( bool enabled ) { Q_UNUSED( enabled ); return false; }
376 
378  // TODO: add data type (may be defferent from band type)
379  virtual bool write( void *data, int band, int width, int height, int xOffset, int yOffset )
380  {
381  Q_UNUSED( data );
382  Q_UNUSED( band );
383  Q_UNUSED( width );
384  Q_UNUSED( height );
385  Q_UNUSED( xOffset );
386  Q_UNUSED( yOffset );
387  return false;
388  }
389 
405  bool writeBlock( QgsRasterBlock *block, int band, int xOffset = 0, int yOffset = 0 );
406 
408  static QgsRasterDataProvider *create( const QString &providerKey,
409  const QString &uri,
410  const QString &format, int nBands,
411  Qgis::DataType type,
412  int width, int height, double *geoTransform,
413  const QgsCoordinateReferenceSystem &crs,
414  const QStringList &createOptions = QStringList() );
415 
420  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
421 
423  virtual bool remove() { return false; }
424 
428  static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString &providerKey );
429 
434  virtual QString validateCreationOptions( const QStringList &createOptions, const QString &format )
435  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
436 
441  const QStringList &configOptions, const QString &fileFormat )
442  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( configOptions ); Q_UNUSED( fileFormat ); return QString(); }
443 
444  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
445  static QgsRaster::IdentifyFormat identifyFormatFromName( const QString &formatName );
446  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
447  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
448 
455 
462 
463  signals:
464 
468  void statusChanged( const QString & ) const;
469 
470  protected:
471 
475  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data ) SIP_SKIP
476  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
477 
481  virtual void readBlock( int bandNo, QgsRectangle const &viewExtent, int width, int height, void *data, QgsRasterBlockFeedback *feedback = nullptr ) SIP_SKIP
482  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); Q_UNUSED( feedback ); }
483 
485  bool userNoDataValuesContains( int bandNo, double value ) const;
486 
488  void copyBaseSettings( const QgsRasterDataProvider &other );
489 
491  static QStringList cStringList2Q_( char **stringList ) SIP_SKIP;
492 
493  static QString makeTableCell( const QString &value );
494  static QString makeTableCells( const QStringList &values );
495 
498  int mDpi;
499 
502  //bool hasNoDataValue ( int bandNo );
503 
505  QList<double> mSrcNoDataValue;
506 
508  QList<bool> mSrcHasNoDataValue;
509 
513  QList<bool> mUseSrcNoDataValue;
514 
517  QList< QgsRasterRangeList > mUserNoDataValue;
518 
520 
521 };
522 #endif
virtual void readBlock(int bandNo, int xBlock, int yBlock, void *data)
Read block of data.
IdentifyFormat
Definition: qgsraster.h:73
A rectangle specified with double values.
Definition: qgsrectangle.h:38
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:62
Handles asynchronous download of images.
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
virtual double bandOffset(int bandNo) const
Read band offset for raster value.
QDateTime mTimestamp
Timestamp of data in the moment when the data were loaded by provider.
DataType
Raster data types.
Definition: qgis.h:64
virtual QgsImageFetcher * getLegendGraphicFetcher(const QgsMapSettings *mapSettings)
Get an image downloader for the raster legend.
Red band of RGBA image.
Definition: qgsraster.h:42
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 bool supportsLegendGraphic() const
Returns whether the provider supplies a legend graphic.
virtual bool setNoDataValue(int bandNo, double noDataValue)
Set no data value on created dataset.
Abstract base class for spatial data provider implementations.
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
virtual QString buildPyramids(const QList< QgsRasterPyramid > &pyramidList, const QString &resamplingMethod="NEAREST", QgsRaster::RasterPyramidsFormat format=QgsRaster::PyramidsGTiff, const QStringList &configOptions=QStringList(), QgsRasterBlockFeedback *feedback=nullptr)
Create pyramid overviews.
Hue band of HLS image.
Definition: qgsraster.h:50
virtual double sourceNoDataValue(int bandNo) const
Value representing no data value.
virtual QString validatePyramidsConfigOptions(QgsRaster::RasterPyramidsFormat pyramidsFormat, const QStringList &configOptions, const QString &fileFormat)
Validates pyramid creation options for a specific dataset and destination format. ...
The QgsMapSettings class contains configuration for rendering of the map.
Raster identify results container.
Lightness band of HLS image.
Definition: qgsraster.h:54
int dpi() const
Returns the dpi of the output device.
virtual bool setEditable(bool enabled)
Turns on/off editing mode of the provider.
Paletted (see associated color table)
Definition: qgsraster.h:40
Alpha (0=transparent, 255=opaque)
Definition: qgsraster.h:48
Raster data container.
Green band of RGBA image.
Definition: qgsraster.h:44
virtual QList< QgsRasterPyramid > buildPyramidList(QList< int > overviewList=QList< int >())
Accessor for the raster layers pyramid list.
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)=0
Read block of data using given extent and size.
#define SIP_SKIP
Definition: qgis_sip.h:102
Y Luminance.
Definition: qgsraster.h:64
virtual QStringList subLayers() const override
Returns the sublayers of this layer - useful for providers that manage their own layers, such as WMS.
static const int DEFAULT_MAXIMUM_TILE_HEIGHT
virtual bool reload()
Reload data (data could change)
QList< bool > mSrcHasNoDataValue
Source no data value exists.
virtual QString colorInterpretationName(int bandNo) const
virtual Qgis::DataType sourceDataType(int bandNo) const
Returns source data type for the band specified by number, source data type may be shorter than dataT...
#define SIP_FACTORY
Definition: qgis_sip.h:57
virtual void readBlock(int bandNo, QgsRectangle const &viewExtent, int width, int height, void *data, QgsRasterBlockFeedback *feedback=nullptr)
Read block of data using give extent and size.
Base class for processing filters like renderers, reprojector, resampler etc.
virtual bool isEditable() const
Checks whether the provider is in editing mode, i.e.
A class to represent a point.
Definition: qgspoint.h:37
virtual bool sourceHasNoDataValue(int bandNo) const
Return true if source band has no data value.
Saturation band of HLS image.
Definition: qgsraster.h:52
QList< double > mSrcNoDataValue
Source no data value is available and is set to be used or internal no data is available.
virtual int stepHeight() const
Step height for raster iterations.
Blue band of RGBA image.
Definition: qgsraster.h:46
QString colorName(int colorInterpretation) const
QList< QgsRasterRange > QgsRasterRangeList
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
This class represents a coordinate reference system (CRS).
Greyscale.
Definition: qgsraster.h:38
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Get list of user no data value ranges.
virtual int stepWidth() const
Step width for raster iterations.
Magenta band of CMYK image.
Definition: qgsraster.h:58
virtual QString validateCreationOptions(const QStringList &createOptions, const QString &format)
Validates creation options for a specific dataset and destination format.
virtual QgsRectangle extent() const =0
Returns the extent of the layer.
virtual bool write(void *data, int band, int width, int height, int xOffset, int yOffset)
Writes into the provider datasource.
virtual bool useSourceNoDataValue(int bandNo) const
Get source nodata value usage.
RasterPyramidsFormat
Definition: qgsraster.h:97
Feedback object tailored for raster block reading.
static const int DEFAULT_MAXIMUM_TILE_WIDTH
void setDpi(int dpi)
Sets the output device resolution.
Cyan band of CMYK image.
Definition: qgsraster.h:56
virtual QDateTime dataTimestamp() const override
Current time stamp of data source.
QgsImageFetcher(QObject *parent=0)
Constructor.
virtual int colorInterpretation(int bandNo) const
Returns data type for the band specified by number.
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...
QList< bool > mUseSrcNoDataValue
Use source nodata value.
Yellow band of CMYK image.
Definition: qgsraster.h:60
virtual double bandScale(int bandNo) const
Read band scale for raster value.