QGIS API Documentation  2.99.0-Master (5753576)
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 
42 class QImage;
43 class QByteArray;
44 
45 class QgsPoint;
47 class QgsMapSettings;
48 
54 class CORE_EXPORT QgsImageFetcher : public QObject
55 {
56  Q_OBJECT
57  public:
59  QgsImageFetcher( QObject* parent = 0 ) : QObject( parent ) {}
60 
63  virtual void start() = 0;
64 
65  signals:
66 
69  void finish( const QImage& legend );
71  void progress( qint64 received, qint64 total );
73  void error( const QString& msg );
74 };
75 
76 
80 class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRasterInterface
81 {
82  Q_OBJECT
83 
84  public:
86 
87  QgsRasterDataProvider( const QString & uri );
88 
89  virtual QgsRasterInterface * clone() const override = 0;
90 
91  /* It makes no sense to set input on provider */
92  bool setInput( QgsRasterInterface* input ) override { Q_UNUSED( input ); return false; }
93 
94  virtual QgsRectangle extent() const override = 0;
95 
97  virtual Qgis::DataType dataType( int bandNo ) const override = 0;
98 
102  virtual Qgis::DataType sourceDataType( int bandNo ) const override = 0;
103 
105  virtual int colorInterpretation( int theBandNo ) const
106  {
107  Q_UNUSED( theBandNo );
109  }
110 
111  QString colorName( int colorInterpretation ) const
112  {
113  // Modified copy from GDAL
114  switch ( colorInterpretation )
115  {
117  return QStringLiteral( "Undefined" );
118 
120  return QStringLiteral( "Gray" );
121 
123  return QStringLiteral( "Palette" );
124 
125  case QgsRaster::RedBand:
126  return QStringLiteral( "Red" );
127 
129  return QStringLiteral( "Green" );
130 
131  case QgsRaster::BlueBand:
132  return QStringLiteral( "Blue" );
133 
135  return QStringLiteral( "Alpha" );
136 
137  case QgsRaster::HueBand:
138  return QStringLiteral( "Hue" );
139 
141  return QStringLiteral( "Saturation" );
142 
144  return QStringLiteral( "Lightness" );
145 
146  case QgsRaster::CyanBand:
147  return QStringLiteral( "Cyan" );
148 
150  return QStringLiteral( "Magenta" );
151 
153  return QStringLiteral( "Yellow" );
154 
156  return QStringLiteral( "Black" );
157 
159  return QStringLiteral( "YCbCr_Y" );
160 
162  return QStringLiteral( "YCbCr_Cb" );
163 
165  return QStringLiteral( "YCbCr_Cr" );
166 
167  default:
168  return QStringLiteral( "Unknown" );
169  }
170  }
172  virtual bool reload() { return true; }
173 
174  virtual QString colorInterpretationName( int theBandNo ) const
175  {
176  return colorName( colorInterpretation( theBandNo ) );
177  }
178 
182  virtual double bandScale( int bandNo ) const { Q_UNUSED( bandNo ); return 1.0; }
183 
187  virtual double bandOffset( int bandNo ) const { Q_UNUSED( bandNo ); return 0.0; }
188 
189  // TODO: remove or make protected all readBlock working with void*
190 
192  virtual QgsRasterBlock *block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight, QgsRasterBlockFeedback* feedback = nullptr ) override;
193 
195  virtual bool sourceHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo -1 ); }
196 
198  virtual bool useSourceNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo -1 ); }
199 
201  virtual void setUseSourceNoDataValue( int bandNo, bool use );
202 
204  virtual double sourceNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo -1 ); }
205 
206  virtual void setUserNoDataValue( int bandNo, const QgsRasterRangeList& noData );
207 
209  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
210 
211  virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
212  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
213 
216  virtual QStringList subLayers() const override
217  {
218  return QStringList();
219  }
220 
222  virtual bool supportsLegendGraphic() const { return false; }
223 
232  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle * visibleExtent = nullptr )
233  {
234  Q_UNUSED( scale );
235  Q_UNUSED( forceRefresh );
236  Q_UNUSED( visibleExtent );
237  return QImage();
238  }
239 
254  {
255  Q_UNUSED( mapSettings );
256  return nullptr;
257  }
258 
260  virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
261  const QString & theResamplingMethod = "NEAREST",
263  const QStringList & theConfigOptions = QStringList() )
264  {
265  Q_UNUSED( thePyramidList );
266  Q_UNUSED( theResamplingMethod );
267  Q_UNUSED( theFormat );
268  Q_UNUSED( theConfigOptions );
269  return QStringLiteral( "FAILED_NOT_SUPPORTED" );
270  }
271 
279  virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() ) // clazy:exclude=function-args-by-ref
280  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }
281 
283  bool hasPyramids();
284 
289  virtual QString metadata() = 0;
290 
314  //virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
315  virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0, int theDpi = 96 );
316 
326  virtual QString lastErrorTitle() = 0;
327 
337  virtual QString lastError() = 0;
338 
340  virtual QString lastErrorFormat();
341 
343  int dpi() const { return mDpi; }
344 
346  void setDpi( int dpi ) { mDpi = dpi; }
347 
349  virtual QDateTime timestamp() const override { return mTimestamp; }
350 
352  virtual QDateTime dataTimestamp() const override { return QDateTime(); }
353 
359  virtual bool isEditable() const { return false; }
360 
370  virtual bool setEditable( bool enabled ) { Q_UNUSED( enabled ); return false; }
371 
373  // TODO: add data type (may be defferent from band type)
374  virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
375  {
376  Q_UNUSED( data );
377  Q_UNUSED( band );
378  Q_UNUSED( width );
379  Q_UNUSED( height );
380  Q_UNUSED( xOffset );
381  Q_UNUSED( yOffset );
382  return false;
383  }
384 
400  bool writeBlock( QgsRasterBlock* block, int band, int xOffset = 0, int yOffset = 0 );
401 
403  static QgsRasterDataProvider* create( const QString &providerKey,
404  const QString &uri,
405  const QString& format, int nBands,
406  Qgis::DataType type,
407  int width, int height, double* geoTransform,
408  const QgsCoordinateReferenceSystem& crs,
409  const QStringList& createOptions = QStringList() );
410 
415  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
416 
418  virtual bool remove() { return false; }
419 
423  static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString& providerKey );
424 
429  virtual QString validateCreationOptions( const QStringList& createOptions, const QString& format )
430  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
431 
436  const QStringList & theConfigOptions, const QString & fileFormat )
437  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
438 
439  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
440  static QgsRaster::IdentifyFormat identifyFormatFromName( const QString& formatName );
441  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
442  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
443 
444  signals:
445 
448  void progress( int theType, double theProgress, const QString& theMessage );
449  void progressUpdate( int theProgress );
450 
454  void statusChanged( const QString& ) const;
455 
456  protected:
457 
461  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
462  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
463 
467  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data, QgsRasterBlockFeedback* feedback = nullptr )
468  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); Q_UNUSED( feedback ); }
469 
471  bool userNoDataValuesContains( int bandNo, double value ) const;
472 
474  void copyBaseSettings( const QgsRasterDataProvider& other );
475 
477  static QStringList cStringList2Q_( char ** stringList );
478 
479  static QString makeTableCell( const QString & value );
480  static QString makeTableCells( const QStringList & values );
481 
484  int mDpi;
485 
488  //bool hasNoDataValue ( int theBandNo );
489 
491  QList<double> mSrcNoDataValue;
492 
494  QList<bool> mSrcHasNoDataValue;
495 
499  QList<bool> mUseSrcNoDataValue;
500 
503  QList< QgsRasterRangeList > mUserNoDataValue;
504 
506 
507 };
508 #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: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
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. ...
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.
Hue band of HLS image.
Definition: qgsraster.h:49
virtual double sourceNoDataValue(int bandNo) const
Value representing no data value.
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.
virtual bool reload()
Reload data (data could change)
QList< bool > mSrcHasNoDataValue
Source no data value exists.
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:143
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 QString colorInterpretationName(int theBandNo) const
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 int colorInterpretation(int theBandNo) const
Returns data type for the band specified by number.
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Get list of user no data value ranges.
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: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.
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
virtual double bandScale(int bandNo) const
Read band scale for raster value.