QGIS API Documentation  2.99.0-Master (c558d51)
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 "qgsrasterbandstats.h"
28 #include "qgsrasterblock.h"
29 #include "qgsrasterhistogram.h"
30 #include "qgsrectangle.h"
31 
37 class CORE_EXPORT QgsRasterBlockFeedback : public QgsFeedback
38 {
39  public:
41  QgsRasterBlockFeedback( QObject* parent = nullptr ) : QgsFeedback( parent ), mPreviewOnly( false ), mRenderPartialOutput( false ) {}
42 
45  virtual void onNewData() {}
46 
50  bool isPreviewOnly() const { return mPreviewOnly; }
53  void setPreviewOnly( bool preview ) { mPreviewOnly = preview; }
54 
57  bool renderPartialOutput() const { return mRenderPartialOutput; }
60  void setRenderPartialOutput( bool enable ) { mRenderPartialOutput = enable; }
61 
62  private:
65  bool mPreviewOnly;
66 
68  bool mRenderPartialOutput;
69 };
70 
71 
75 class CORE_EXPORT QgsRasterInterface
76 {
77  Q_DECLARE_TR_FUNCTIONS( QgsRasterInterface )
78 
79  public:
82  {
83  NoCapabilities = 0,
84  Size = 1 << 1, // original data source size (and thus resolution) is known, it is not always available, for example for WMS
85  Create = 1 << 2, // create new datasets
86  Remove = 1 << 3, // delete datasets
87  BuildPyramids = 1 << 4, // supports building of pyramids (overviews)
88  Identify = 1 << 5, // at least one identify format supported
89  IdentifyValue = 1 << 6, // numerical values
90  IdentifyText = 1 << 7, // WMS text
91  IdentifyHtml = 1 << 8, // WMS HTML
92  IdentifyFeature = 1 << 9, // WMS GML -> feature
93  };
94 
95  QgsRasterInterface( QgsRasterInterface * input = nullptr );
96 
97  virtual ~QgsRasterInterface();
98 
100  virtual QgsRasterInterface *clone() const = 0;
101 
103  virtual int capabilities() const
104  {
106  }
107 
111  QString capabilitiesString() const;
112 
114  virtual Qgis::DataType dataType( int bandNo ) const = 0;
115 
118  virtual Qgis::DataType sourceDataType( int bandNo ) const { return mInput ? mInput->sourceDataType( bandNo ) : Qgis::UnknownDataType; }
119 
124  virtual QgsRectangle extent() const { return mInput ? mInput->extent() : QgsRectangle(); }
125 
126  int dataTypeSize( int bandNo ) { return QgsRasterBlock::typeSize( dataType( bandNo ) ); }
127 
129  virtual int bandCount() const = 0;
130 
132  virtual int xBlockSize() const { return mInput ? mInput->xBlockSize() : 0; }
133  virtual int yBlockSize() const { return mInput ? mInput->yBlockSize() : 0; }
134 
136  virtual int xSize() const { return mInput ? mInput->xSize() : 0; }
137  virtual int ySize() const { return mInput ? mInput->ySize() : 0; }
138 
140  virtual QString generateBandName( int theBandNumber ) const
141  {
142  return tr( "Band" ) + QStringLiteral( " %1" ) .arg( theBandNumber, 1 + static_cast< int >( log10( static_cast< double >( bandCount() ) ) ), 10, QChar( '0' ) );
143  }
144 
154  virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height, QgsRasterBlockFeedback* feedback = nullptr ) = 0;
155 
158  virtual bool setInput( QgsRasterInterface* input ) { mInput = input; return true; }
159 
161  virtual QgsRasterInterface * input() const { return mInput; }
162 
164  virtual bool on() const { return mOn; }
165 
167  virtual void setOn( bool on ) { mOn = on; }
168 
173  virtual const QgsRasterInterface *sourceInput() const
174  {
175  QgsDebugMsgLevel( "Entered", 4 );
176  return mInput ? mInput->sourceInput() : this;
177  }
178 
184  {
185  QgsDebugMsgLevel( "Entered", 4 );
186  return mInput ? mInput->sourceInput() : this;
187  }
188 
196  virtual QgsRasterBandStats bandStatistics( int theBandNo,
197  int theStats = QgsRasterBandStats::All,
198  const QgsRectangle & theExtent = QgsRectangle(),
199  int theSampleSize = 0 );
200 
204  virtual bool hasStatistics( int theBandNo,
205  int theStats = QgsRasterBandStats::All,
206  const QgsRectangle & theExtent = QgsRectangle(),
207  int theSampleSize = 0 );
208 
220  virtual QgsRasterHistogram histogram( int theBandNo,
221  int theBinCount = 0,
222  double theMinimum = std::numeric_limits<double>::quiet_NaN(),
223  double theMaximum = std::numeric_limits<double>::quiet_NaN(),
224  const QgsRectangle & theExtent = QgsRectangle(),
225  int theSampleSize = 0,
226  bool theIncludeOutOfRange = false );
227 
231  virtual bool hasHistogram( int theBandNo,
232  int theBinCount,
233  double theMinimum = std::numeric_limits<double>::quiet_NaN(),
234  double theMaximum = std::numeric_limits<double>::quiet_NaN(),
235  const QgsRectangle & theExtent = QgsRectangle(),
236  int theSampleSize = 0,
237  bool theIncludeOutOfRange = false );
238 
248  virtual void cumulativeCut( int theBandNo,
249  double theLowerCount,
250  double theUpperCount,
251  double &theLowerValue,
252  double &theUpperValue,
253  const QgsRectangle & theExtent = QgsRectangle(),
254  int theSampleSize = 0 );
255 
257  virtual void writeXml( QDomDocument& doc, QDomElement& parentElem ) const { Q_UNUSED( doc ); Q_UNUSED( parentElem ); }
259  virtual void readXml( const QDomElement& filterElem ) { Q_UNUSED( filterElem ); }
260 
261  protected:
262  // QgsRasterInterface used as input
264 
266  QList <QgsRasterBandStats> mStatistics;
267 
269  QList <QgsRasterHistogram> mHistograms;
270 
271  // On/off state, if off, it does not do anything, replicates input
272  bool mOn;
273 
277  void initHistogram( QgsRasterHistogram &theHistogram, int theBandNo,
278  int theBinCount = 0,
279  double theMinimum = std::numeric_limits<double>::quiet_NaN(),
280  double theMaximum = std::numeric_limits<double>::quiet_NaN(),
281  const QgsRectangle & theExtent = QgsRectangle(),
282  int theSampleSize = 0,
283  bool theIncludeOutOfRange = false );
284 
286  void initStatistics( QgsRasterBandStats &theStatistics, int theBandNo,
287  int theStats = QgsRasterBandStats::All,
288  const QgsRectangle & theExtent = QgsRectangle(),
289  int theBinCount = 0 );
290 
291  private:
292  Q_DISABLE_COPY( QgsRasterInterface ) // there is clone() for copying
293 };
294 
295 #endif
296 
297 
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
virtual void readXml(const QDomElement &filterElem)
Sets base class members from xml. Usually called from create() methods of subclasses.
virtual int xBlockSize() const
Get block size.
virtual int yBlockSize() const
DataType
Raster data types.
Definition: qgis.h:60
Capability
If you add to this, please also add to capabilitiesString()
virtual QgsRasterInterface * input() const
Current input.
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 ySize() 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...
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 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.
bool renderPartialOutput() const
Whether our painter is drawing to a temporary image used just by this layer.
Unknown or unspecified type.
Definition: qgis.h:62
virtual QString generateBandName(int theBandNumber) const
helper function to create zero padded band names
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 int capabilities() const
Returns a bitmask containing the supported capabilities.
virtual bool setInput(QgsRasterInterface *input)
Set input.
virtual int xSize() const
Get raster size.
virtual QgsRectangle extent() const
Get the extent of the interface.
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 const QgsRasterInterface * sourceInput() const
Get source / raw input, the first in pipe, usually provider.
QgsRasterInterface * mInput
Feedback object tailored for raster block reading.
bool isPreviewOnly() const
Whether the raster provider should return only data that are already available without waiting for fu...
virtual bool on() const
Is on/off.