QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 "qgslogger.h"
27 #include "qgsrasterbandstats.h"
28 #include "qgsrasterblock.h"
29 #include "qgsrasterhistogram.h"
30 #include "qgsrectangle.h"
31 
35 class CORE_EXPORT QgsRasterInterface
36 {
37  Q_DECLARE_TR_FUNCTIONS( QgsRasterInterface );
38 
39  public:
42  {
43  NoCapabilities = 0,
44  Size = 1 << 1, // original data source size (and thus resolution) is known, it is not always available, for example for WMS
45  Create = 1 << 2, // create new datasets
46  Remove = 1 << 3, // delete datasets
47  BuildPyramids = 1 << 4, // supports building of pyramids (overviews)
48  Identify = 1 << 5, // at least one identify format supported
49  IdentifyValue = 1 << 6, // numerical values
50  IdentifyText = 1 << 7, // WMS text
51  IdentifyHtml = 1 << 8, // WMS HTML
52  IdentifyFeature = 1 << 9, // WMS GML -> feature
53  };
54 
56 
57  virtual ~QgsRasterInterface();
58 
60  virtual QgsRasterInterface *clone() const = 0;
61 
63  virtual int capabilities() const
64  {
66  }
67 
71  QString capabilitiesString() const;
72 
74  virtual QGis::DataType dataType( int bandNo ) const = 0;
75 
78  virtual QGis::DataType srcDataType( int bandNo ) const { if ( mInput ) return mInput->srcDataType( bandNo ); else return QGis::UnknownDataType; };
79 
84  virtual QgsRectangle extent() { if ( mInput ) return mInput->extent(); else return QgsRectangle(); }
85 
86  int dataTypeSize( int bandNo ) { return QgsRasterBlock::typeSize( dataType( bandNo ) ); }
87 
89  virtual int bandCount() const = 0;
90 
92  virtual int xBlockSize() const { if ( mInput ) return mInput->xBlockSize(); else return 0; }
93  virtual int yBlockSize() const { if ( mInput ) return mInput->yBlockSize(); else return 0; }
94 
96  virtual int xSize() const { if ( mInput ) return mInput->xSize(); else return 0; }
97  virtual int ySize() const { if ( mInput ) return mInput->ySize(); else return 0; }
98 
100  virtual QString generateBandName( int theBandNumber ) const
101  {
102  return tr( "Band" ) + QString( " %1" ) .arg( theBandNumber, 1 + ( int ) log10(( float ) bandCount() ), 10, QChar( '0' ) );
103  }
104 
113  virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height ) = 0;
114 
117  virtual bool setInput( QgsRasterInterface* input ) { mInput = input; return true; }
118 
120  virtual QgsRasterInterface * input() const { return mInput; }
121 
123  virtual bool on() const { return mOn; }
124 
126  virtual void setOn( bool on ) { mOn = on; }
127 
132  virtual const QgsRasterInterface *srcInput() const
133  {
134  QgsDebugMsg( "Entered" );
135  return mInput ? mInput->srcInput() : this;
136  }
138  {
139  QgsDebugMsg( "Entered" );
140  return mInput ? mInput->srcInput() : this;
141  }
142 
150  virtual QgsRasterBandStats bandStatistics( int theBandNo,
151  int theStats = QgsRasterBandStats::All,
152  const QgsRectangle & theExtent = QgsRectangle(),
153  int theSampleSize = 0 );
154 
158  virtual bool hasStatistics( int theBandNo,
159  int theStats = QgsRasterBandStats::All,
160  const QgsRectangle & theExtent = QgsRectangle(),
161  int theSampleSize = 0 );
162 
174  virtual QgsRasterHistogram histogram( int theBandNo,
175  int theBinCount = 0,
176  double theMinimum = std::numeric_limits<double>::quiet_NaN(),
177  double theMaximum = std::numeric_limits<double>::quiet_NaN(),
178  const QgsRectangle & theExtent = QgsRectangle(),
179  int theSampleSize = 0,
180  bool theIncludeOutOfRange = false );
181 
185  virtual bool hasHistogram( int theBandNo,
186  int theBinCount,
187  double theMinimum = std::numeric_limits<double>::quiet_NaN(),
188  double theMaximum = std::numeric_limits<double>::quiet_NaN(),
189  const QgsRectangle & theExtent = QgsRectangle(),
190  int theSampleSize = 0,
191  bool theIncludeOutOfRange = false );
192 
202  virtual void cumulativeCut( int theBandNo,
203  double theLowerCount,
204  double theUpperCount,
205  double &theLowerValue,
206  double &theUpperValue,
207  const QgsRectangle & theExtent = QgsRectangle(),
208  int theSampleSize = 0 );
209 
211  virtual void writeXML( QDomDocument& doc, QDomElement& parentElem ) const { Q_UNUSED( doc ); Q_UNUSED( parentElem ); }
213  virtual void readXML( const QDomElement& filterElem ) { Q_UNUSED( filterElem ); }
214 
215  protected:
216  // QgsRasterInterface used as input
218 
220  QList <QgsRasterBandStats> mStatistics;
221 
223  QList <QgsRasterHistogram> mHistograms;
224 
225  // On/off state, if off, it does not do anything, replicates input
226  bool mOn;
227 
231  void initHistogram( QgsRasterHistogram &theHistogram, int theBandNo,
232  int theBinCount = 0,
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 
240  void initStatistics( QgsRasterBandStats &theStatistics, int theBandNo,
241  int theStats = QgsRasterBandStats::All,
242  const QgsRectangle & theExtent = QgsRectangle(),
243  int theBinCount = 0 );
244 };
245 
246 #endif
247 
248 
A rectangle specified with double values.
Definition: qgsrectangle.h:35
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
virtual int xBlockSize() const
Get block size.
Definition: qgsrasterinterface.h:92
Definition: qgsrasterbandstats.h:46
bool mOn
Definition: qgsrasterinterface.h:226
virtual void readXML(const QDomElement &filterElem)
Sets base class members from xml.
Definition: qgsrasterinterface.h:213
virtual const QgsRasterInterface * srcInput() const
Get source / raw input, the first in pipe, usually provider.
Definition: qgsrasterinterface.h:132
virtual int yBlockSize() const
Definition: qgsrasterinterface.h:93
virtual QgsRasterInterface * input() const
Current input.
Definition: qgsrasterinterface.h:120
Definition: qgsrasterinterface.h:43
virtual int ySize() const
Definition: qgsrasterinterface.h:97
The RasterBandStats struct is a container for statistics about a single raster band.
Definition: qgsrasterbandstats.h:33
Raster data container.
Definition: qgsrasterblock.h:32
virtual void setOn(bool on)
Set on/off.
Definition: qgsrasterinterface.h:126
QList< QgsRasterHistogram > mHistograms
List of cached histograms, all bands mixed.
Definition: qgsrasterinterface.h:223
virtual void writeXML(QDomDocument &doc, QDomElement &parentElem) const
Write base class members to xml.
Definition: qgsrasterinterface.h:211
virtual QString generateBandName(int theBandNumber) const
helper function to create zero padded band names
Definition: qgsrasterinterface.h:100
static int typeSize(int dataType)
Definition: qgsrasterblock.h:91
DataType
Raster data types.
Definition: qgis.h:204
Base class for processing filters like renderers, reprojector, resampler etc.
Definition: qgsrasterinterface.h:35
virtual QgsRasterInterface * srcInput()
Definition: qgsrasterinterface.h:137
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
Definition: qgsrasterinterface.h:63
virtual bool setInput(QgsRasterInterface *input)
Set input.
Definition: qgsrasterinterface.h:117
virtual QgsRectangle extent()
Get the extent of the interface.
Definition: qgsrasterinterface.h:84
virtual int xSize() const
Get raster size.
Definition: qgsrasterinterface.h:96
Capability
If you add to this, please also add to capabilitiesString()
Definition: qgsrasterinterface.h:41
Definition: qgis.h:206
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...
Definition: qgsrasterinterface.h:78
int dataTypeSize(int bandNo)
Definition: qgsrasterinterface.h:86
The QgsRasterHistogram is a container for histogram of a single raster band.
Definition: qgsrasterhistogram.h:30
QList< QgsRasterBandStats > mStatistics
List of cached statistics, all bands mixed.
Definition: qgsrasterinterface.h:220
QgsRasterInterface * mInput
Definition: qgsrasterinterface.h:217
virtual bool on() const
Is on/off.
Definition: qgsrasterinterface.h:123
#define tr(sourceText)
Definition: qgsrasterrenderer.cpp:27