QGIS API Documentation  2.99.0-Master (08c2e66)
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 
233  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle * visibleExtent = nullptr )
234  {
235  Q_UNUSED( scale );
236  Q_UNUSED( forceRefresh );
237  Q_UNUSED( visibleExtent );
238  return QImage();
239  }
240 
255  {
256  Q_UNUSED( mapSettings );
257  return nullptr;
258  }
259 
261  virtual QString buildPyramids( const QList<QgsRasterPyramid> & pyramidList,
262  const QString & resamplingMethod = "NEAREST",
264  const QStringList & configOptions = QStringList() )
265  {
266  Q_UNUSED( pyramidList );
267  Q_UNUSED( resamplingMethod );
268  Q_UNUSED( format );
269  Q_UNUSED( configOptions );
270  return QStringLiteral( "FAILED_NOT_SUPPORTED" );
271  }
272 
280  virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() ) // clazy:exclude=function-args-by-ref
281  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }
282 
284  bool hasPyramids();
285 
290  virtual QString metadata() = 0;
291 
315  //virtual QMap<int, QVariant> identify( const QgsPoint & point, QgsRaster::IdentifyFormat format, const QgsRectangle &extent = QgsRectangle(), int width = 0, int height = 0 );
316  virtual QgsRasterIdentifyResult identify( const QgsPoint & point, QgsRaster::IdentifyFormat format, const QgsRectangle &boundingBox = QgsRectangle(), int width = 0, int height = 0, int dpi = 96 );
317 
327  virtual QString lastErrorTitle() = 0;
328 
338  virtual QString lastError() = 0;
339 
341  virtual QString lastErrorFormat();
342 
344  int dpi() const { return mDpi; }
345 
347  void setDpi( int dpi ) { mDpi = dpi; }
348 
350  virtual QDateTime timestamp() const override { return mTimestamp; }
351 
353  virtual QDateTime dataTimestamp() const override { return QDateTime(); }
354 
360  virtual bool isEditable() const { return false; }
361 
371  virtual bool setEditable( bool enabled ) { Q_UNUSED( enabled ); return false; }
372 
374  // TODO: add data type (may be defferent from band type)
375  virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
376  {
377  Q_UNUSED( data );
378  Q_UNUSED( band );
379  Q_UNUSED( width );
380  Q_UNUSED( height );
381  Q_UNUSED( xOffset );
382  Q_UNUSED( yOffset );
383  return false;
384  }
385 
401  bool writeBlock( QgsRasterBlock* block, int band, int xOffset = 0, int yOffset = 0 );
402 
404  static QgsRasterDataProvider* create( const QString &providerKey,
405  const QString &uri,
406  const QString& format, int nBands,
407  Qgis::DataType type,
408  int width, int height, double* geoTransform,
409  const QgsCoordinateReferenceSystem& crs,
410  const QStringList& createOptions = QStringList() );
411 
416  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
417 
419  virtual bool remove() { return false; }
420 
424  static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString& providerKey );
425 
430  virtual QString validateCreationOptions( const QStringList& createOptions, const QString& format )
431  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
432 
437  const QStringList & configOptions, const QString & fileFormat )
438  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( configOptions ); Q_UNUSED( fileFormat ); return QString(); }
439 
440  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
441  static QgsRaster::IdentifyFormat identifyFormatFromName( const QString& formatName );
442  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
443  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
444 
451 
458 
459  signals:
460 
463  void progress( int type, double progress, const QString& message );
464  void progressUpdate( int progress );
465 
469  void statusChanged( const QString& ) const;
470 
471  protected:
472 
476  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
477  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
478 
482  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data, QgsRasterBlockFeedback* feedback = nullptr )
483  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); Q_UNUSED( feedback ); }
484 
486  bool userNoDataValuesContains( int bandNo, double value ) const;
487 
489  void copyBaseSettings( const QgsRasterDataProvider& other );
490 
492  static QStringList cStringList2Q_( char ** stringList );
493 
494  static QString makeTableCell( const QString & value );
495  static QString makeTableCells( const QStringList & values );
496 
499  int mDpi;
500 
503  //bool hasNoDataValue ( int bandNo );
504 
506  QList<double> mSrcNoDataValue;
507 
509  QList<bool> mSrcHasNoDataValue;
510 
514  QList<bool> mUseSrcNoDataValue;
515 
518  QList< QgsRasterRangeList > mUserNoDataValue;
519 
521 
522 };
523 #endif
virtual bool supportsLegendGraphic() const
Returns whether the provider supplies a legend graphic.
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:36
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
virtual bool useSourceNoDataValue(int bandNo) const
Get source nodata value usage.
Handles asynchronous download of images.
virtual QString colorInterpretationName(int bandNo) const
virtual double bandOffset(int bandNo) const
Read band offset for raster value.
virtual int colorInterpretation(int bandNo) const
Returns data type for the band specified by number.
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 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.
virtual Qgis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
Hue band of HLS image.
Definition: qgsraster.h:49
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.
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 int stepWidth() const
Step width for raster iterations.
Raster identify results container.
virtual bool sourceHasNoDataValue(int bandNo) const
Return true if source band has no data value.
Lightness band of HLS image.
Definition: qgsraster.h:53
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 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.
A class to represent a point.
Definition: qgspoint.h:143
virtual double sourceNoDataValue(int bandNo) const
Value representing 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.
virtual double bandScale(int bandNo) const
Read band scale for raster value.
Blue band of RGBA image.
Definition: qgsraster.h:45
QString colorName(int colorInterpretation) const
QList< QgsRasterRange > QgsRasterRangeList
virtual bool isEditable() const
Checks whether the provider is in editing mode, i.e.
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
This class represents a coordinate reference system (CRS).
Greyscale.
Definition: qgsraster.h:37
virtual QString buildPyramids(const QList< QgsRasterPyramid > &pyramidList, const QString &resamplingMethod="NEAREST", QgsRaster::RasterPyramidsFormat format=QgsRaster::PyramidsGTiff, const QStringList &configOptions=QStringList())
Create pyramid overviews.
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.
int dpi() const
Returns the dpi of the output device.
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
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.
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