QGIS API Documentation  2.99.0-Master (cb63e82)
qgsrasterinterface.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterface.h - Internal raster processing modules interface
3  --------------------------------------
4  Date : Jun 21, 2012
5  Copyright : (C) 2012 by Radim Blazek
6  email : radim dot blazek at gmail dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSRASTERINTERFACE_H
19 #define QGSRASTERINTERFACE_H
20 
21 #include "qgis_core.h"
22 #include <limits>
23 
24 #include <QCoreApplication> // for tr()
25 #include <QImage>
26 
27 #include "qgsfeedback.h"
28 #include "qgsrasterbandstats.h"
29 #include "qgsrasterblock.h"
30 #include "qgsrasterhistogram.h"
31 #include "qgsrectangle.h"
32 
38 class CORE_EXPORT QgsRasterBlockFeedback : public QgsFeedback
39 {
40  public:
42  QgsRasterBlockFeedback( QObject *parent = nullptr ) : QgsFeedback( parent ), mPreviewOnly( false ), mRenderPartialOutput( false ) {}
43 
46  virtual void onNewData() {}
47 
51  bool isPreviewOnly() const { return mPreviewOnly; }
54  void setPreviewOnly( bool preview ) { mPreviewOnly = preview; }
55 
58  bool renderPartialOutput() const { return mRenderPartialOutput; }
61  void setRenderPartialOutput( bool enable ) { mRenderPartialOutput = enable; }
62 
63  private:
66  bool mPreviewOnly;
67 
69  bool mRenderPartialOutput;
70 };
71 
72 
76 class CORE_EXPORT QgsRasterInterface
77 {
78  Q_DECLARE_TR_FUNCTIONS( QgsRasterInterface )
79 
80  public:
83  {
84  NoCapabilities = 0,
85  Size = 1 << 1, // original data source size (and thus resolution) is known, it is not always available, for example for WMS
86  Create = 1 << 2, // create new datasets
87  Remove = 1 << 3, // delete datasets
88  BuildPyramids = 1 << 4, // supports building of pyramids (overviews)
89  Identify = 1 << 5, // at least one identify format supported
90  IdentifyValue = 1 << 6, // numerical values
91  IdentifyText = 1 << 7, // WMS text
92  IdentifyHtml = 1 << 8, // WMS HTML
93  IdentifyFeature = 1 << 9, // WMS GML -> feature
94  };
95 
96  QgsRasterInterface( QgsRasterInterface *input = nullptr );
97 
98  virtual ~QgsRasterInterface() = default;
99 
101  virtual QgsRasterInterface *clone() const = 0;
102 
104  virtual int capabilities() const
105  {
107  }
108 
112  QString capabilitiesString() const;
113 
115  virtual Qgis::DataType dataType( int bandNo ) const = 0;
116 
119  virtual Qgis::DataType sourceDataType( int bandNo ) const { return mInput ? mInput->sourceDataType( bandNo ) : Qgis::UnknownDataType; }
120 
125  virtual QgsRectangle extent() const { return mInput ? mInput->extent() : QgsRectangle(); }
126 
127  int dataTypeSize( int bandNo ) { return QgsRasterBlock::typeSize( dataType( bandNo ) ); }
128 
130  virtual int bandCount() const = 0;
131 
133  virtual int xBlockSize() const { return mInput ? mInput->xBlockSize() : 0; }
134  virtual int yBlockSize() const { return mInput ? mInput->yBlockSize() : 0; }
135 
137  virtual int xSize() const { return mInput ? mInput->xSize() : 0; }
138  virtual int ySize() const { return mInput ? mInput->ySize() : 0; }
139 
141  virtual QString generateBandName( int bandNumber ) const
142  {
143  return tr( "Band" ) + QStringLiteral( " %1" ) .arg( bandNumber, 1 + static_cast< int >( log10( static_cast< double >( bandCount() ) ) ), 10, QChar( '0' ) );
144  }
145 
155  virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback = nullptr ) = 0;
156 
159  virtual bool setInput( QgsRasterInterface *input ) { mInput = input; return true; }
160 
162  virtual QgsRasterInterface *input() const { return mInput; }
163 
165  virtual bool on() const { return mOn; }
166 
168  virtual void setOn( bool on ) { mOn = on; }
169 
174  virtual const QgsRasterInterface *sourceInput() const
175  {
176  QgsDebugMsgLevel( "Entered", 4 );
177  return mInput ? mInput->sourceInput() : this;
178  }
179 
185  {
186  QgsDebugMsgLevel( "Entered", 4 );
187  return mInput ? mInput->sourceInput() : this;
188  }
189 
198  virtual QgsRasterBandStats bandStatistics( int bandNo,
199  int stats = QgsRasterBandStats::All,
200  const QgsRectangle &extent = QgsRectangle(),
201  int sampleSize = 0, QgsRasterBlockFeedback *feedback = nullptr );
202 
206  virtual bool hasStatistics( int bandNo,
207  int stats = QgsRasterBandStats::All,
208  const QgsRectangle &extent = QgsRectangle(),
209  int sampleSize = 0 );
210 
223  virtual QgsRasterHistogram histogram( int bandNo,
224  int binCount = 0,
225  double minimum = std::numeric_limits<double>::quiet_NaN(),
226  double maximum = std::numeric_limits<double>::quiet_NaN(),
227  const QgsRectangle &extent = QgsRectangle(),
228  int sampleSize = 0,
229  bool includeOutOfRange = false, QgsRasterBlockFeedback *feedback = nullptr );
230 
234  virtual bool hasHistogram( int bandNo,
235  int binCount,
236  double minimum = std::numeric_limits<double>::quiet_NaN(),
237  double maximum = std::numeric_limits<double>::quiet_NaN(),
238  const QgsRectangle &extent = QgsRectangle(),
239  int sampleSize = 0,
240  bool includeOutOfRange = false );
241 
251  virtual void cumulativeCut( int bandNo,
252  double lowerCount,
253  double upperCount,
254  double &lowerValue,
255  double &upperValue,
256  const QgsRectangle &extent = QgsRectangle(),
257  int sampleSize = 0 );
258 
260  virtual void writeXml( QDomDocument &doc, QDomElement &parentElem ) const { Q_UNUSED( doc ); Q_UNUSED( parentElem ); }
262  virtual void readXml( const QDomElement &filterElem ) { Q_UNUSED( filterElem ); }
263 
264  protected:
265  // QgsRasterInterface used as input
266  QgsRasterInterface *mInput = nullptr;
267 
269  QList <QgsRasterBandStats> mStatistics;
270 
272  QList <QgsRasterHistogram> mHistograms;
273 
274  // On/off state, if off, it does not do anything, replicates input
275  bool mOn;
276 
280  void initHistogram( QgsRasterHistogram &histogram, int bandNo,
281  int binCount = 0,
282  double minimum = std::numeric_limits<double>::quiet_NaN(),
283  double maximum = std::numeric_limits<double>::quiet_NaN(),
284  const QgsRectangle &boundingBox = QgsRectangle(),
285  int sampleSize = 0,
286  bool includeOutOfRange = false );
287 
289  void initStatistics( QgsRasterBandStats &statistics, int bandNo,
290  int stats = QgsRasterBandStats::All,
291  const QgsRectangle &boundingBox = QgsRectangle(),
292  int binCount = 0 );
293 
294  private:
295  Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
296 };
297 
298 #endif
299 
300 
virtual void onNewData()
May be emitted by raster data provider to indicate that some partial data are available and a new pre...
A rectangle specified with double values.
Definition: qgsrectangle.h:38
virtual void readXml(const QDomElement &filterElem)
Sets base class members from xml. Usually called from create() methods of subclasses.
bool renderPartialOutput() const
Whether our painter is drawing to a temporary image used just by this layer.
virtual QgsRectangle extent() const
Get the extent of the interface.
virtual QgsRasterInterface * input() const
Current input.
DataType
Raster data types.
Definition: qgis.h:61
virtual int ySize() const
Capability
If you add to this, please also add to capabilitiesString()
void setRenderPartialOutput(bool enable)
Set whether our painter is drawing to a temporary image used just by this layer.
virtual QgsRasterInterface * sourceInput()
Get source / raw input, the first in pipe, usually provider.
virtual int xBlockSize() const
Get block size.
Base class for feedback objects to be used for cancelation of something running in a worker thread...
Definition: qgsfeedback.h:43
The RasterBandStats struct is a container for statistics about a single raster band.
Raster data container.
void setPreviewOnly(bool preview)
set flag whether the block request is for preview purposes only
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:37
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
virtual void setOn(bool on)
Set on/off.
QList< QgsRasterHistogram > mHistograms
List of cached histograms, all bands mixed.
Unknown or unspecified type.
Definition: qgis.h:63
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...
QgsRasterBlockFeedback(QObject *parent=nullptr)
Construct a new raster block feedback object.
static int typeSize(int dataType)
Base class for processing filters like renderers, reprojector, resampler etc.
virtual bool setInput(QgsRasterInterface *input)
Set input.
virtual bool on() const
Is on/off.
virtual int yBlockSize() const
bool isPreviewOnly() const
Whether the raster provider should return only data that are already available without waiting for fu...
int dataTypeSize(int bandNo)
The QgsRasterHistogram is a container for histogram of a single raster band.
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
virtual void writeXml(QDomDocument &doc, QDomElement &parentElem) const
Write base class members to xml.
virtual QString generateBandName(int bandNumber) const
helper function to create zero padded band names
Feedback object tailored for raster block reading.
virtual int xSize() const
Get raster size.
virtual const QgsRasterInterface * sourceInput() const
Get source / raw input, the first in pipe, usually provider.