Class: QgsKernelDensityEstimation

Performs Kernel Density Estimation (“heatmap”) calculations on a vector layer.

Methods

addFeature

Adds a single feature to the KDE surface.

finalise

Finalises the output file.

prepare

Prepares the output file for writing and setups up the surface calculation.

run

Runs the KDE calculation across the whole layer at once.

Attributes

DriverError

FileCreationError

InvalidParameters

KernelEpanechnikov

KernelQuartic

KernelTriangular

KernelTriweight

KernelUniform

OutputRaw

OutputScaled

RasterIoError

Success

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:
DriverError = 1
FileCreationError = 3
InvalidParameters = 2
KernelEpanechnikov = 4
KernelQuartic = 0
class KernelShape

Bases: int

KernelTriangular = 1
KernelTriweight = 3
KernelUniform = 2
OutputRaw = 0
OutputScaled = 1
class OutputValues

Bases: int

class Parameters

Bases: object

KDE parameters

decayRatio

Decay ratio (Triangular kernels only)

outputValues

Type of output value

pixelSize

Size of pixel in output file

radius

Fixed radius, in map units

radiusField

Field for radius, or empty if using a fixed radius

shape

Kernel shape

source

Point feature source

weightField

Field name for weighting field, or empty if not using weights

RasterIoError = 4
class Result

Bases: int

Success = 0
addFeature(self, feature: QgsFeature) QgsKernelDensityEstimation.Result[source]

Adds a single feature to the KDE surface. prepare() must be called before adding features.

See also

prepare()

See also

finalise()

Parameters:

feature (QgsFeature)

Return type:

QgsKernelDensityEstimation.Result

finalise(self) QgsKernelDensityEstimation.Result[source]

Finalises the output file. Must be called after adding all features via addFeature().

See also

prepare()

See also

addFeature()

Return type:

QgsKernelDensityEstimation.Result

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

addFeature()

See also

finalise()

Return type:

QgsKernelDensityEstimation.Result

run(self) QgsKernelDensityEstimation.Result[source]

Runs the KDE calculation across the whole layer at once. Either call this method, or manually call run(), addFeature() and finalise() separately.

Return type:

QgsKernelDensityEstimation.Result