Class: QgsKernelDensityEstimation¶
Performs Kernel Density Estimation (“heatmap”) calculations on a vector layer.
Enums
Kernel shape type |
|
Output values type |
|
Result of operation |
Methods
Adds a single feature to the KDE surface. |
|
Finalises the output file. |
|
Prepares the output file for writing and setups up the surface calculation. |
|
Runs the KDE calculation across the whole layer at once. |
- class qgis.analysis.QgsKernelDensityEstimation[source]¶
Bases:
object- __init__(parameters: QgsKernelDensityEstimation.Parameters, outputFile: str | None, outputFormat: str | None)
Constructor for QgsKernelDensityEstimation. Requires a Parameters object specifying the options to use to generate the surface. The output path and file format are also required.
- Parameters:
parameters (QgsKernelDensityEstimation.Parameters)
outputFile (Optional[str])
outputFormat (Optional[str])
- class KernelShape(*values)¶
Bases:
IntEnumKernel shape type
Quartic: Quartic kernelAvailable as
QgsKernelDensityEstimation.KernelQuarticin older QGIS releases.Triangular: Triangular kernelAvailable as
QgsKernelDensityEstimation.KernelTriangularin older QGIS releases.Uniform: Uniform (flat) kernelAvailable as
QgsKernelDensityEstimation.KernelUniformin older QGIS releases.Triweight: Triweight kernelAvailable as
QgsKernelDensityEstimation.KernelTriweightin older QGIS releases.Epanechnikov: Epanechnikov kernelAvailable as
QgsKernelDensityEstimation.KernelEpanechnikovin older QGIS releases.
- class OutputValues(*values)¶
Bases:
IntEnumOutput values type
Raw: Output the raw KDE valuesAvailable as
QgsKernelDensityEstimation.OutputRawin older QGIS releases.Scaled: Output mathematically correct scaled valuesAvailable as
QgsKernelDensityEstimation.OutputScaledin older QGIS releases.
- class Parameters¶
Bases:
objectKDE parameters
- decayRatio: float¶
Decay ratio (Triangular kernels only)
- outputValues: QgsKernelDensityEstimation.OutputValues¶
Type of output value
- pixelSize: float¶
Size of pixel in output file
- radius: float¶
Fixed radius, in map units
- radiusField: str¶
Field for radius, or empty if using a fixed radius
- shape: QgsKernelDensityEstimation.KernelShape¶
Kernel shape
- source: QgsFeatureSource¶
Point feature source
- weightField: str¶
Field name for weighting field, or empty if not using weights
- class Result(*values)¶
Bases:
IntEnumResult of operation
Success: Operation completed successfullyDriverError: Could not open the driver for the specified formatInvalidParameters: Input parameters were not validFileCreationError: Error creating output fileRasterIoError: Error writing to raster
- addFeature(self, feature: QgsFeature) QgsKernelDensityEstimation.Result[source]¶
Adds a single feature to the KDE surface.
prepare()must be called before adding features.See also
See also
- Parameters:
feature (QgsFeature)
- Return type:
- finalise(self) QgsKernelDensityEstimation.Result[source]¶
Finalises the output file. Must be called after adding all features via
addFeature().See also
See also
- Return type:
- prepare(self) QgsKernelDensityEstimation.Result[source]¶
Prepares the output file for writing and setups up the surface calculation. This must be called before adding features via
addFeature().See also
See also
- Return type:
- run(self) QgsKernelDensityEstimation.Result[source]¶
Runs the KDE calculation across the whole layer at once. Either call this method, or manually call
run(),addFeature()andfinalise()separately.- Return type: