QGIS API Documentation  2.99.0-Master (7fe5405)
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 theBandNumber ) const
142  {
143  return tr( "Band" ) + QStringLiteral( " %1" ) .arg( theBandNumber, 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 
197  virtual QgsRasterBandStats bandStatistics( int theBandNo,
198  int theStats = QgsRasterBandStats::All,
199  const QgsRectangle & theExtent = QgsRectangle(),
200  int theSampleSize = 0 );
201 
205  virtual bool hasStatistics( int theBandNo,
206  int theStats = QgsRasterBandStats::All,
207  const QgsRectangle & theExtent = QgsRectangle(),
208  int theSampleSize = 0 );
209 
221  virtual QgsRasterHistogram histogram( int theBandNo,
222  int theBinCount = 0,
223  double theMinimum = std::numeric_limits<double>::quiet_NaN(),
224  double theMaximum = std::numeric_limits<double>::quiet_NaN(),
225  const QgsRectangle & theExtent = QgsRectangle(),
226  int theSampleSize = 0,
227  bool theIncludeOutOfRange = false );
228 
232  virtual bool hasHistogram( int theBandNo,
233  int theBinCount,
234  double theMinimum = std::numeric_limits<double>::quiet_NaN(),
235  double theMaximum = std::numeric_limits<double>::quiet_NaN(),
236  const QgsRectangle & theExtent = QgsRectangle(),
237  int theSampleSize = 0,
238  bool theIncludeOutOfRange = false );
239 
249  virtual void cumulativeCut( int theBandNo,
250  double theLowerCount,
251  double theUpperCount,
252  double &theLowerValue,
253  double &theUpperValue,
254  const QgsRectangle & theExtent = QgsRectangle(),
255  int theSampleSize = 0 );
256 
258  virtual void writeXml( QDomDocument& doc, QDomElement& parentElem ) const { Q_UNUSED( doc ); Q_UNUSED( parentElem ); }
260  virtual void readXml( const QDomElement& filterElem ) { Q_UNUSED( filterElem ); }
261 
262  protected:
263  // QgsRasterInterface used as input
265 
267  QList <QgsRasterBandStats> mStatistics;
268 
270  QList <QgsRasterHistogram> mHistograms;
271 
272  // On/off state, if off, it does not do anything, replicates input
273  bool mOn;
274 
278  void initHistogram( QgsRasterHistogram &theHistogram, int theBandNo,
279  int theBinCount = 0,
280  double theMinimum = std::numeric_limits<double>::quiet_NaN(),
281  double theMaximum = std::numeric_limits<double>::quiet_NaN(),
282  const QgsRectangle & theExtent = QgsRectangle(),
283  int theSampleSize = 0,
284  bool theIncludeOutOfRange = false );
285 
287  void initStatistics( QgsRasterBandStats &theStatistics, int theBandNo,
288  int theStats = QgsRasterBandStats::All,
289  const QgsRectangle & theExtent = QgsRectangle(),
290  int theBinCount = 0 );
291 
292  private:
293  Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
294 };
295 
296 #endif
297 
298 
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:36
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 QString generateBandName(int theBandNumber) const
helper function to create zero padded band names
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:42
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.
QgsRasterInterface * mInput
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.