QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
Loading...
Searching...
No Matches
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 "qgis_core.h"
20#include "qgis_sip.h"
22#include "qgsexpression.h"
23#include "qgsgeometry.h"
24#include "qgsmapunitscale.h"
25#include "qgsrenderer.h"
26
27class QgsColorRamp;
28
34class CORE_EXPORT QgsHeatmapRenderer : public QgsFeatureRenderer
35{
36 public:
38 ~QgsHeatmapRenderer() override;
39
44
45 //reimplemented methods
46 QgsHeatmapRenderer *clone() const override SIP_FACTORY;
47 void startRender( QgsRenderContext &context, const QgsFields &fields ) override;
48 bool renderFeature( const QgsFeature &feature, QgsRenderContext &context, int layer = -1, bool selected = false, bool drawVertexMarker = false ) override SIP_THROW( QgsCsException );
49 void stopRender( QgsRenderContext &context ) override;
50 QgsSymbol *symbolForFeature( const QgsFeature &feature, QgsRenderContext &context ) const override;
51 QgsSymbolList symbols( QgsRenderContext &context ) const override;
52 QString dump() const override;
53 QSet<QString> usedAttributes( const QgsRenderContext &context ) const override;
55 static QgsFeatureRenderer *create( QDomElement &element, const QgsReadWriteContext &context ) SIP_FACTORY;
56 QDomElement save( QDomDocument &doc, const QgsReadWriteContext &context ) override;
58 bool accept( QgsStyleEntityVisitorInterface *visitor ) const override;
60
61 //reimplemented to extent the request so that points up to heatmap's radius distance outside
62 //visible area are included
63 void modifyRequestExtent( QgsRectangle &extent, QgsRenderContext &context ) override;
64
65 //heatmap specific methods
66
72 QgsColorRamp *colorRamp() const { return mGradientRamp; }
73
79 void setColorRamp( QgsColorRamp *ramp SIP_TRANSFER );
80
87 const QgsColorRampLegendNodeSettings &legendSettings() const { return mLegendSettings; }
88
95 void setLegendSettings( const QgsColorRampLegendNodeSettings &settings );
96
104 double radius() const { return mRadius; }
105
113 void setRadius( const double radius ) { mRadius = radius; }
114
122 Qgis::RenderUnit radiusUnit() const { return mRadiusUnit; }
123
131 void setRadiusUnit( const Qgis::RenderUnit unit ) { mRadiusUnit = unit; }
132
140 const QgsMapUnitScale &radiusMapUnitScale() const { return mRadiusMapUnitScale; }
141
149 void setRadiusMapUnitScale( const QgsMapUnitScale &scale ) { mRadiusMapUnitScale = scale; }
150
157 double maximumValue() const { return mExplicitMax; }
158
165 void setMaximumValue( const double value ) { mExplicitMax = value; }
166
173 double renderQuality() const { return mRenderQuality; }
174
181 void setRenderQuality( const int quality ) { mRenderQuality = quality; }
182
188 QString weightExpression() const { return mWeightExpressionString; }
189
195 void setWeightExpression( const QString &expression ) { mWeightExpressionString = expression; }
196
197 private:
198 QVector<double> mValues;
199
200 double mCalculatedMaxValue = 0;
201
202 double mRadius = 10;
203 int mRadiusPixels = 0;
204 double mRadiusSquared = 0;
206 QgsMapUnitScale mRadiusMapUnitScale;
207
208 QString mWeightExpressionString;
209 int mWeightAttrNum = -1;
210 std::unique_ptr<QgsExpression> mWeightExpression;
211
212 QgsColorRamp *mGradientRamp = nullptr;
213
214 double mExplicitMax = 0.0;
215 int mRenderQuality = 3;
216
217 int mFeaturesRendered = 0;
218
219 QgsColorRampLegendNodeSettings mLegendSettings;
220
221 double uniformKernel( double distance, int bandwidth ) const;
222 double quarticKernel( double distance, int bandwidth ) const;
223 double triweightKernel( double distance, int bandwidth ) const;
224 double epanechnikovKernel( double distance, int bandwidth ) const;
225 double triangularKernel( double distance, int bandwidth ) const;
226
227 QgsMultiPointXY convertToMultipoint( const QgsGeometry *geom );
228 void initializeValues( QgsRenderContext &context );
229 void renderImage( QgsRenderContext &context );
230};
231
232
233#endif // QGSHEATMAPRENDERER_H
RenderUnit
Rendering size units.
Definition qgis.h:5340
@ Millimeters
Millimeters.
Definition qgis.h:5341
Settings for a color ramp legend node.
Abstract base class for color ramps.
Custom exception class for Coordinate Reference System related exceptions.
QgsFeatureRenderer(const QString &type)
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:60
Container of fields for a vector layer.
Definition qgsfields.h:46
A geometry is the spatial representation of a feature.
QString weightExpression() const
Returns the expression used for weighting points when generating the heatmap.
QgsSymbol * symbolForFeature(const QgsFeature &feature, QgsRenderContext &context) const override
To be overridden.
void modifyRequestExtent(QgsRectangle &extent, QgsRenderContext &context) override
Allows for a renderer to modify the extent of a feature request prior to rendering.
void startRender(QgsRenderContext &context, const QgsFields &fields) override
Must be called when a new render cycle is started.
QgsHeatmapRenderer & operator=(const QgsHeatmapRenderer &)=delete
Direct copies are forbidden. Use clone() instead.
QgsColorRamp * colorRamp() const
Returns the color ramp used for shading the heatmap.
QSet< QString > usedAttributes(const QgsRenderContext &context) const override
Returns a list of attributes required by this renderer.
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.
static QgsFeatureRenderer * create(QDomElement &element, const QgsReadWriteContext &context)
Creates a new heatmap renderer instance from XML.
void setRenderQuality(const int quality)
Sets the render quality used for drawing the heatmap.
bool renderFeature(const QgsFeature &feature, QgsRenderContext &context, int layer=-1, bool selected=false, bool drawVertexMarker=false) override
Render a feature using this renderer in the given context.
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.
static QgsHeatmapRenderer * convertFromRenderer(const QgsFeatureRenderer *renderer)
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.
void stopRender(QgsRenderContext &context) override
Must be called when a render cycle has finished, to allow the renderer to clean up.
QString dump() const override
Returns debug information about this renderer.
QDomElement save(QDomDocument &doc, const QgsReadWriteContext &context) override
Stores renderer properties to an XML element.
const QgsMapUnitScale & radiusMapUnitScale() const
Returns the map unit scale used for the heatmap's radius.
QList< QgsLayerTreeModelLegendNode * > createLegendNodes(QgsLayerTreeLayer *nodeLayer) const override
Returns a list of legend nodes to be used for the legend for the renderer.
const QgsColorRampLegendNodeSettings & legendSettings() const
Returns the color ramp legend settings.
bool accept(QgsStyleEntityVisitorInterface *visitor) const override
Accepts the specified symbology visitor, causing it to visit all symbols associated with the renderer...
void setRadiusMapUnitScale(const QgsMapUnitScale &scale)
Sets the map unit scale used for the heatmap's radius.
QgsSymbolList symbols(QgsRenderContext &context) const override
Returns list of symbols used by the renderer.
Layer tree node points to a map layer.
An abstract interface for legend items returned from QgsMapLayerLegend implementation.
Struct for storing maximum and minimum scales for measurements in map units.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
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:227
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_THROW(name,...)
Definition qgis_sip.h:210
QVector< QgsPointXY > QgsMultiPointXY
A collection of QgsPoints that share a common collection of attributes.
Definition qgsgeometry.h:98
QList< QgsSymbol * > QgsSymbolList
Definition qgsrenderer.h:51