QGIS API Documentation 3.39.0-Master (bca3cdb6021)
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 "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:
41
51
54 {
55 OutputRaw = 0,
57 };
58
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
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 gdal::dataset_unique_ptr mDatasetH;
169 GDALRasterBandH mRasterBandH;
170
172 bool createEmptyLayer( GDALDriverH driver, const QgsRectangle &bounds, int rows, int columns ) const;
173 int radiusSizeInPixels( double radius ) const;
174
175#ifdef SIP_RUN
177#endif
178};
179
180
181#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
Result
Result of operation.
Definition qgskde.h:61
@ DriverError
Could not open the driver for the specified format.
Definition qgskde.h:63
@ FileCreationError
Error creating output file.
Definition qgskde.h:65
@ RasterIoError
Error writing to raster.
Definition qgskde.h:66
@ Success
Operation completed successfully.
Definition qgskde.h:62
@ InvalidParameters
Input parameters were not valid.
Definition qgskde.h:64
QgsKernelDensityEstimation & operator=(const QgsKernelDensityEstimation &other)=delete
OutputValues
Output values type.
Definition qgskde.h:54
@ OutputScaled
Output mathematically correct scaled values.
Definition qgskde.h:56
KernelShape
Kernel shape type.
Definition qgskde.h:44
@ KernelTriweight
Triweight kernel.
Definition qgskde.h:48
@ KernelUniform
Uniform (flat) kernel.
Definition qgskde.h:47
@ KernelEpanechnikov
Epanechnikov kernel.
Definition qgskde.h:49
@ KernelTriangular
Triangular kernel.
Definition qgskde.h:46
A rectangle specified with double values.
std::unique_ptr< std::remove_pointer< GDALDatasetH >::type, GDALDatasetCloser > dataset_unique_ptr
Scoped GDAL dataset.
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
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