QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
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 "qgsogrutils.h"
20 #include <QString>
21 
22 #include "qgis_analysis.h"
23 #include "qgsrectangle.h"
24 #include "qgsrasterdataprovider.h"
25 
26 class QgsFeatureSource;
27 class QgsFeature;
28 
29 
36 class ANALYSIS_EXPORT QgsKernelDensityEstimation
37 {
38  public:
39 
42  {
43  KernelQuartic = 0,
48  };
49 
52  {
53  OutputRaw = 0,
55  };
56 
58  enum Result
59  {
65  };
66 
68  struct Parameters
69  {
71  QgsFeatureSource *source = nullptr;
72 
74  double radius;
75 
77  QString radiusField;
78 
80  QString weightField;
81 
83  double pixelSize;
84 
87 
89  double decayRatio;
90 
93  };
94 
99  QgsKernelDensityEstimation( const Parameters &parameters, const QString &outputFile, const QString &outputFormat );
100 
104  QgsKernelDensityEstimation &operator=( const QgsKernelDensityEstimation &other ) = delete;
105 
110  Result run();
111 
118  Result prepare();
119 
125  Result addFeature( const QgsFeature &feature );
126 
132  Result finalise();
133 
134  private:
135 
137  double calculateKernelValue( double distance, double bandwidth, KernelShape shape, OutputValues outputType ) const;
139  double uniformKernel( double distance, double bandwidth, OutputValues outputType ) const;
141  double quarticKernel( double distance, double bandwidth, OutputValues outputType ) const;
143  double triweightKernel( double distance, double bandwidth, OutputValues outputType ) const;
145  double epanechnikovKernel( double distance, double bandwidth, OutputValues outputType ) const;
147  double triangularKernel( double distance, double bandwidth, OutputValues outputType ) const;
148 
149  QgsRectangle calculateBounds() const;
150 
151  QgsFeatureSource *mSource = nullptr;
152 
153  QString mOutputFile;
154  QString mOutputFormat;
155 
156  int mRadiusField;
157  int mWeightField;
158  double mRadius;
159  double mPixelSize;
160  QgsRectangle mBounds;
161 
162  KernelShape mShape;
163  double mDecay;
164  OutputValues mOutputValues;
165 
166  int mBufferSize;
167 
168  QgsRasterDataProvider *mProvider = nullptr;
169 
170  int radiusSizeInPixels( double radius ) const;
171 
172 #ifdef SIP_RUN
174 #endif
175 };
176 
177 
178 #endif // QGSKDE_H
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QString weightField
Field name for weighting field, or empty if not using weights.
Definition: qgskde.h:80
Uniform (flat) kernel.
Definition: qgskde.h:45
double pixelSize
Size of pixel in output file.
Definition: qgskde.h:83
Performs Kernel Density Estimation ("heatmap") calculations on a vector layer.
Definition: qgskde.h:36
QgsKernelDensityEstimation::KernelShape shape
Kernel shape.
Definition: qgskde.h:86
Error writing to raster.
Definition: qgskde.h:64
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
KernelShape
Kernel shape type.
Definition: qgskde.h:41
OutputValues
Output values type.
Definition: qgskde.h:51
Input parameters were not valid.
Definition: qgskde.h:62
Could not open the driver for the specified format.
Definition: qgskde.h:61
Output mathematically correct scaled values.
Definition: qgskde.h:54
double radius
Fixed radius, in map units.
Definition: qgskde.h:74
Operation completed successfully.
Definition: qgskde.h:60
An interface for objects which provide features via a getFeatures method.
QString radiusField
Field for radius, or empty if using a fixed radius.
Definition: qgskde.h:77
double decayRatio
Decay ratio (Triangular kernels only)
Definition: qgskde.h:89
Result
Result of operation.
Definition: qgskde.h:58
Error creating output file.
Definition: qgskde.h:63
Base class for raster data providers.
QgsKernelDensityEstimation::OutputValues outputValues
Type of output value.
Definition: qgskde.h:92