QGIS API Documentation  2.0.1-Dufour
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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  }
137  virtual QgsRasterInterface * srcInput()
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