QGIS API Documentation
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"
34 #include "qgsdataprovider.h"
35 #include "qgserror.h"
36 #include "qgsfeature.h"
37 #include "qgsfield.h"
38 #include "qgslogger.h"
39 #include "qgsrasterbandstats.h"
40 #include "qgsraster.h"
41 #include "qgsrasterhistogram.h"
42 #include "qgsrasterinterface.h"
43 #include "qgsrasterpyramid.h"
44 #include "qgsrasterrange.h"
45 #include "qgsrectangle.h"
46 
47 class QImage;
48 class QByteArray;
49 
50 class QgsPoint;
52 class QgsMapSettings;
53 
59 class CORE_EXPORT QgsImageFetcher : public QObject
60 {
61  Q_OBJECT
62  public:
63 
65  virtual ~QgsImageFetcher() {}
66 
67  // Make sure to connect to "finish" and "error" before starting
68  virtual void start() = 0;
69 
70  signals:
71 
72  void finish( const QImage& legend );
73  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 
109  virtual QgsRectangle extent() override = 0;
110 
112  virtual QGis::DataType dataType( int bandNo ) const override = 0;
113 
117  virtual QGis::DataType srcDataType( int bandNo ) const override = 0;
118 
120  virtual int colorInterpretation( int theBandNo ) const
121  {
122  Q_UNUSED( theBandNo );
124  }
125 
126  QString colorName( int colorInterpretation ) const
127  {
128  // Modified copy from GDAL
129  switch ( colorInterpretation )
130  {
132  return "Undefined";
133 
135  return "Gray";
136 
138  return "Palette";
139 
140  case QgsRaster::RedBand:
141  return "Red";
142 
144  return "Green";
145 
146  case QgsRaster::BlueBand:
147  return "Blue";
148 
150  return "Alpha";
151 
152  case QgsRaster::HueBand:
153  return "Hue";
154 
156  return "Saturation";
157 
159  return "Lightness";
160 
161  case QgsRaster::CyanBand:
162  return "Cyan";
163 
165  return "Magenta";
166 
168  return "Yellow";
169 
171  return "Black";
172 
174  return "YCbCr_Y";
175 
177  return "YCbCr_Cb";
178 
180  return "YCbCr_Cr";
181 
182  default:
183  return "Unknown";
184  }
185  }
187  virtual bool reload() { return true; }
188 
189  virtual QString colorInterpretationName( int theBandNo ) const
190  {
191  return colorName( colorInterpretation( theBandNo ) );
192  }
193 
197  virtual double bandScale( int bandNo ) const { Q_UNUSED( bandNo ); return 1.0; }
201  virtual double bandOffset( int bandNo ) const { Q_UNUSED( bandNo ); return 0.0; }
202 
203  // TODO: remove or make protected all readBlock working with void*
204 
206  virtual QgsRasterBlock *block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight ) override;
207 
209  virtual bool srcHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo -1 ); }
210 
212  virtual bool useSrcNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo -1 ); }
213 
215  virtual void setUseSrcNoDataValue( int bandNo, bool use );
216 
218  virtual double srcNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo -1 ); }
219 
220  virtual void setUserNoDataValue( int bandNo, const QgsRasterRangeList& noData );
221 
223  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
224 
226  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
227 
230  virtual QStringList subLayers() const override
231  {
232  return QStringList();
233  }
234 
243  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle * visibleExtent = nullptr )
244  {
245  Q_UNUSED( scale );
246  Q_UNUSED( forceRefresh );
247  Q_UNUSED( visibleExtent );
248  return QImage();
249  }
250 
265  {
266  Q_UNUSED( mapSettings );
267  return nullptr;
268  }
269 
271  virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
272  const QString & theResamplingMethod = "NEAREST",
274  const QStringList & theConfigOptions = QStringList() )
275  {
276  Q_UNUSED( thePyramidList );
277  Q_UNUSED( theResamplingMethod );
278  Q_UNUSED( theFormat );
279  Q_UNUSED( theConfigOptions );
280  return "FAILED_NOT_SUPPORTED";
281  }
282 
291  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }
292 
294  bool hasPyramids();
295 
300  virtual QString metadata() = 0;
301 
324  //virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
325  virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
326 
336  virtual QString lastErrorTitle() = 0;
337 
347  virtual QString lastError() = 0;
348 
350  virtual QString lastErrorFormat();
351 
353  int dpi() const { return mDpi; }
354 
356  void setDpi( int dpi ) { mDpi = dpi; }
357 
359  virtual QDateTime timestamp() const override { return mTimestamp; }
360 
362  virtual QDateTime dataTimestamp() const override { return QDateTime(); }
363 
365  // TODO: add data type (may be defferent from band type)
366  virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
367  {
368  Q_UNUSED( data );
369  Q_UNUSED( band );
370  Q_UNUSED( width );
371  Q_UNUSED( height );
372  Q_UNUSED( xOffset );
373  Q_UNUSED( yOffset );
374  return false;
375  }
376 
378  static QgsRasterDataProvider* create( const QString &providerKey,
379  const QString &uri,
380  const QString& format, int nBands,
381  QGis::DataType type,
382  int width, int height, double* geoTransform,
383  const QgsCoordinateReferenceSystem& crs,
384  const QStringList& createOptions = QStringList() );
385 
390  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
391 
393  virtual bool remove() { return false; }
394 
398  static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString& providerKey );
399 
404  virtual QString validateCreationOptions( const QStringList& createOptions, const QString& format )
405  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
406 
411  const QStringList & theConfigOptions, const QString & fileFormat )
412  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
413 
414  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
415  static QgsRaster::IdentifyFormat identifyFormatFromName( const QString& formatName );
416  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
417  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
418 
419  signals:
422  void progress( int theType, double theProgress, const QString& theMessage );
423  void progressUpdate( int theProgress );
424 
428  void statusChanged( const QString& );
429 
430  protected:
434  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
435  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
436 
440  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data )
441  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
442 
444  bool userNoDataValuesContains( int bandNo, double value ) const;
445 
447  void copyBaseSettings( const QgsRasterDataProvider& other );
448 
450  static QStringList cStringList2Q_( char ** stringList );
451 
452  static QString makeTableCell( const QString & value );
453  static QString makeTableCells( const QStringList & values );
454 
457  int mDpi;
458 
461  //bool hasNoDataValue ( int theBandNo );
462 
465 
468 
473 
477 
479 
482 
483 };
484 #endif
virtual void readBlock(int bandNo, int xBlock, int yBlock, void *data)
Read block of data.
IdentifyFormat
Definition: qgsraster.h:54
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:47
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. ...
static QStringList mPyramidResamplingListGdal
virtual double bandOffset(int bandNo) const
Read band offset for raster value.
virtual double srcNoDataValue(int bandNo) const
Value representing no data value.
QDateTime mTimestamp
Timestamp of data in the moment when the data were loaded by provider.
virtual QgsImageFetcher * getLegendGraphicFetcher(const QgsMapSettings *mapSettings)
Get an image downloader for the raster legend.
Red band of RGBA image.
Definition: qgsraster.h:37
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.
Hue band of HLS image.
Definition: qgsraster.h:41
T value(int i) const
The QgsMapSettings class contains configuration for rendering of the map.
virtual bool useSrcNoDataValue(int bandNo) const
Get source nodata value usage.
Raster identify results container.
Lightness band of HLS image.
Definition: qgsraster.h:43
Paletted (see associated color table)
Definition: qgsraster.h:36
Alpha (0=transparent, 255=opaque)
Definition: qgsraster.h:40
Raster data container.
virtual void readBlock(int bandNo, QgsRectangle const &viewExtent, int width, int height, void *data)
Read block of data using give extent and size.
Green band of RGBA image.
Definition: qgsraster.h:38
virtual QList< QgsRasterPyramid > buildPyramidList(QList< int > overviewList=QList< int >())
Accessor for ths raster layers pyramid list.
Y Luminance.
Definition: qgsraster.h:48
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 dataType(int bandNo) const =0
Returns data type for the band specified by number.
Base class for processing filters like renderers, reprojector, resampler etc.
A class to represent a point.
Definition: qgspoint.h:117
Saturation band of HLS image.
Definition: qgsraster.h:42
virtual QString colorInterpretationName(int theBandNo) const
QList< double > mSrcNoDataValue
Source no data value is available and is set to be used or internal no data is available.
virtual int colorInterpretation(int theBandNo) const
Returns data type for the band specified by number.
virtual double bandScale(int bandNo) const
Read band scale for raster value.
Blue band of RGBA image.
Definition: qgsraster.h:39
QString colorName(int colorInterpretation) const
virtual QgsRectangle extent()=0
Get the extent of the layer.
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
virtual QGis::DataType srcDataType(int bandNo) const
Returns source data type for the band specified by number, source data type may be shorter than dataT...
Class for storing a coordinate reference system (CRS)
DataType
Raster data types.
Definition: qgis.h:129
virtual QgsRasterBlock * block(int bandNo, const QgsRectangle &extent, int width, int height)=0
Read block of data using given extent and size.
Greyscale.
Definition: qgsraster.h:35
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:45
virtual QString validateCreationOptions(const QStringList &createOptions, const QString &format)
Validates creation options for a specific dataset and destination format.
virtual bool write(void *data, int band, int width, int height, int xOffset, int yOffset)
Writes into the provider datasource.
virtual bool srcHasNoDataValue(int bandNo) const
Return true if source band has no data value.
int dpi() const
Returns the dpi of the output device.
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
RasterPyramidsFormat
Definition: qgsraster.h:78
void setDpi(int dpi)
Sets the output device resolution.
Cyan band of CMYK image.
Definition: qgsraster.h:44
virtual QDateTime dataTimestamp() const override
Current time stamp of data source.
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:46