QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 <limits>
22 
23 #include <QCoreApplication> // for tr()
24 #include <QImage>
25 
26 #include "qgsfeedback.h"
27 #include "qgslogger.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();
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 srcDataType( int bandNo ) const { return mInput ? mInput->srcDataType( bandNo ) : QGis::UnknownDataType; }
120 
125  virtual QgsRectangle extent() { 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" ) + QString( " %1" ) .arg( theBandNumber, 1 + static_cast< int >( log10( static_cast< double >( bandCount() ) ) ), 10, QChar( '0' ) );
144  }
145 
154  virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height ) = 0;
155 
167  virtual QgsRasterBlock *block2( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback* feedback = nullptr )
168  {
169  Q_UNUSED( feedback );
170  return block( bandNo, extent, width, height );
171  }
172 
175  virtual bool setInput( QgsRasterInterface* input ) { mInput = input; return true; }
176 
178  virtual QgsRasterInterface * input() const { return mInput; }
179 
181  virtual bool on() const { return mOn; }
182 
184  virtual void setOn( bool on ) { mOn = on; }
185 
190  virtual const QgsRasterInterface *srcInput() const
191  {
192  QgsDebugMsgLevel( "Entered", 4 );
193  return mInput ? mInput->srcInput() : this;
194  }
196  {
197  QgsDebugMsgLevel( "Entered", 4 );
198  return mInput ? mInput->srcInput() : this;
199  }
200 
208  virtual QgsRasterBandStats bandStatistics( int theBandNo,
209  int theStats = QgsRasterBandStats::All,
210  const QgsRectangle & theExtent = QgsRectangle(),
211  int theSampleSize = 0 );
212 
216  virtual bool hasStatistics( int theBandNo,
217  int theStats = QgsRasterBandStats::All,
218  const QgsRectangle & theExtent = QgsRectangle(),
219  int theSampleSize = 0 );
220 
232  virtual QgsRasterHistogram histogram( int theBandNo,
233  int theBinCount = 0,
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 
243  virtual bool hasHistogram( int theBandNo,
244  int theBinCount,
245  double theMinimum = std::numeric_limits<double>::quiet_NaN(),
246  double theMaximum = std::numeric_limits<double>::quiet_NaN(),
247  const QgsRectangle & theExtent = QgsRectangle(),
248  int theSampleSize = 0,
249  bool theIncludeOutOfRange = false );
250 
260  virtual void cumulativeCut( int theBandNo,
261  double theLowerCount,
262  double theUpperCount,
263  double &theLowerValue,
264  double &theUpperValue,
265  const QgsRectangle & theExtent = QgsRectangle(),
266  int theSampleSize = 0 );
267 
269  virtual void writeXML( QDomDocument& doc, QDomElement& parentElem ) const { Q_UNUSED( doc ); Q_UNUSED( parentElem ); }
271  virtual void readXML( const QDomElement& filterElem ) { Q_UNUSED( filterElem ); }
272 
273  protected:
274  // QgsRasterInterface used as input
276 
279 
282 
283  // On/off state, if off, it does not do anything, replicates input
284  bool mOn;
285 
289  void initHistogram( QgsRasterHistogram &theHistogram, int theBandNo,
290  int theBinCount = 0,
291  double theMinimum = std::numeric_limits<double>::quiet_NaN(),
292  double theMaximum = std::numeric_limits<double>::quiet_NaN(),
293  const QgsRectangle & theExtent = QgsRectangle(),
294  int theSampleSize = 0,
295  bool theIncludeOutOfRange = false );
296 
298  void initStatistics( QgsRasterBandStats &theStatistics, int theBandNo,
299  int theStats = QgsRasterBandStats::All,
300  const QgsRectangle & theExtent = QgsRectangle(),
301  int theBinCount = 0 );
302 
303 };
304 
305 #endif
306 
307 
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:35
bool renderPartialOutput() const
Whether our painter is drawing to a temporary image used just by this layer.
Unknown or unspecified type.
Definition: qgis.h:135
virtual QString generateBandName(int theBandNumber) const
helper function to create zero padded band names
virtual void readXML(const QDomElement &filterElem)
Sets base class members from xml.
virtual QgsRasterInterface * input() const
Current input.
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 QgsRasterBlock * block2(int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback *feedback=nullptr)
Read block of data using given extent and size.
virtual int xBlockSize() const
Get block size.
Base class for feedback objects to be used for cancellation of something running in a worker thread...
Definition: qgsfeedback.h:40
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:34
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.
virtual void writeXML(QDomDocument &doc, QDomElement &parentElem) const
Write base class members to xml.
QgsRasterBlockFeedback(QObject *parent=nullptr)
Construct a new raster block feedback object.
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...
static int typeSize(int dataType)
Base class for processing filters like renderers, reprojector, resampler etc.
virtual QgsRasterInterface * srcInput()
virtual bool setInput(QgsRasterInterface *input)
Set input.
virtual QgsRectangle extent()
Get the extent of the interface.
virtual bool on() const
Is on/off.
virtual int yBlockSize() const
DataType
Raster data types.
Definition: qgis.h:133
bool isPreviewOnly() const
Whether the raster provider should return only data that are already available without waiting for fu...
int dataTypeSize(int bandNo)
virtual const QgsRasterInterface * srcInput() const
Get source / raw input, the first in pipe, usually provider.
The QgsRasterHistogram is a container for histogram of a single raster band.
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
QgsRasterInterface * mInput
Feedback object tailored for raster block reading.
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
virtual int xSize() const
Get raster size.