QGIS API Documentation  2.99.0-Master (716ff6c)
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 <cmath>
28 
29 #include <QDateTime>
30 #include <QVariant>
31 #include <QImage>
32 
33 #include "qgscolorrampshader.h"
34 #include "qgsdataprovider.h"
35 #include "qgsfields.h"
36 #include "qgsraster.h"
37 #include "qgsrasterinterface.h"
38 #include "qgsrasterpyramid.h"
39 #include "qgsrasterrange.h"
40 #include "qgsrectangle.h"
41 #include "qgsrasteriterator.h"
42 
43 class QImage;
44 class QByteArray;
45 
46 class QgsPoint;
48 class QgsMapSettings;
49 
55 class CORE_EXPORT QgsImageFetcher : public QObject
56 {
57  Q_OBJECT
58  public:
60  QgsImageFetcher( QObject *parent = 0 ) : QObject( parent ) {}
61 
64  virtual void start() = 0;
65 
66  signals:
67 
70  void finish( const QImage &legend );
72  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 
90  virtual QgsRasterInterface *clone() const override = 0;
91 
92  /* It makes no sense to set input on provider */
93  bool setInput( QgsRasterInterface *input ) override { Q_UNUSED( input ); return false; }
94 
95  virtual QgsRectangle extent() const override = 0;
96 
98  virtual Qgis::DataType dataType( int bandNo ) const override = 0;
99 
103  virtual Qgis::DataType sourceDataType( int bandNo ) const override = 0;
104 
106  virtual int colorInterpretation( int bandNo ) const
107  {
108  Q_UNUSED( bandNo );
110  }
111 
112  QString colorName( int colorInterpretation ) const
113  {
114  // Modified copy from GDAL
115  switch ( colorInterpretation )
116  {
118  return QStringLiteral( "Undefined" );
119 
121  return QStringLiteral( "Gray" );
122 
124  return QStringLiteral( "Palette" );
125 
126  case QgsRaster::RedBand:
127  return QStringLiteral( "Red" );
128 
130  return QStringLiteral( "Green" );
131 
132  case QgsRaster::BlueBand:
133  return QStringLiteral( "Blue" );
134 
136  return QStringLiteral( "Alpha" );
137 
138  case QgsRaster::HueBand:
139  return QStringLiteral( "Hue" );
140 
142  return QStringLiteral( "Saturation" );
143 
145  return QStringLiteral( "Lightness" );
146 
147  case QgsRaster::CyanBand:
148  return QStringLiteral( "Cyan" );
149 
151  return QStringLiteral( "Magenta" );
152 
154  return QStringLiteral( "Yellow" );
155 
157  return QStringLiteral( "Black" );
158 
160  return QStringLiteral( "YCbCr_Y" );
161 
163  return QStringLiteral( "YCbCr_Cb" );
164 
166  return QStringLiteral( "YCbCr_Cr" );
167 
168  default:
169  return QStringLiteral( "Unknown" );
170  }
171  }
173  virtual bool reload() { return true; }
174 
175  virtual QString colorInterpretationName( int bandNo ) const
176  {
177  return colorName( colorInterpretation( bandNo ) );
178  }
179 
183  virtual double bandScale( int bandNo ) const { Q_UNUSED( bandNo ); return 1.0; }
184 
188  virtual double bandOffset( int bandNo ) const { Q_UNUSED( bandNo ); return 0.0; }
189 
190  // TODO: remove or make protected all readBlock working with void*
191 
193  virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override;
194 
196  virtual bool sourceHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo - 1 ); }
197 
199  virtual bool useSourceNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo - 1 ); }
200 
202  virtual void setUseSourceNoDataValue( int bandNo, bool use );
203 
205  virtual double sourceNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo - 1 ); }
206 
207  virtual void setUserNoDataValue( int bandNo, const QgsRasterRangeList &noData );
208 
210  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo - 1 ); }
211 
212  virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
213  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
214 
217  virtual QStringList subLayers() const override
218  {
219  return QStringList();
220  }
221 
223  virtual bool supportsLegendGraphic() const { return false; }
224 
234  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle *visibleExtent = nullptr )
235  {
236  Q_UNUSED( scale );
237  Q_UNUSED( forceRefresh );
238  Q_UNUSED( visibleExtent );
239  return QImage();
240  }
241 
256  {
257  Q_UNUSED( mapSettings );
258  return nullptr;
259  }
260 
262  virtual QString buildPyramids( const QList<QgsRasterPyramid> &pyramidList,
263  const QString &resamplingMethod = "NEAREST",
265  const QStringList &configOptions = QStringList(),
266  QgsRasterBlockFeedback *feedback = nullptr )
267  {
268  Q_UNUSED( pyramidList );
269  Q_UNUSED( resamplingMethod );
270  Q_UNUSED( format );
271  Q_UNUSED( configOptions );
272  Q_UNUSED( feedback );
273  return QStringLiteral( "FAILED_NOT_SUPPORTED" );
274  }
275 
283  virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() ) // clazy:exclude=function-args-by-ref
284  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }
285 
287  bool hasPyramids();
288 
293  virtual QString metadata() = 0;
294 
318  //virtual QMap<int, QVariant> identify( const QgsPoint & point, QgsRaster::IdentifyFormat format, const QgsRectangle &extent = QgsRectangle(), int width = 0, int height = 0 );
319  virtual QgsRasterIdentifyResult identify( const QgsPoint &point, QgsRaster::IdentifyFormat format, const QgsRectangle &boundingBox = QgsRectangle(), int width = 0, int height = 0, int dpi = 96 );
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 
363  virtual bool isEditable() const { return false; }
364 
374  virtual bool setEditable( bool enabled ) { Q_UNUSED( enabled ); return false; }
375 
377  // TODO: add data type (may be defferent from band type)
378  virtual bool write( void *data, int band, int width, int height, int xOffset, int yOffset )
379  {
380  Q_UNUSED( data );
381  Q_UNUSED( band );
382  Q_UNUSED( width );
383  Q_UNUSED( height );
384  Q_UNUSED( xOffset );
385  Q_UNUSED( yOffset );
386  return false;
387  }
388 
404  bool writeBlock( QgsRasterBlock *block, int band, int xOffset = 0, int yOffset = 0 );
405 
407  static QgsRasterDataProvider *create( const QString &providerKey,
408  const QString &uri,
409  const QString &format, int nBands,
410  Qgis::DataType type,
411  int width, int height, double *geoTransform,
412  const QgsCoordinateReferenceSystem &crs,
413  const QStringList &createOptions = QStringList() );
414 
419  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
420 
422  virtual bool remove() { return false; }
423 
427  static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString &providerKey );
428 
433  virtual QString validateCreationOptions( const QStringList &createOptions, const QString &format )
434  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
435 
440  const QStringList &configOptions, const QString &fileFormat )
441  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( configOptions ); Q_UNUSED( fileFormat ); return QString(); }
442 
443  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
444  static QgsRaster::IdentifyFormat identifyFormatFromName( const QString &formatName );
445  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
446  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
447 
454 
461 
462  signals:
463 
467  void statusChanged( const QString & ) const;
468 
469  protected:
470 
474  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
475  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
476 
480  virtual void readBlock( int bandNo, QgsRectangle const &viewExtent, int width, int height, void *data, QgsRasterBlockFeedback *feedback = nullptr )
481  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); Q_UNUSED( feedback ); }
482 
484  bool userNoDataValuesContains( int bandNo, double value ) const;
485 
487  void copyBaseSettings( const QgsRasterDataProvider &other );
488 
490  static QStringList cStringList2Q_( char **stringList );
491 
492  static QString makeTableCell( const QString &value );
493  static QString makeTableCells( const QStringList &values );
494 
497  int mDpi;
498 
501  //bool hasNoDataValue ( int bandNo );
502 
504  QList<double> mSrcNoDataValue;
505 
507  QList<bool> mSrcHasNoDataValue;
508 
512  QList<bool> mUseSrcNoDataValue;
513 
516  QList< QgsRasterRangeList > mUserNoDataValue;
517 
519 
520 };
521 #endif
virtual void readBlock(int bandNo, int xBlock, int yBlock, void *data)
Read block of data.
IdentifyFormat
Definition: qgsraster.h:72
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:61
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:61
virtual QgsImageFetcher * getLegendGraphicFetcher(const QgsMapSettings *mapSettings)
Get an image downloader for the raster legend.
Red band of RGBA image.
Definition: qgsraster.h:41
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:49
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:53
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:39
Alpha (0=transparent, 255=opaque)
Definition: qgsraster.h:47
Raster data container.
Green band of RGBA image.
Definition: qgsraster.h:43
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.
Y Luminance.
Definition: qgsraster.h:63
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...
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:51
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:45
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:37
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:57
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:96
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:55
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:59
virtual double bandScale(int bandNo) const
Read band scale for raster value.