QGIS API Documentation  2.10.1-Pisa
 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( const QgsGeometry *geom );
201  void initializeValues( QgsRenderContext& context );
202  void renderImage( QgsRenderContext &context );
203 };
204 
205 
206 #endif // QGSHEATMAPRENDERER_H
void setInvertRamp(const bool invert)
Sets whether the ramp is inverted.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
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:173
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:75
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:162
void setRadiusUnit(const QgsSymbolV2::OutputUnit unit)
Sets the units used for the heatmap's radius.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
virtual void stopRender(QgsRenderContext &context)=0
virtual QgsSymbolV2List symbols()=0
for symbol levels
virtual bool renderFeature(QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false)
virtual QgsFeatureRendererV2 * clone() const =0
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.
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.
double invertRamp() const
Returns whether the ramp is inverted.
virtual QgsSymbolV2 * symbolForFeature(QgsFeature &feature)=0
to be overridden
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.