QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
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 "qgsrectangle.h"
21
22#include <QString>
23
24// GDAL includes
25#include <gdal.h>
26#include <cpl_string.h>
27#include <cpl_conv.h>
28#include "qgis_analysis.h"
29
31class QgsFeature;
32
33
39class ANALYSIS_EXPORT QgsKernelDensityEstimation
40{
41 public:
44 {
45 Quartic SIP_MONKEYPATCH_COMPAT_NAME( KernelQuartic ) = 0,
46 Triangular SIP_MONKEYPATCH_COMPAT_NAME( KernelTriangular ),
47 Uniform SIP_MONKEYPATCH_COMPAT_NAME( KernelUniform ),
48 Triweight SIP_MONKEYPATCH_COMPAT_NAME( KernelTriweight ),
49 Epanechnikov SIP_MONKEYPATCH_COMPAT_NAME( KernelEpanechnikov ),
50 };
51
58
61 {
62 Success,
63 DriverError,
64 InvalidParameters,
65 FileCreationError,
66 RasterIoError,
67 };
68
96
101 QgsKernelDensityEstimation( const Parameters &parameters, const QString &outputFile, const QString &outputFormat );
102
105
110 Result run();
111
118 Result prepare();
119
125 Result addFeature( const QgsFeature &feature );
126
133
134 private:
136 double calculateKernelValue( double distance, double bandwidth, KernelShape shape, OutputValues outputType ) const;
138 double uniformKernel( double distance, double bandwidth, OutputValues outputType ) const;
140 double quarticKernel( double distance, double bandwidth, OutputValues outputType ) const;
142 double triweightKernel( double distance, double bandwidth, OutputValues outputType ) const;
144 double epanechnikovKernel( double distance, double bandwidth, OutputValues outputType ) const;
146 double triangularKernel( double distance, double bandwidth, OutputValues outputType ) const;
147
148 QgsRectangle calculateBounds() const;
149
150 QgsFeatureSource *mSource = nullptr;
151
152 QString mOutputFile;
153 QString mOutputFormat;
154
155 int mRadiusField = -1;
156 int mWeightField = -1;
157 double mRadius;
158 double mPixelSize;
159 QgsRectangle mBounds;
160
161 KernelShape mShape;
162 double mDecay;
163 OutputValues mOutputValues;
164
165 int mBufferSize = -1;
166
167 gdal::dataset_unique_ptr mDatasetH;
168 GDALRasterBandH mRasterBandH = nullptr;
169
171 bool createEmptyLayer( GDALDriverH driver, const QgsRectangle &bounds, int rows, int columns ) const;
172 int radiusSizeInPixels( double radius ) const;
173
174#ifdef SIP_RUN
176#endif
177};
178
179#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
QgsKernelDensityEstimation(const Parameters &parameters, const QString &outputFile, const QString &outputFormat)
Constructor for QgsKernelDensityEstimation.
Definition qgskde.cpp:24
Result run()
Runs the KDE calculation across the whole layer at once.
Definition qgskde.cpp:41
QgsKernelDensityEstimation(const QgsKernelDensityEstimation &other)=delete
Result addFeature(const QgsFeature &feature)
Adds a single feature to the KDE surface.
Definition qgskde.cpp:104
Result finalise()
Finalises the output file.
Definition qgskde.cpp:203
QgsKernelDensityEstimation & operator=(const QgsKernelDensityEstimation &other)=delete
KernelShape
Kernel shape type.
Definition qgskde.h:44
OutputValues
Output values type.
Definition qgskde.h:54
Result prepare()
Prepares the output file for writing and setups up the surface calculation.
Definition qgskde.cpp:66
Result
Result of operation.
Definition qgskde.h:61
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:268
#define SIP_MONKEYPATCH_COMPAT_NAME(FORMERNAME)
Definition qgis_sip.h:270
QgsKernelDensityEstimation::OutputValues outputValues
Type of output value.
Definition qgskde.h:94
QString radiusField
Field for radius, or empty if using a fixed radius.
Definition qgskde.h:79
double radius
Fixed radius, in map units.
Definition qgskde.h:76
QgsFeatureSource * source
Point feature source.
Definition qgskde.h:73
double decayRatio
Decay ratio (Triangular kernels only).
Definition qgskde.h:91
QgsKernelDensityEstimation::KernelShape shape
Kernel shape.
Definition qgskde.h:88
QString weightField
Field name for weighting field, or empty if not using weights.
Definition qgskde.h:82
double pixelSize
Size of pixel in output file.
Definition qgskde.h:85