QGIS API Documentation  2.99.0-Master (37c43df)
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"
33 #include "qgsdataprovider.h"
34 #include "qgsfields.h"
35 #include "qgsraster.h"
36 #include "qgsrasterinterface.h"
37 #include "qgsrasterpyramid.h"
38 #include "qgsrasterrange.h"
39 #include "qgsrectangle.h"
40 
41 class QImage;
42 class QByteArray;
43 
44 class QgsPoint;
46 class QgsMapSettings;
47 
53 class CORE_EXPORT QgsImageFetcher : public QObject
54 {
55  Q_OBJECT
56  public:
58  QgsImageFetcher( QObject* parent = 0 ) : QObject( parent ) {}
60  virtual ~QgsImageFetcher() {}
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 
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 
106  virtual QgsRectangle extent() const override = 0;
107 
109  virtual Qgis::DataType dataType( int bandNo ) const override = 0;
110 
114  virtual Qgis::DataType sourceDataType( int bandNo ) const override = 0;
115 
117  virtual int colorInterpretation( int theBandNo ) const
118  {
119  Q_UNUSED( theBandNo );
121  }
122 
123  QString colorName( int colorInterpretation ) const
124  {
125  // Modified copy from GDAL
126  switch ( colorInterpretation )
127  {
129  return QStringLiteral( "Undefined" );
130 
132  return QStringLiteral( "Gray" );
133 
135  return QStringLiteral( "Palette" );
136 
137  case QgsRaster::RedBand:
138  return QStringLiteral( "Red" );
139 
141  return QStringLiteral( "Green" );
142 
143  case QgsRaster::BlueBand:
144  return QStringLiteral( "Blue" );
145 
147  return QStringLiteral( "Alpha" );
148 
149  case QgsRaster::HueBand:
150  return QStringLiteral( "Hue" );
151 
153  return QStringLiteral( "Saturation" );
154 
156  return QStringLiteral( "Lightness" );
157 
158  case QgsRaster::CyanBand:
159  return QStringLiteral( "Cyan" );
160 
162  return QStringLiteral( "Magenta" );
163 
165  return QStringLiteral( "Yellow" );
166 
168  return QStringLiteral( "Black" );
169 
171  return QStringLiteral( "YCbCr_Y" );
172 
174  return QStringLiteral( "YCbCr_Cb" );
175 
177  return QStringLiteral( "YCbCr_Cr" );
178 
179  default:
180  return QStringLiteral( "Unknown" );
181  }
182  }
184  virtual bool reload() { return true; }
185 
186  virtual QString colorInterpretationName( int theBandNo ) const
187  {
188  return colorName( colorInterpretation( theBandNo ) );
189  }
190 
194  virtual double bandScale( int bandNo ) const { Q_UNUSED( bandNo ); return 1.0; }
195 
199  virtual double bandOffset( int bandNo ) const { Q_UNUSED( bandNo ); return 0.0; }
200 
201  // TODO: remove or make protected all readBlock working with void*
202 
204  virtual QgsRasterBlock *block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight, QgsRasterBlockFeedback* feedback = nullptr ) override;
205 
207  virtual bool sourceHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo -1 ); }
208 
210  virtual bool useSourceNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo -1 ); }
211 
213  virtual void setUseSourceNoDataValue( int bandNo, bool use );
214 
216  virtual double sourceNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo -1 ); }
217 
218  virtual void setUserNoDataValue( int bandNo, const QgsRasterRangeList& noData );
219 
221  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
222 
223  virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
224  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
225 
228  virtual QStringList subLayers() const override
229  {
230  return QStringList();
231  }
232 
234  virtual bool supportsLegendGraphic() const { return false; }
235 
244  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle * visibleExtent = nullptr )
245  {
246  Q_UNUSED( scale );
247  Q_UNUSED( forceRefresh );
248  Q_UNUSED( visibleExtent );
249  return QImage();
250  }
251 
266  {
267  Q_UNUSED( mapSettings );
268  return nullptr;
269  }
270 
272  virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
273  const QString & theResamplingMethod = "NEAREST",
275  const QStringList & theConfigOptions = QStringList() )
276  {
277  Q_UNUSED( thePyramidList );
278  Q_UNUSED( theResamplingMethod );
279  Q_UNUSED( theFormat );
280  Q_UNUSED( theConfigOptions );
281  return QStringLiteral( "FAILED_NOT_SUPPORTED" );
282  }
283 
291  virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() ) // clazy:exclude=function-args-by-ref
292  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }
293 
295  bool hasPyramids();
296 
301  virtual QString metadata() = 0;
302 
326  //virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
327  virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0, int theDpi = 96 );
328 
338  virtual QString lastErrorTitle() = 0;
339 
349  virtual QString lastError() = 0;
350 
352  virtual QString lastErrorFormat();
353 
355  int dpi() const { return mDpi; }
356 
358  void setDpi( int dpi ) { mDpi = dpi; }
359 
361  virtual QDateTime timestamp() const override { return mTimestamp; }
362 
364  virtual QDateTime dataTimestamp() const override { return QDateTime(); }
365 
367  // TODO: add data type (may be defferent from band type)
368  virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
369  {
370  Q_UNUSED( data );
371  Q_UNUSED( band );
372  Q_UNUSED( width );
373  Q_UNUSED( height );
374  Q_UNUSED( xOffset );
375  Q_UNUSED( yOffset );
376  return false;
377  }
378 
380  static QgsRasterDataProvider* create( const QString &providerKey,
381  const QString &uri,
382  const QString& format, int nBands,
383  Qgis::DataType type,
384  int width, int height, double* geoTransform,
385  const QgsCoordinateReferenceSystem& crs,
386  const QStringList& createOptions = QStringList() );
387 
392  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
393 
395  virtual bool remove() { return false; }
396 
400  static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString& providerKey );
401 
406  virtual QString validateCreationOptions( const QStringList& createOptions, const QString& format )
407  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
408 
413  const QStringList & theConfigOptions, const QString & fileFormat )
414  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
415 
416  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
417  static QgsRaster::IdentifyFormat identifyFormatFromName( const QString& formatName );
418  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
419  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
420 
421  signals:
422 
425  void progress( int theType, double theProgress, const QString& theMessage );
426  void progressUpdate( int theProgress );
427 
431  void statusChanged( const QString& ) const;
432 
433  protected:
434 
438  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
439  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
440 
444  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data, QgsRasterBlockFeedback* feedback = nullptr )
445  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); Q_UNUSED( feedback ); }
446 
448  bool userNoDataValuesContains( int bandNo, double value ) const;
449 
451  void copyBaseSettings( const QgsRasterDataProvider& other );
452 
454  static QStringList cStringList2Q_( char ** stringList );
455 
456  static QString makeTableCell( const QString & value );
457  static QString makeTableCells( const QStringList & values );
458 
461  int mDpi;
462 
465  //bool hasNoDataValue ( int theBandNo );
466 
468  QList<double> mSrcNoDataValue;
469 
471  QList<bool> mSrcHasNoDataValue;
472 
476  QList<bool> mUseSrcNoDataValue;
477 
480  QList< QgsRasterRangeList > mUserNoDataValue;
481 
483 
484  static QStringList mPyramidResamplingListGdal;
486 
487 };
488 #endif
virtual void readBlock(int bandNo, int xBlock, int yBlock, void *data)
Read block of data.
IdentifyFormat
Definition: qgsraster.h:71
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:60
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
static QStringList mPyramidResamplingListGdal
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:60
virtual QgsImageFetcher * getLegendGraphicFetcher(const QgsMapSettings *mapSettings)
Get an image downloader for the raster legend.
Red band of RGBA image.
Definition: qgsraster.h:40
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:48
QMap< QString, QString > QgsStringMap
Definition: qgis.h:328
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:52
int dpi() const
Returns the dpi of the output device.
Paletted (see associated color table)
Definition: qgsraster.h:38
Alpha (0=transparent, 255=opaque)
Definition: qgsraster.h:46
Raster data container.
Green band of RGBA image.
Definition: qgsraster.h:42
virtual QList< QgsRasterPyramid > buildPyramidList(QList< int > overviewList=QList< int >())
Accessor for ths 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:62
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.
A class to represent a point.
Definition: qgspoint.h:111
virtual bool sourceHasNoDataValue(int bandNo) const
Return true if source band has no data value.
Saturation band of HLS image.
Definition: qgsraster.h:50
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:44
QString colorName(int colorInterpretation) const
QList< QgsRasterRange > QgsRasterRangeList
virtual ~QgsImageFetcher()
Destructor.
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
This class represents a coordinate reference system (CRS).
Greyscale.
Definition: qgsraster.h:36
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:56
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:95
Feedback object tailored for raster block reading.
void setDpi(int dpi)
Sets the output device resolution.
Cyan band of CMYK image.
Definition: qgsraster.h:54
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...
static QgsStringMap mPyramidResamplingMapGdal
QList< bool > mUseSrcNoDataValue
Use source nodata value.
Yellow band of CMYK image.
Definition: qgsraster.h:58
virtual double bandScale(int bandNo) const
Read band scale for raster value.