QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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  virtual QgsRasterBlock *block2( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight, QgsRasterBlockFeedback* feedback = nullptr ) override;
213 
215  virtual bool srcHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo -1 ); }
216 
218  virtual bool useSrcNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo -1 ); }
219 
221  virtual void setUseSrcNoDataValue( int bandNo, bool use );
222 
224  virtual double srcNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo -1 ); }
225 
226  virtual void setUserNoDataValue( int bandNo, const QgsRasterRangeList& noData );
227 
229  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo -1 ); }
230 
232  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
233 
236  virtual QStringList subLayers() const override
237  {
238  return QStringList();
239  }
240 
242  virtual bool supportsLegendGraphic() const { return false; }
243 
252  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle * visibleExtent = nullptr )
253  {
254  Q_UNUSED( scale );
255  Q_UNUSED( forceRefresh );
256  Q_UNUSED( visibleExtent );
257  return QImage();
258  }
259 
274  {
275  Q_UNUSED( mapSettings );
276  return nullptr;
277  }
278 
280  virtual QString buildPyramids( const QList<QgsRasterPyramid> & thePyramidList,
281  const QString & theResamplingMethod = "NEAREST",
283  const QStringList & theConfigOptions = QStringList() )
284  {
285  Q_UNUSED( thePyramidList );
286  Q_UNUSED( theResamplingMethod );
287  Q_UNUSED( theFormat );
288  Q_UNUSED( theConfigOptions );
289  return "FAILED_NOT_SUPPORTED";
290  }
291 
300  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }
301 
303  bool hasPyramids();
304 
309  virtual QString metadata() = 0;
310 
334  //virtual QMap<int, QVariant> identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0 );
335  virtual QgsRasterIdentifyResult identify( const QgsPoint & thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent = QgsRectangle(), int theWidth = 0, int theHeight = 0, int theDpi = 96 );
336 
346  virtual QString lastErrorTitle() = 0;
347 
357  virtual QString lastError() = 0;
358 
360  virtual QString lastErrorFormat();
361 
363  int dpi() const { return mDpi; }
364 
366  void setDpi( int dpi ) { mDpi = dpi; }
367 
369  virtual QDateTime timestamp() const override { return mTimestamp; }
370 
372  virtual QDateTime dataTimestamp() const override { return QDateTime(); }
373 
375  // TODO: add data type (may be defferent from band type)
376  virtual bool write( void* data, int band, int width, int height, int xOffset, int yOffset )
377  {
378  Q_UNUSED( data );
379  Q_UNUSED( band );
380  Q_UNUSED( width );
381  Q_UNUSED( height );
382  Q_UNUSED( xOffset );
383  Q_UNUSED( yOffset );
384  return false;
385  }
386 
388  static QgsRasterDataProvider* create( const QString &providerKey,
389  const QString &uri,
390  const QString& format, int nBands,
391  QGis::DataType type,
392  int width, int height, double* geoTransform,
393  const QgsCoordinateReferenceSystem& crs,
394  const QStringList& createOptions = QStringList() );
395 
400  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
401 
403  virtual bool remove() { return false; }
404 
408  static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString& providerKey );
409 
414  virtual QString validateCreationOptions( const QStringList& createOptions, const QString& format )
415  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
416 
421  const QStringList & theConfigOptions, const QString & fileFormat )
422  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( theConfigOptions ); Q_UNUSED( fileFormat ); return QString(); }
423 
424  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
425  static QgsRaster::IdentifyFormat identifyFormatFromName( const QString& formatName );
426  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
427  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
428 
429  signals:
432  void progress( int theType, double theProgress, const QString& theMessage );
433  void progressUpdate( int theProgress );
434 
438  void statusChanged( const QString& );
439 
440  protected:
444  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data )
445  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
446 
450  virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data, QgsRasterBlockFeedback* feedback = nullptr )
451  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); Q_UNUSED( feedback ); }
452 
454  bool userNoDataValuesContains( int bandNo, double value ) const;
455 
457  void copyBaseSettings( const QgsRasterDataProvider& other );
458 
460  static QStringList cStringList2Q_( char ** stringList );
461 
462  static QString makeTableCell( const QString & value );
463  static QString makeTableCells( const QStringList & values );
464 
467  int mDpi;
468 
471  //bool hasNoDataValue ( int theBandNo );
472 
475 
478 
483 
487 
489 
492 
493 };
494 #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. ...
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.
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 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.
Hue band of HLS image.
Definition: qgsraster.h:41
virtual QgsRasterBlock * block2(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)
Read block of data using given extent and size.
T value(int i) const
The QgsMapSettings class contains configuration for rendering of the map.
Raster identify results container.
Lightness band of HLS image.
Definition: qgsraster.h:43
int dpi() const
Returns the dpi of the output device.
Paletted (see associated color table)
Definition: qgsraster.h:36
Alpha (0=transparent, 255=opaque)
Definition: qgsraster.h:40
Raster data container.
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 srcDataType(int bandNo) const
Returns source data type for the band specified by number, source data type may be shorter than dataT...
virtual QGis::DataType dataType(int bandNo) const =0
Returns data type for the band specified by number.
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:117
virtual bool useSrcNoDataValue(int bandNo) const
Get source nodata value usage.
Saturation band of HLS image.
Definition: qgsraster.h:42
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:39
virtual QgsRectangle extent()=0
Get the extent of the layer.
QString colorName(int colorInterpretation) const
virtual ~QgsImageFetcher()
Destructor.
virtual QgsRasterInterface * clone() const =0
Clone itself, create deep copy.
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 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: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.
virtual double srcNoDataValue(int bandNo) const
Value representing no data value.
RasterPyramidsFormat
Definition: qgsraster.h:78
Feedback object tailored for raster block reading.
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
virtual double bandScale(int bandNo) const
Read band scale for raster value.