QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsheatmaprenderer.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsheatmaprenderer.h
3  ---------------------
4  begin : November 2014
5  copyright : (C) 2014 Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #ifndef QGSHEATMAPRENDERER_H
16 #define QGSHEATMAPRENDERER_H
17 
18 #include "qgis.h"
19 #include "qgsrendererv2.h"
20 #include "qgssymbolv2.h"
21 #include "qgsexpression.h"
22 #include "qgsfeature.h"
23 #include "qgsgeometry.h"
24 #include <QScopedPointer>
25 
27 
33 class CORE_EXPORT QgsHeatmapRenderer : public QgsFeatureRendererV2
34 {
35  public:
36 
38  virtual ~QgsHeatmapRenderer();
39 
40  //reimplemented methods
41  virtual QgsFeatureRendererV2* clone() const override;
42  virtual void startRender( QgsRenderContext& context, const QgsFields& fields ) override;
43  virtual bool renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override;
44  virtual void stopRender( QgsRenderContext& context ) override;
45  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature ) override;
46  virtual QgsSymbolV2List symbols() override;
47  virtual QString dump() const override;
48  virtual QList<QString> usedAttributes() override;
49  static QgsFeatureRendererV2* create( QDomElement& element );
50  virtual QDomElement save( QDomDocument& doc ) override;
51  static QgsHeatmapRenderer* convertFromRenderer( const QgsFeatureRendererV2* renderer );
52 
53  //reimplemented to extent the request so that points up to heatmap's radius distance outside
54  //visible area are included
55  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) override;
56 
57  //heatmap specific methods
58 
63  QgsVectorColorRampV2* colorRamp() const { return mGradientRamp; }
68  void setColorRamp( QgsVectorColorRampV2* ramp );
69 
75  double invertRamp() const { return mInvertRamp; }
81  void setInvertRamp( const bool invert ) { mInvertRamp = invert; }
82 
89  double radius() const { return mRadius; }
96  void setRadius( const double radius ) { mRadius = radius; }
97 
104  QgsSymbolV2::OutputUnit radiusUnit() const { return mRadiusUnit; }
111  void setRadiusUnit( const QgsSymbolV2::OutputUnit unit ) { mRadiusUnit = unit; }
112 
119  const QgsMapUnitScale& radiusMapUnitScale() const { return mRadiusMapUnitScale; }
126  void setRadiusMapUnitScale( const QgsMapUnitScale& scale ) { mRadiusMapUnitScale = scale; }
127 
133  double maximumValue() const { return mExplicitMax; }
139  void setMaximumValue( const double value ) { mExplicitMax = value; }
140 
146  double renderQuality() const { return mRenderQuality; }
152  void setRenderQuality( const int quality ) { mRenderQuality = quality; }
153 
158  QString weightExpression() const { return mWeightExpressionString; }
159 
164  void setWeightExpression( const QString& expression ) { mWeightExpressionString = expression; }
165 
166  private:
170  QgsHeatmapRenderer& operator=( const QgsHeatmapRenderer& );
171 
172  QVector<double> mValues;
173 
174  double mCalculatedMaxValue;
175 
176  double mRadius;
177  int mRadiusPixels;
178  double mRadiusSquared;
179  QgsSymbolV2::OutputUnit mRadiusUnit;
180  QgsMapUnitScale mRadiusMapUnitScale;
181 
182  QString mWeightExpressionString;
183  int mWeightAttrNum;
184  QScopedPointer<QgsExpression> mWeightExpression;
185 
186  QgsVectorColorRampV2* mGradientRamp;
187  bool mInvertRamp;
188 
189  double mExplicitMax;
190  int mRenderQuality;
191 
192  int mFeaturesRendered;
193 
194  double uniformKernel( const double distance, const int bandwidth ) const;
195  double quarticKernel( const double distance, const int bandwidth ) const;
196  double triweightKernel( const double distance, const int bandwidth ) const;
197  double epanechnikovKernel( const double distance, const int bandwidth ) const;
198  double triangularKernel( const double distance, const int bandwidth ) const;
199 
200  QgsMultiPoint convertToMultipoint( QgsGeometry *geom );
201  void initializeValues( QgsRenderContext& context );
202  void renderImage( QgsRenderContext &context );
203 };
204 
205 
206 #endif // QGSHEATMAPRENDERER_H