QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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_core.h"
19#include "qgis_sip.h"
20#include "qgsrenderer.h"
21#include "qgsexpression.h"
22#include "qgsgeometry.h"
23#include "qgsmapunitscale.h"
24#include "qgis.h"
25
26class QgsColorRamp;
27
34class CORE_EXPORT QgsHeatmapRenderer : public QgsFeatureRenderer
35{
36 public:
37
39 ~QgsHeatmapRenderer() override;
40
45
46 //reimplemented methods
47 QgsHeatmapRenderer *clone() const override SIP_FACTORY;
48 void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
49 bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override SIP_THROW( QgsCsException );
50 void stopRender( QgsRenderContext &context ) override;
52 QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
54 QgsSymbolList symbols( QgsRenderContext &context ) const override;
55 QString dump() const override;
56 QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
58 static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
59 QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) override;
60 static QgsHeatmapRenderer *convertFromRenderer( const QgsFeatureRenderer *renderer ) SIP_FACTORY;
61 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
62
63 //reimplemented to extent the request so that points up to heatmap's radius distance outside
64 //visible area are included
65 void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context ) override;
66
67 //heatmap specific methods
68
74 QgsColorRamp *colorRamp() const { return mGradientRamp; }
75
81 void setColorRamp( QgsColorRamp *ramp SIP_TRANSFER );
82
90 double radius() const { return mRadius; }
91
99 void setRadius( const double radius ) { mRadius = radius; }
100
108 Qgis::RenderUnit radiusUnit() const { return mRadiusUnit; }
109
117 void setRadiusUnit( const Qgis::RenderUnit unit ) { mRadiusUnit = unit; }
118
126 const QgsMapUnitScale &radiusMapUnitScale() const { return mRadiusMapUnitScale; }
127
135 void setRadiusMapUnitScale( const QgsMapUnitScale &scale ) { mRadiusMapUnitScale = scale; }
136
143 double maximumValue() const { return mExplicitMax; }
144
151 void setMaximumValue( const double value ) { mExplicitMax = value; }
152
159 double renderQuality() const { return mRenderQuality; }
160
167 void setRenderQuality( const int quality ) { mRenderQuality = quality; }
168
174 QString weightExpression() const { return mWeightExpressionString; }
175
181 void setWeightExpression( const QString &expression ) { mWeightExpressionString = expression; }
182
183 private:
184
185 QVector<double> mValues;
186
187 double mCalculatedMaxValue = 0;
188
189 double mRadius = 10;
190 int mRadiusPixels = 0;
191 double mRadiusSquared = 0;
192 Qgis::RenderUnit mRadiusUnit = Qgis::RenderUnit::Millimeters;
193 QgsMapUnitScale mRadiusMapUnitScale;
194
195 QString mWeightExpressionString;
196 int mWeightAttrNum = -1;
197 std::unique_ptr<QgsExpression> mWeightExpression;
198
199 QgsColorRamp *mGradientRamp = nullptr;
200
201 double mExplicitMax = 0.0;
202 int mRenderQuality = 3;
203
204 int mFeaturesRendered = 0;
205
206 double uniformKernel( double distance, int bandwidth ) const;
207 double quarticKernel( double distance, int bandwidth ) const;
208 double triweightKernel( double distance, int bandwidth ) const;
209 double epanechnikovKernel( double distance, int bandwidth ) const;
210 double triangularKernel( double distance, int bandwidth ) const;
211
212 QgsMultiPointXY convertToMultipoint( const QgsGeometry *geom );
213 void initializeValues( QgsRenderContext &context );
214 void renderImage( QgsRenderContext &context );
215};
216
217
218#endif // QGSHEATMAPRENDERER_H
RenderUnit
Rendering size units.
Definition: qgis.h:3176
Abstract base class for color ramps.
Definition: qgscolorramp.h:30
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
virtual QgsFeatureRenderer * clone() const =0
Create a deep copy of this renderer.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
Container of fields for a vector layer.
Definition: qgsfields.h:45
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
A renderer which draws points as a live heatmap.
QString weightExpression() const
Returns the expression used for weighting points when generating the heatmap.
QgsHeatmapRenderer & operator=(const QgsHeatmapRenderer &)=delete
Direct copies are forbidden. Use clone() instead.
void setRadius(const double radius)
Sets the radius for the heatmap.
double maximumValue() const
Returns the maximum value used for shading the heatmap.
void setRadiusUnit(const Qgis::RenderUnit unit)
Sets the units used for the heatmap's radius.
double renderQuality() const
Returns the render quality used for drawing the heatmap.
void setRenderQuality(const int quality)
Sets the render quality used for drawing the heatmap.
double radius() const
Returns the radius for the heatmap.
QgsHeatmapRenderer(const QgsHeatmapRenderer &)=delete
Direct copies are forbidden. Use clone() instead.
Qgis::RenderUnit radiusUnit() const
Returns the units used for the heatmap's radius.
void setWeightExpression(const QString &expression)
Sets the expression used for weighting points when generating the heatmap.
void setMaximumValue(const double value)
Sets the maximum value used for shading the heatmap.
const QgsMapUnitScale & radiusMapUnitScale() const
Returns the map unit scale used for the heatmap's radius.
void setRadiusMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the heatmap's radius.
Struct for storing maximum and minimum scales for measurements in map units.
The class is used as a container of context for various read/write operations on other objects.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Contains information about the context of a rendering operation.
An interface for classes which can visit style entity (e.g.
Abstract base class for all rendered symbols.
Definition: qgssymbol.h:93
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_THROW(name,...)
Definition: qgis_sip.h:198
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
Definition: qgsgeometry.h:82
QList< QgsSymbol * > QgsSymbolList
Definition: qgsrenderer.h:44