Class: QgsAbstractLabelingEngineRuleDistanceFromFeature

Base class for labeling engine rules which prevent labels being placed too close or too far from features from a different layer.

Added in version 3.40.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: QgsAbstractLabelingEngineRule.clone(), QgsAbstractLabelingEngineRule.displayType(), QgsAbstractLabelingEngineRule.id()

Class Hierarchy

Inheritance diagram of qgis.core.QgsAbstractLabelingEngineRuleDistanceFromFeature

Base classes

QgsAbstractLabelingEngineRule

Abstract base class for labeling engine rules.

Subclasses

QgsLabelingEngineRuleMaximumDistanceLabelToFeature

A labeling engine rule which prevents labels being placed too far from features from a different layer.

QgsLabelingEngineRuleMinimumDistanceLabelToFeature

A labeling engine rule which prevents labels being placed too close to features from a different layer.

Methods

cost

Returns the penalty cost incurred when the rule is violated.

distance

Returns the acceptable distance threshold between labels and the features from the targetLayer().

distanceUnit

Returns the units for the distance between labels and the features from the targetLayer().

distanceUnitScale

Returns the scaling for the distance between labels and the features from the targetLayer().

labeledLayer

Returns the layer providing the labels.

setCost

Sets the penalty cost incurred when the rule is violated.

setDistance

Sets the acceptable distance threshold between labels and the features from the targetLayer().

setDistanceUnit

Sets the unit for the distance between labels and the features from the targetLayer().

setDistanceUnitScale

Sets the scale for the distance between labels and the features from the targetLayer().

setLabeledLayer

Sets the layer providing the labels.

setTargetLayer

Sets the layer providing the features which labels must be distant from (or close to).

targetLayer

Returns the layer providing the features which labels must be distant from (or close to).

class qgis.core.QgsAbstractLabelingEngineRuleDistanceFromFeature[source]

Bases: QgsAbstractLabelingEngineRule

cost(self) float[source]

Returns the penalty cost incurred when the rule is violated.

This is a value between 0 and 10, where 10 indicates that the rule must never be violated, and 1-9 = nice to have if possible, where higher numbers will try harder to avoid violating the rule.

See also

setCost()

Return type:

float

distance(self) float[source]

Returns the acceptable distance threshold between labels and the features from the targetLayer().

See also

setDistance()

See also

distanceUnit()

Return type:

float

distanceUnit(self) Qgis.RenderUnit[source]

Returns the units for the distance between labels and the features from the targetLayer().

See also

distance()

Return type:

Qgis.RenderUnit

distanceUnitScale(self) QgsMapUnitScale

Returns the scaling for the distance between labels and the features from the targetLayer().

See also

distance()

Return type:

QgsMapUnitScale

labeledLayer(self) QgsMapLayer | None[source]

Returns the layer providing the labels.

Return type:

Optional[QgsMapLayer]

setCost(self, cost: float)[source]

Sets the penalty cost incurred when the rule is violated.

This is a value between 0 and 10, where 10 indicates that the rule must never be violated, and 1-9 = nice to have if possible, where higher numbers will try harder to avoid violating the rule.

See also

cost()

Parameters:

cost (float)

setDistance(self, distance: float)[source]

Sets the acceptable distance threshold between labels and the features from the targetLayer().

See also

distance()

Parameters:

distance (float)

setDistanceUnit(self, unit: Qgis.RenderUnit)[source]

Sets the unit for the distance between labels and the features from the targetLayer().

See also

distanceUnit()

See also

setDistance()

Parameters:

unit (Qgis.RenderUnit)

setDistanceUnitScale(self, scale: QgsMapUnitScale)[source]

Sets the scale for the distance between labels and the features from the targetLayer().

See also

setDistance()

Parameters:

scale (QgsMapUnitScale)

setLabeledLayer(self, layer: QgsMapLayer | None)[source]

Sets the layer providing the labels.

See also

labeledLayer()

Parameters:

layer (Optional[QgsMapLayer])

setTargetLayer(self, layer: QgsVectorLayer | None)[source]

Sets the layer providing the features which labels must be distant from (or close to).

See also

targetLayer()

Parameters:

layer (Optional[QgsVectorLayer])

targetLayer(self) QgsVectorLayer | None[source]

Returns the layer providing the features which labels must be distant from (or close to).

See also

setTargetLayer()

Return type:

Optional[QgsVectorLayer]