QGIS API Documentation  2.12.0-Lyon
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, QgsRenderContext &context ) override;
46  virtual QgsSymbolV2List symbols( QgsRenderContext &context ) 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  bool invertRamp() const { return mInvertRamp; }
76 
82  void setInvertRamp( const bool invert ) { mInvertRamp = invert; }
83 
90  double radius() const { return mRadius; }
97  void setRadius( const double radius ) { mRadius = radius; }
98 
105  QgsSymbolV2::OutputUnit radiusUnit() const { return mRadiusUnit; }
112  void setRadiusUnit( const QgsSymbolV2::OutputUnit unit ) { mRadiusUnit = unit; }
113 
120  const QgsMapUnitScale& radiusMapUnitScale() const { return mRadiusMapUnitScale; }
127  void setRadiusMapUnitScale( const QgsMapUnitScale& scale ) { mRadiusMapUnitScale = scale; }
128 
134  double maximumValue() const { return mExplicitMax; }
140  void setMaximumValue( const double value ) { mExplicitMax = value; }
141 
147  double renderQuality() const { return mRenderQuality; }
153  void setRenderQuality( const int quality ) { mRenderQuality = quality; }
154 
159  QString weightExpression() const { return mWeightExpressionString; }
160 
165  void setWeightExpression( const QString& expression ) { mWeightExpressionString = expression; }
166 
167  private:
171  QgsHeatmapRenderer& operator=( const QgsHeatmapRenderer& );
172 
173  QVector<double> mValues;
174 
175  double mCalculatedMaxValue;
176 
177  double mRadius;
178  int mRadiusPixels;
179  double mRadiusSquared;
180  QgsSymbolV2::OutputUnit mRadiusUnit;
181  QgsMapUnitScale mRadiusMapUnitScale;
182 
183  QString mWeightExpressionString;
184  int mWeightAttrNum;
185  QScopedPointer<QgsExpression> mWeightExpression;
186 
187  QgsVectorColorRampV2* mGradientRamp;
188  bool mInvertRamp;
189 
190  double mExplicitMax;
191  int mRenderQuality;
192 
193  int mFeaturesRendered;
194 
195  double uniformKernel( const double distance, const int bandwidth ) const;
196  double quarticKernel( const double distance, const int bandwidth ) const;
197  double triweightKernel( const double distance, const int bandwidth ) const;
198  double epanechnikovKernel( const double distance, const int bandwidth ) const;
199  double triangularKernel( const double distance, const int bandwidth ) const;
200 
201  QgsMultiPoint convertToMultipoint( const QgsGeometry *geom );
202  void initializeValues( QgsRenderContext& context );
203  void renderImage( QgsRenderContext &context );
204 };
205 
206 
207 #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:55
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's radius.
double maximumValue() const
Returns the maximum value used for shading the heatmap.
Container of fields for a vector layer.
Definition: qgsfield.h:177
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
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:176
void setRadiusUnit(const QgsSymbolV2::OutputUnit unit)
Sets the units used for the heatmap'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
virtual bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
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'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'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.