Class: QgsLabelObstacleSettings

class qgis.core.QgsLabelObstacleSettings

Bases: sip.wrapper

Contains settings related to how the label engine treats features as obstacles

New in version 3.10.2:

Enums

ObstacleType

Bases: enum.IntEnum

Methods

factor

Returns the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels, > 1.0 less likely to be covered

isObstacle

Returns True if the features are obstacles to labels of other layers.

obstacleGeometry

Returns the label's obstacle geometry, if different to the feature geometry.

setFactor

Sets the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels, > 1.0 less likely to be covered

setIsObstacle

Sets whether features are obstacles to labels of other layers.

setObstacleGeometry

Sets the label's obstacle geometry, if different to the feature geometry.

setType

Controls how features act as obstacles for labels.

type

Returns how features act as obstacles for labels.

updateDataDefinedProperties

Updates the obstacle settings to respect any data defined properties set within the specified properties collection.

class ObstacleType(value)

Bases: enum.IntEnum

Valid obstacle types, which affect how features within the layer will act as obstacles for labels.

  • PolygonInterior: Avoid placing labels over interior of polygon (prefer placing labels totally outside or just slightly inside polygon)

  • PolygonBoundary: Avoid placing labels over boundary of polygon (prefer placing outside or completely inside polygon)

  • PolygonWhole: Avoid placing labels over ANY part of polygon. Where PolygonInterior will prefer to place labels with the smallest area of intersection between the label and the polygon, PolygonWhole will penalise any label which intersects with the polygon by an equal amount, so that placing labels over any part of the polygon is avoided

factor(self) float

Returns the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels, > 1.0 less likely to be covered

See also

setFactor()

See also

isObstacle()

See also

type()

Return type:

float

isObstacle(self) bool

Returns True if the features are obstacles to labels of other layers.

See also

setIsObstacle()

See also

factor()

See also

type()

Return type:

bool

obstacleGeometry(self) QgsGeometry

Returns the label’s obstacle geometry, if different to the feature geometry.

Return type:

QgsGeometry

setFactor(self, factor: float)

Sets the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels, > 1.0 less likely to be covered

See also

factor()

See also

isObstacle()

See also

type()

Parameters:

factor (float) –

setIsObstacle(self, isObstacle: bool)

Sets whether features are obstacles to labels of other layers.

See also

isObstacle()

See also

factor()

See also

type()

Parameters:

isObstacle (bool) –

setObstacleGeometry(self, obstacleGeom: QgsGeometry)

Sets the label’s obstacle geometry, if different to the feature geometry. This can be used to override the shape of the feature for obstacle detection, e.g., to buffer around a point geometry to prevent labels being placed too close to the point itself. It not set, the feature’s geometry is used for obstacle detection.

Parameters:

obstacleGeom (QgsGeometry) –

setType(self, type: QgsLabelObstacleSettings.ObstacleType)

Controls how features act as obstacles for labels.

See also

type()

See also

isObstacle()

See also

factor()

Parameters:

type (QgsLabelObstacleSettings.ObstacleType) –

type(self) QgsLabelObstacleSettings.ObstacleType

Returns how features act as obstacles for labels.

See also

setType()

See also

isObstacle()

See also

factor()

Return type:

QgsLabelObstacleSettings.ObstacleType

updateDataDefinedProperties(self, properties: QgsPropertyCollection, context: QgsExpressionContext)

Updates the obstacle settings to respect any data defined properties set within the specified properties collection.

Parameters: