QGIS API Documentation 3.43.0-Master (58029bba303)
qgskde.h
Go to the documentation of this file.
1/***************************************************************************
2 qgskde.h
3 --------
4 Date : October 2016
5 Copyright : (C) 2016 by 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
16#ifndef QGSKDE_H
17#define QGSKDE_H
18
19#include "qgsrectangle.h"
20#include "qgsogrutils.h"
21#include <QString>
22
23// GDAL includes
24#include <gdal.h>
25#include <cpl_string.h>
26#include <cpl_conv.h>
27#include "qgis_analysis.h"
28
30class QgsFeature;
31
32
38class ANALYSIS_EXPORT QgsKernelDensityEstimation
39{
40 public:
43 {
44 Quartic SIP_MONKEYPATCH_COMPAT_NAME( KernelQuartic ) = 0,
45 Triangular SIP_MONKEYPATCH_COMPAT_NAME( KernelTriangular ),
46 Uniform SIP_MONKEYPATCH_COMPAT_NAME( KernelUniform ),
47 Triweight SIP_MONKEYPATCH_COMPAT_NAME( KernelTriweight ),
48 Epanechnikov SIP_MONKEYPATCH_COMPAT_NAME( KernelEpanechnikov ),
49 };
50
57
59 enum class Result : int
60 {
61 Success,
62 DriverError,
63 InvalidParameters,
64 FileCreationError,
65 RasterIoError,
66 };
67
95
100 QgsKernelDensityEstimation( const Parameters &parameters, const QString &outputFile, const QString &outputFormat );
101
104
109 Result run();
110
117 Result prepare();
118
124 Result addFeature( const QgsFeature &feature );
125
131 Result finalise();
132
133 private:
135 double calculateKernelValue( double distance, double bandwidth, KernelShape shape, OutputValues outputType ) const;
137 double uniformKernel( double distance, double bandwidth, OutputValues outputType ) const;
139 double quarticKernel( double distance, double bandwidth, OutputValues outputType ) const;
141 double triweightKernel( double distance, double bandwidth, OutputValues outputType ) const;
143 double epanechnikovKernel( double distance, double bandwidth, OutputValues outputType ) const;
145 double triangularKernel( double distance, double bandwidth, OutputValues outputType ) const;
146
147 QgsRectangle calculateBounds() const;
148
149 QgsFeatureSource *mSource = nullptr;
150
151 QString mOutputFile;
152 QString mOutputFormat;
153
154 int mRadiusField;
155 int mWeightField;
156 double mRadius;
157 double mPixelSize;
158 QgsRectangle mBounds;
159
160 KernelShape mShape;
161 double mDecay;
162 OutputValues mOutputValues;
163
164 int mBufferSize;
165
166 gdal::dataset_unique_ptr mDatasetH;
167 GDALRasterBandH mRasterBandH;
168
170 bool createEmptyLayer( GDALDriverH driver, const QgsRectangle &bounds, int rows, int columns ) const;
171 int radiusSizeInPixels( double radius ) const;
172
173#ifdef SIP_RUN
175#endif
176};
177
178#endif // QGSKDE_H
An interface for objects which provide features via a getFeatures method.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Performs Kernel Density Estimation ("heatmap") calculations on a vector layer.
Definition qgskde.h:39
QgsKernelDensityEstimation(const QgsKernelDensityEstimation &other)=delete
QgsKernelDensityEstimation & operator=(const QgsKernelDensityEstimation &other)=delete
KernelShape
Kernel shape type.
Definition qgskde.h:43
OutputValues
Output values type.
Definition qgskde.h:53
Result
Result of operation.
Definition qgskde.h:60
A rectangle specified with double values.
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
#define SIP_MONKEYPATCH_SCOPEENUM_UNNEST(OUTSIDE_CLASS, FORMERNAME)
Definition qgis_sip.h:271
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:273
QgsKernelDensityEstimation::OutputValues outputValues
Type of output value.
Definition qgskde.h:93
QString radiusField
Field for radius, or empty if using a fixed radius.
Definition qgskde.h:78
double radius
Fixed radius, in map units.
Definition qgskde.h:75
double decayRatio
Decay ratio (Triangular kernels only)
Definition qgskde.h:90
QgsKernelDensityEstimation::KernelShape shape
Kernel shape.
Definition qgskde.h:87
QString weightField
Field name for weighting field, or empty if not using weights.
Definition qgskde.h:81
double pixelSize
Size of pixel in output file.
Definition qgskde.h:84