|
| 1 | +/** |
| 2 | + * \class QgsKernelDensityEstimation |
| 3 | + * \ingroup analysis |
| 4 | + * Performs Kernel Density Estimation ("heatmap") calculations on a vector layer. |
| 5 | + * @note added in QGIS 3.0 |
| 6 | + */ |
| 7 | +class QgsKernelDensityEstimation |
| 8 | +{ |
| 9 | +%TypeHeaderCode |
| 10 | +#include <qgskde.h> |
| 11 | +%End |
| 12 | + |
| 13 | + public: |
| 14 | + |
| 15 | + //! Kernel shape type |
| 16 | + enum KernelShape |
| 17 | + { |
| 18 | + KernelQuartic, //!< Quartic kernel |
| 19 | + KernelTriangular, //!< Triangular kernel |
| 20 | + KernelUniform, //!< Uniform (flat) kernel |
| 21 | + KernelTriweight, //!< Triweight kernel |
| 22 | + KernelEpanechnikov, //!< Epanechnikov kernel |
| 23 | + }; |
| 24 | + |
| 25 | + //! Output values type |
| 26 | + enum OutputValues |
| 27 | + { |
| 28 | + OutputRaw, //!< Output the raw KDE values |
| 29 | + OutputScaled, //!< Output mathematically correct scaled values |
| 30 | + }; |
| 31 | + |
| 32 | + //! Result of operation |
| 33 | + enum Result |
| 34 | + { |
| 35 | + Success, //!< Operation completed successfully |
| 36 | + DriverError, //!< Could not open the driver for the specified format |
| 37 | + InvalidParameters, //!< Input parameters were not valid |
| 38 | + FileCreationError, //!< Error creating output file |
| 39 | + RasterIoError, //!< Error writing to raster |
| 40 | + }; |
| 41 | + |
| 42 | + //! KDE parameters |
| 43 | + struct Parameters |
| 44 | + { |
| 45 | + //! Vector point layer |
| 46 | + QgsVectorLayer* vectorLayer; |
| 47 | + |
| 48 | + //! Fixed radius, in map units |
| 49 | + double radius; |
| 50 | + |
| 51 | + //! Field for radius, or empty if using a fixed radius |
| 52 | + QString radiusField; |
| 53 | + |
| 54 | + //! Field name for weighting field, or empty if not using weights |
| 55 | + QString weightField; |
| 56 | + |
| 57 | + //! Size of pixel in output file |
| 58 | + double pixelSize; |
| 59 | + |
| 60 | + //! Kernel shape |
| 61 | + QgsKernelDensityEstimation::KernelShape shape; |
| 62 | + |
| 63 | + //! Decay ratio (Triangular kernels only) |
| 64 | + double decayRatio; |
| 65 | + |
| 66 | + //! Type of output value |
| 67 | + QgsKernelDensityEstimation::OutputValues outputValues; |
| 68 | + }; |
| 69 | + |
| 70 | + /** |
| 71 | + * Constructor for QgsKernelDensityEstimation. Requires a Parameters object specifying the options to use |
| 72 | + * to generate the surface. The output path and file format are also required. |
| 73 | + */ |
| 74 | + QgsKernelDensityEstimation( const Parameters& parameters, const QString& outputFile, const QString& outputFormat ); |
| 75 | + |
| 76 | + /** |
| 77 | + * Runs the KDE calculation across the whole layer at once. Either call this method, or manually |
| 78 | + * call run(), addFeature() and finalise() separately. |
| 79 | + */ |
| 80 | + Result run(); |
| 81 | + |
| 82 | + /** |
| 83 | + * Prepares the output file for writing and setups up the surface calculation. This must be called |
| 84 | + * before adding features via addFeature(). |
| 85 | + * @see addFeature() |
| 86 | + * @see finalise() |
| 87 | + */ |
| 88 | + Result prepare(); |
| 89 | + |
| 90 | + /** |
| 91 | + * Adds a single feature to the KDE surface. prepare() must be called before adding features. |
| 92 | + * @see prepare() |
| 93 | + * @see finalise() |
| 94 | + */ |
| 95 | + Result addFeature( const QgsFeature& feature ); |
| 96 | + |
| 97 | + /** |
| 98 | + * Finalises the output file. Must be called after adding all features via addFeature(). |
| 99 | + * @see prepare() |
| 100 | + * @see addFeature() |
| 101 | + */ |
| 102 | + Result finalise(); |
| 103 | + |
| 104 | +}; |
0 commit comments