QGIS API Documentation  2.14.0-Essen
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 QgsHeatmapRenderer* 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;
46  virtual QgsSymbolV2* symbolForFeature( QgsFeature& feature, QgsRenderContext &context ) override;
48  virtual QgsSymbolV2List symbols( QgsRenderContext &context ) override;
49  virtual QString dump() const override;
50  virtual QList<QString> usedAttributes() override;
51  static QgsFeatureRendererV2* create( QDomElement& element );
52  virtual QDomElement save( QDomDocument& doc ) override;
53  static QgsHeatmapRenderer* convertFromRenderer( const QgsFeatureRendererV2* renderer );
54 
55  //reimplemented to extent the request so that points up to heatmap's radius distance outside
56  //visible area are included
57  virtual void modifyRequestExtent( QgsRectangle& extent, QgsRenderContext& context ) override;
58 
59  //heatmap specific methods
60 
65  QgsVectorColorRampV2* colorRamp() const { return mGradientRamp; }
70  void setColorRamp( QgsVectorColorRampV2* ramp );
71 
77  bool invertRamp() const { return mInvertRamp; }
78 
84  void setInvertRamp( const bool invert ) { mInvertRamp = invert; }
85 
92  double radius() const { return mRadius; }
99  void setRadius( const double radius ) { mRadius = radius; }
100 
107  QgsSymbolV2::OutputUnit radiusUnit() const { return mRadiusUnit; }
114  void setRadiusUnit( const QgsSymbolV2::OutputUnit unit ) { mRadiusUnit = unit; }
115 
122  const QgsMapUnitScale& radiusMapUnitScale() const { return mRadiusMapUnitScale; }
129  void setRadiusMapUnitScale( const QgsMapUnitScale& scale ) { mRadiusMapUnitScale = scale; }
130 
136  double maximumValue() const { return mExplicitMax; }
142  void setMaximumValue( const double value ) { mExplicitMax = value; }
143 
149  double renderQuality() const { return mRenderQuality; }
155  void setRenderQuality( const int quality ) { mRenderQuality = quality; }
156 
161  QString weightExpression() const { return mWeightExpressionString; }
162 
167  void setWeightExpression( const QString& expression ) { mWeightExpressionString = expression; }
168 
169  private:
173  QgsHeatmapRenderer& operator=( const QgsHeatmapRenderer& );
174 
175  QVector<double> mValues;
176 
177  double mCalculatedMaxValue;
178 
179  double mRadius;
180  int mRadiusPixels;
181  double mRadiusSquared;
182  QgsSymbolV2::OutputUnit mRadiusUnit;
183  QgsMapUnitScale mRadiusMapUnitScale;
184 
185  QString mWeightExpressionString;
186  int mWeightAttrNum;
187  QScopedPointer<QgsExpression> mWeightExpression;
188 
189  QgsVectorColorRampV2* mGradientRamp;
190  bool mInvertRamp;
191 
192  double mExplicitMax;
193  int mRenderQuality;
194 
195  int mFeaturesRendered;
196 
197  double uniformKernel( const double distance, const int bandwidth ) const;
198  double quarticKernel( const double distance, const int bandwidth ) const;
199  double triweightKernel( const double distance, const int bandwidth ) const;
200  double epanechnikovKernel( const double distance, const int bandwidth ) const;
201  double triangularKernel( const double distance, const int bandwidth ) const;
202 
203  QgsMultiPoint convertToMultipoint( const QgsGeometry *geom );
204  void initializeValues( QgsRenderContext& context );
205  void renderImage( QgsRenderContext &context );
206 };
207 
208 
209 #endif // QGSHEATMAPRENDERER_H
void setInvertRamp(const bool invert)
Sets whether the ramp is inverted.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
OutputUnit
The unit of the output.
Definition: qgssymbolv2.h:62
virtual QString dump() const
for debugging
virtual QDomElement save(QDomDocument &doc)
store renderer info to XML element
virtual void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context)
Allows for a renderer to modify the extent of a feature request prior to rendering.
QgsSymbolV2::OutputUnit radiusUnit() const
Returns the units used for the heatmap&#39;s radius.
double maximumValue() const
Returns the maximum value used for shading the heatmap.
Container of fields for a vector layer.
Definition: qgsfield.h:187
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:76
void setWeightExpression(const QString &expression)
Sets the expression used for weighting points when generating the heatmap.
QgsVectorColorRampV2 * colorRamp() const
Returns the color ramp used for shading the heatmap.
virtual QList< QString > usedAttributes()=0
Returns a set of attributes required for this renderer.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:187
void setRadiusUnit(const QgsSymbolV2::OutputUnit unit)
Sets the units used for the heatmap&#39;s radius.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
Needs to be called when a new render cycle is started.
virtual void stopRender(QgsRenderContext &context)=0
Needs to be called when a render cycle has finished to clean up.
virtual bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
Render a feature using this renderer in the given context.
virtual QgsFeatureRendererV2 * clone() const =0
virtual Q_DECL_DEPRECATED QgsSymbolV2 * symbolForFeature(QgsFeature &feature)
To be overridden.
A renderer which draws points as a live heatmap.
const QgsMapUnitScale & radiusMapUnitScale() const
Returns the map unit scale used for the heatmap&#39;s radius.
double radius() const
Returns the radius for the heatmap.
void setRadiusMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the heatmap&#39;s radius.
virtual Q_DECL_DEPRECATED QgsSymbolV2List symbols()
For symbol levels.
void setRenderQuality(const int quality)
Sets the render quality used for drawing the heatmap.
void setRadius(const double radius)
Sets the radius for the heatmap.
double renderQuality() const
Returns the render quality used for drawing the heatmap.
Contains information about the context of a rendering operation.
Struct for storing maximum and minimum scales for measurements in map units.
bool invertRamp() const
Returns whether the ramp is inverted.
QString weightExpression() const
Returns the expression used for weighting points when generating the heatmap.
void setMaximumValue(const double value)
Sets the maximum value used for shading the heatmap.