QGIS API Documentation  2.99.0-Master (b058df7)
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 "qgis_sip.h"
28 #include <cmath>
29 
30 #include <QDateTime>
31 #include <QVariant>
32 #include <QImage>
33 
34 #include "qgscolorrampshader.h"
35 #include "qgsdataprovider.h"
36 #include "qgsfields.h"
37 #include "qgsraster.h"
38 #include "qgsrasterinterface.h"
39 #include "qgsrasterpyramid.h"
40 #include "qgsrasterrange.h"
41 #include "qgsrectangle.h"
42 #include "qgsrasteriterator.h"
43 
44 class QImage;
45 class QByteArray;
46 
47 class QgsPointXY;
49 class QgsMapSettings;
50 
56 class CORE_EXPORT QgsImageFetcher : public QObject
57 {
58  Q_OBJECT
59  public:
61  QgsImageFetcher( QObject *parent = 0 ) : QObject( parent ) {}
62 
66  virtual void start() = 0;
67 
68  signals:
69 
73  void finish( const QImage &legend );
75  void progress( qint64 received, qint64 total );
77  void error( const QString &msg );
78 };
79 
80 
85 class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRasterInterface
86 {
87  Q_OBJECT
88 
89  public:
91 
92  QgsRasterDataProvider( const QString &uri );
93 
94  virtual QgsRasterInterface *clone() const override = 0;
95 
96  /* It makes no sense to set input on provider */
97  bool setInput( QgsRasterInterface *input ) override { Q_UNUSED( input ); return false; }
98 
99  virtual QgsRectangle extent() const override = 0;
100 
102  virtual Qgis::DataType dataType( int bandNo ) const override = 0;
103 
108  virtual Qgis::DataType sourceDataType( int bandNo ) const override = 0;
109 
111  virtual int colorInterpretation( int bandNo ) const
112  {
113  Q_UNUSED( bandNo );
115  }
116 
117  QString colorName( int colorInterpretation ) const
118  {
119  // Modified copy from GDAL
120  switch ( colorInterpretation )
121  {
123  return QStringLiteral( "Undefined" );
124 
126  return QStringLiteral( "Gray" );
127 
129  return QStringLiteral( "Palette" );
130 
131  case QgsRaster::RedBand:
132  return QStringLiteral( "Red" );
133 
135  return QStringLiteral( "Green" );
136 
137  case QgsRaster::BlueBand:
138  return QStringLiteral( "Blue" );
139 
141  return QStringLiteral( "Alpha" );
142 
143  case QgsRaster::HueBand:
144  return QStringLiteral( "Hue" );
145 
147  return QStringLiteral( "Saturation" );
148 
150  return QStringLiteral( "Lightness" );
151 
152  case QgsRaster::CyanBand:
153  return QStringLiteral( "Cyan" );
154 
156  return QStringLiteral( "Magenta" );
157 
159  return QStringLiteral( "Yellow" );
160 
162  return QStringLiteral( "Black" );
163 
165  return QStringLiteral( "YCbCr_Y" );
166 
168  return QStringLiteral( "YCbCr_Cb" );
169 
171  return QStringLiteral( "YCbCr_Cr" );
172 
173  default:
174  return QStringLiteral( "Unknown" );
175  }
176  }
178  virtual bool reload() { return true; }
179 
180  virtual QString colorInterpretationName( int bandNo ) const
181  {
182  return colorName( colorInterpretation( bandNo ) );
183  }
184 
189  virtual double bandScale( int bandNo ) const { Q_UNUSED( bandNo ); return 1.0; }
190 
195  virtual double bandOffset( int bandNo ) const { Q_UNUSED( bandNo ); return 0.0; }
196 
197  // TODO: remove or make protected all readBlock working with void*
198 
200  virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &boundingBox, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) override;
201 
203  virtual bool sourceHasNoDataValue( int bandNo ) const { return mSrcHasNoDataValue.value( bandNo - 1 ); }
204 
206  virtual bool useSourceNoDataValue( int bandNo ) const { return mUseSrcNoDataValue.value( bandNo - 1 ); }
207 
209  virtual void setUseSourceNoDataValue( int bandNo, bool use );
210 
212  virtual double sourceNoDataValue( int bandNo ) const { return mSrcNoDataValue.value( bandNo - 1 ); }
213 
214  virtual void setUserNoDataValue( int bandNo, const QgsRasterRangeList &noData );
215 
217  virtual QgsRasterRangeList userNoDataValues( int bandNo ) const { return mUserNoDataValue.value( bandNo - 1 ); }
218 
219  virtual QList<QgsColorRampShader::ColorRampItem> colorTable( int bandNo ) const
220  { Q_UNUSED( bandNo ); return QList<QgsColorRampShader::ColorRampItem>(); }
221 
225  virtual QStringList subLayers() const override
226  {
227  return QStringList();
228  }
229 
231  virtual bool supportsLegendGraphic() const { return false; }
232 
243  virtual QImage getLegendGraphic( double scale = 0, bool forceRefresh = false, const QgsRectangle *visibleExtent = nullptr ) SIP_SKIP
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> &pyramidList,
272  const QString &resamplingMethod = "NEAREST",
274  const QStringList &configOptions = QStringList(),
275  QgsRasterBlockFeedback *feedback = nullptr )
276  {
277  Q_UNUSED( pyramidList );
278  Q_UNUSED( resamplingMethod );
279  Q_UNUSED( format );
280  Q_UNUSED( configOptions );
281  Q_UNUSED( feedback );
282  return QStringLiteral( "FAILED_NOT_SUPPORTED" );
283  }
284 
293  virtual QList<QgsRasterPyramid> buildPyramidList( QList<int> overviewList = QList<int>() ) // clazy:exclude=function-args-by-ref
294  { Q_UNUSED( overviewList ); return QList<QgsRasterPyramid>(); }
295 
297  bool hasPyramids();
298 
303  virtual QString htmlMetadata() = 0;
304 
329  //virtual QMap<int, QVariant> identify( const QgsPointXY & point, QgsRaster::IdentifyFormat format, const QgsRectangle &extent = QgsRectangle(), int width = 0, int height = 0 );
330  virtual QgsRasterIdentifyResult identify( const QgsPointXY &point, QgsRaster::IdentifyFormat format, const QgsRectangle &boundingBox = QgsRectangle(), int width = 0, int height = 0, int dpi = 96 );
331 
341  virtual QString lastErrorTitle() = 0;
342 
352  virtual QString lastError() = 0;
353 
355  virtual QString lastErrorFormat();
356 
358  int dpi() const { return mDpi; }
359 
361  void setDpi( int dpi ) { mDpi = dpi; }
362 
364  virtual QDateTime timestamp() const override { return mTimestamp; }
365 
367  virtual QDateTime dataTimestamp() const override { return QDateTime(); }
368 
375  virtual bool isEditable() const { return false; }
376 
387  virtual bool setEditable( bool enabled ) { Q_UNUSED( enabled ); return false; }
388 
390  // TODO: add data type (may be defferent from band type)
391  virtual bool write( void *data, int band, int width, int height, int xOffset, int yOffset )
392  {
393  Q_UNUSED( data );
394  Q_UNUSED( band );
395  Q_UNUSED( width );
396  Q_UNUSED( height );
397  Q_UNUSED( xOffset );
398  Q_UNUSED( yOffset );
399  return false;
400  }
401 
418  bool writeBlock( QgsRasterBlock *block, int band, int xOffset = 0, int yOffset = 0 );
419 
421  static QgsRasterDataProvider *create( const QString &providerKey,
422  const QString &uri,
423  const QString &format, int nBands,
424  Qgis::DataType type,
425  int width, int height, double *geoTransform,
426  const QgsCoordinateReferenceSystem &crs,
427  const QStringList &createOptions = QStringList() );
428 
434  virtual bool setNoDataValue( int bandNo, double noDataValue ) { Q_UNUSED( bandNo ); Q_UNUSED( noDataValue ); return false; }
435 
437  virtual bool remove() { return false; }
438 
443  static QList<QPair<QString, QString> > pyramidResamplingMethods( const QString &providerKey );
444 
450  virtual QString validateCreationOptions( const QStringList &createOptions, const QString &format )
451  { Q_UNUSED( createOptions ); Q_UNUSED( format ); return QString(); }
452 
458  const QStringList &configOptions, const QString &fileFormat )
459  { Q_UNUSED( pyramidsFormat ); Q_UNUSED( configOptions ); Q_UNUSED( fileFormat ); return QString(); }
460 
461  static QString identifyFormatName( QgsRaster::IdentifyFormat format );
462  static QgsRaster::IdentifyFormat identifyFormatFromName( const QString &formatName );
463  static QString identifyFormatLabel( QgsRaster::IdentifyFormat format );
464  static Capability identifyFormatToCapability( QgsRaster::IdentifyFormat format );
465 
472 
479 
480  signals:
481 
486  void statusChanged( const QString & ) const;
487 
488  protected:
489 
494  virtual void readBlock( int bandNo, int xBlock, int yBlock, void *data ) SIP_SKIP
495  { Q_UNUSED( bandNo ); Q_UNUSED( xBlock ); Q_UNUSED( yBlock ); Q_UNUSED( data ); }
496 
501  virtual void readBlock( int bandNo, QgsRectangle const &viewExtent, int width, int height, void *data, QgsRasterBlockFeedback *feedback = nullptr ) SIP_SKIP
502  { Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); Q_UNUSED( feedback ); }
503 
505  bool userNoDataValuesContains( int bandNo, double value ) const;
506 
508  void copyBaseSettings( const QgsRasterDataProvider &other );
509 
511  static QStringList cStringList2Q_( char **stringList ) SIP_SKIP;
512 
513  static QString makeTableCell( const QString &value );
514  static QString makeTableCells( const QStringList &values );
515 
519  int mDpi = -1;
520 
524  //bool hasNoDataValue ( int bandNo );
525 
527  QList<double> mSrcNoDataValue;
528 
530  QList<bool> mSrcHasNoDataValue;
531 
536  QList<bool> mUseSrcNoDataValue;
537 
541  QList< QgsRasterRangeList > mUserNoDataValue;
542 
544 
545 };
546 
547 // clazy:excludeall=qstring-allocations
548 
549 #endif
virtual void readBlock(int bandNo, int xBlock, int yBlock, void *data)
Read block of data.
IdentifyFormat
Definition: qgsraster.h:57
A rectangle specified with double values.
Definition: qgsrectangle.h:39
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:50
Handles asynchronous download of images.
virtual QList< QgsColorRampShader::ColorRampItem > colorTable(int bandNo) const
virtual double bandOffset(int bandNo) const
Read band offset for raster value.
A class to represent a 2D point.
Definition: qgspointxy.h:43
QDateTime mTimestamp
Timestamp of data in the moment when the data were loaded by provider.
DataType
Raster data types.
Definition: qgis.h:78
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.
virtual QString buildPyramids(const QList< QgsRasterPyramid > &pyramidList, const QString &resamplingMethod="NEAREST", QgsRaster::RasterPyramidsFormat format=QgsRaster::PyramidsGTiff, const QStringList &configOptions=QStringList(), QgsRasterBlockFeedback *feedback=nullptr)
Create pyramid overviews.
Hue band of HLS image.
Definition: qgsraster.h:44
virtual double sourceNoDataValue(int bandNo) const
Value representing no data value.
virtual QString validatePyramidsConfigOptions(QgsRaster::RasterPyramidsFormat pyramidsFormat, const QStringList &configOptions, const QString &fileFormat)
Validates pyramid creation options for a specific dataset and destination format. ...
The QgsMapSettings class contains configuration for rendering of the map.
Raster identify results container.
Lightness band of HLS image.
Definition: qgsraster.h:46
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:43
Raster data container.
Green band of RGBA image.
Definition: qgsraster.h:41
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.
#define SIP_SKIP
Definition: qgis_sip.h:119
Y Luminance.
Definition: qgsraster.h:51
virtual QStringList subLayers() const override
Returns the sublayers of this layer - useful for providers that manage their own layers, such as WMS.
static const int DEFAULT_MAXIMUM_TILE_HEIGHT
virtual bool reload()
Reload data (data could change)
QList< bool > mSrcHasNoDataValue
Source no data value exists.
virtual QString colorInterpretationName(int bandNo) const
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...
#define SIP_FACTORY
Definition: qgis_sip.h:69
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.
virtual bool sourceHasNoDataValue(int bandNo) const
Return true if source band has no data value.
Saturation band of HLS image.
Definition: qgsraster.h:45
QList< double > mSrcNoDataValue
Source no data value is available and is set to be used or internal no data is available.
virtual int stepHeight() const
Step height for raster iterations.
Blue band of RGBA image.
Definition: qgsraster.h:42
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:38
virtual QgsRasterRangeList userNoDataValues(int bandNo) const
Get list of user no data value ranges.
virtual int stepWidth() const
Step width for raster iterations.
Magenta band of CMYK image.
Definition: qgsraster.h:48
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:81
Feedback object tailored for raster block reading.
static const int DEFAULT_MAXIMUM_TILE_WIDTH
void setDpi(int dpi)
Sets the output device resolution.
Cyan band of CMYK image.
Definition: qgsraster.h:47
virtual QDateTime dataTimestamp() const override
Current time stamp of data source.
QgsImageFetcher(QObject *parent=0)
Constructor.
virtual int colorInterpretation(int bandNo) const
Returns data type for the band specified by number.
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:49
virtual double bandScale(int bandNo) const
Read band scale for raster value.