QGIS API Documentation  2.17.0-Master (6f7b933)
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:
64  QgsImageFetcher( QObject* parent = 0 ) : QObject( parent ) {}
66  virtual ~QgsImageFetcher() {}
67 
70  virtual void start() = 0;
71 
72  signals:
75  void finish( const QImage& legend );
77  void progress( qint64 received, qint64 total );
79  void error( const QString& msg );
80 };
81 
82 
86 class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRasterInterface
87 {
88  Q_OBJECT
89 
90  public:
92 
93  QgsRasterDataProvider( const QString & uri );
94 
96 
97  virtual QgsRasterInterface * clone() const override = 0;
98 
99  /* It makes no sense to set input on provider */
100  bool setInput( QgsRasterInterface* input ) override { Q_UNUSED( input ); return false; }
101 
109  virtual QImage* draw( const QgsRectangle & viewExtent, int pixelWidth, int pixelHeight ) = 0;
110 
114  virtual QgsRectangle extent() override = 0;
115 
117  virtual QGis::DataType dataType( int bandNo ) const override = 0;
118 
122  virtual QGis::DataType srcDataType( int bandNo ) const override = 0;
123 
125  virtual int colorInterpretation( int theBandNo ) const
126  {
127  Q_UNUSED( theBandNo );
129  }
130 
131  QString colorName( int colorInterpretation ) const
132  {
133  // Modified copy from GDAL
134  switch ( colorInterpretation )
135  {
137  return "Undefined";
138 
140  return "Gray";
141 
143  return "Palette";
144 
145  case QgsRaster::RedBand:
146  return "Red";
147 
149  return "Green";
150 
151  case QgsRaster::BlueBand:
152  return "Blue";
153 
155  return "Alpha";
156 
157  case QgsRaster::HueBand:
158  return "Hue";
159 
161  return "Saturation";
162 
164  return "Lightness";
165 
166  case QgsRaster::CyanBand:
167  return "Cyan";
168 
170  return "Magenta";
171 
173  return "Yellow";
174 
176  return "Black";
177 
179  return "YCbCr_Y";
180 
182  return "YCbCr_Cb";
183 
185  return "YCbCr_Cr";
186 
187  default:
188  return "Unknown";
189  }
190  }
192  virtual bool reload() { return true; }
193 
194  virtual QString colorInterpretationName( int theBandNo ) const
195  {
196  return colorName( colorInterpretation( theBandNo ) );
197  }
198 
202  virtual double bandScale( int bandNo ) const { Q_UNUSED( bandNo ); return 1.0; }
206  virtual double bandOffset( int bandNo ) const { Q_UNUSED( bandNo ); return 0.0; }
207 
208  // TODO: remove or make protected all readBlock working with void*
209 
211  virtual QgsRasterBlock *block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight ) override;
212 
214  virtual bool srcHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo -1 ); }
215 
217  virtual bool useSrcNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo -1 ); }
218 
220  virtual void setUseSrcNoDataValue( int bandNo, bool use );
221 
223  virtual double srcNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo -1 ); }
224 
225  virtual void setUserNoDataValue( int bandNo, const QgsRasterRangeList& noData );
226 
228  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
229 
231  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
232 
235  virtual QStringList subLayers() const override
236  {
237  return QStringList();
238  }
239 
241  virtual bool supportsLegendGraphic() const { return false; }
242 
251  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle * visibleExtent = nullptr )
252  {
253  Q_UNUSED( scale );
254  Q_UNUSED( forceRefresh );
255  Q_UNUSED( visibleExtent );
256  return QImage();
257  }
258 
273  {
274  Q_UNUSED( mapSettings );
275  return nullptr;
276  }
277 
279  virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
280  const QString & theResamplingMethod = "NEAREST",
282  const QStringList & theConfigOptions = QStringList() )
283  {
284  Q_UNUSED( thePyramidList );
285  Q_UNUSED( theResamplingMethod );
286  Q_UNUSED( theFormat );
287  Q_UNUSED( theConfigOptions );
288  return "FAILED_NOT_SUPPORTED";
289  }
290 
299  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }
300 
302  bool hasPyramids();
303 
308  virtual QString metadata() = 0;
309 
333  //virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
334  virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0, int theDpi = 96 );
335 
345  virtual QString lastErrorTitle() = 0;
346 
356  virtual QString lastError() = 0;
357 
359  virtual QString lastErrorFormat();
360 
362  int dpi() const { return mDpi; }
363 
365  void setDpi( int dpi ) { mDpi = dpi; }
366 
368  virtual QDateTime timestamp() const override { return mTimestamp; }
369 
371  virtual QDateTime dataTimestamp() const override { return QDateTime(); }
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 
387  static QgsRasterDataProvider* create( const QString &providerKey,
388  const QString &uri,
389  const QString& format, int nBands,
390  QGis::DataType type,
391  int width, int height, double* geoTransform,
392  const QgsCoordinateReferenceSystem& crs,
393  const QStringList& createOptions = QStringList() );
394 
399  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
400 
402  virtual bool remove() { return false; }
403 
407  static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString& providerKey );
408 
413  virtual QString validateCreationOptions( const QStringList& createOptions, const QString& format )
414  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
415 
420  const QStringList & theConfigOptions, const QString & fileFormat )
421  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
422 
423  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
424  static QgsRaster::IdentifyFormat identifyFormatFromName( const QString& formatName );
425  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
426  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
427 
428  signals:
431  void progress( int theType, double theProgress, const QString& theMessage );
432  void progressUpdate( int theProgress );
433 
437  void statusChanged( const QString& );
438 
439  protected:
443  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
444  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
445 
449  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data )
450  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
451 
453  bool userNoDataValuesContains( int bandNo, double value ) const;
454 
456  void copyBaseSettings( const QgsRasterDataProvider& other );
457 
459  static QStringList cStringList2Q_( char ** stringList );
460 
461  static QString makeTableCell( const QString & value );
462  static QString makeTableCells( const QStringList & values );
463 
466  int mDpi;
467 
470  //bool hasNoDataValue ( int theBandNo );
471 
474 
477 
482 
486 
488 
491 
492 };
493 #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: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 ~QgsImageFetcher()
Destructor.
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:133
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.
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:46