Class: QgsLabelLineSettings

class qgis.core.QgsLabelLineSettings

Bases: sip.wrapper

Contains settings related to how the label engine places and formats labels for line features (or polygon features which are labeled in a “perimeter” style mode).

New in version 3.16: Enums

AnchorType

Bases: enum.IntEnum

DirectionSymbolPlacement

Bases: enum.IntEnum

Methods

addDirectionSymbol

Returns True if ‘<’ or ‘>’ (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will be automatically added to the label text, pointing in the direction of the line or polygon ring.

anchorType

Returns the line anchor type, which dictates how the lineAnchorPercent() setting is handled.

directionSymbolPlacement

Returns the placement for direction symbols.

leftDirectionSymbol

Returns the string to use for left direction arrows.

lineAnchorPercent

Returns the percent along the line at which labels should be placed.

mergeLines

Returns True if connected line features with identical label text should be merged prior to generating label positions.

overrunDistance

Returns the distance which labels are allowed to overrun past the start or end of line features.

overrunDistanceMapUnitScale

Returns the map unit scale for label overrun distance.

overrunDistanceUnit

Returns the units for label overrun distance.

placementFlags

Returns the line placement flags, which dictate how line labels can be placed above or below the lines.

reverseDirectionSymbol

Returns True if direction symbols should be reversed.

rightDirectionSymbol

Returns the string to use for right direction arrows.

setAddDirectionSymbol

Sets whether ‘<’ or ‘>’ (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will be automatically added to the label text, pointing in the direction of the line or polygon ring.

setAnchorType

Sets the line anchor type, which dictates how the lineAnchorPercent() setting is handled.

setDirectionSymbolPlacement

Sets the placement for direction symbols.

setLeftDirectionSymbol

Sets the string to use for left direction arrows.

setLineAnchorPercent

Sets the percent along the line at which labels should be placed.

setMergeLines

Sets whether connected line features with identical label text should be merged prior to generating label positions.

setOverrunDistance

Sets the distance which labels are allowed to overrun past the start or end of line features.

setOverrunDistanceMapUnitScale

Sets the map unit scale for label overrun distance.

setOverrunDistanceUnit

Sets the unit for label overrun distance.

setPlacementFlags

Returns the line placement flags, which dictate how line labels can be placed above or below the lines.

setReverseDirectionSymbol

Sets whether the direction symbols should be reversed.

setRightDirectionSymbol

Sets the string to use for right direction arrows.

updateDataDefinedProperties

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

class AnchorType(value)

Bases: enum.IntEnum

Line anchor types

  • HintOnly: Line anchor is a hint for preferred placement only, but other placements close to the hint are permitted

  • Strict: Line anchor is a strict placement, and other placements are not permitted

HintOnly = 0
Strict = 1
class DirectionSymbolPlacement(value)

Bases: enum.IntEnum

Placement options for direction symbols.

  • SymbolLeftRight: Place direction symbols on left/right of label

  • SymbolAbove: Place direction symbols on above label

  • SymbolBelow: Place direction symbols on below label

SymbolAbove = 1
SymbolBelow = 2
SymbolLeftRight = 0
addDirectionSymbol(self) → bool

Returns True if ‘<’ or ‘>’ (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will be automatically added to the label text, pointing in the direction of the line or polygon ring.

Return type

bool

anchorType(self)QgsLabelLineSettings.AnchorType

Returns the line anchor type, which dictates how the lineAnchorPercent() setting is handled.

See also

setAnchorType()

Return type

QgsLabelLineSettings.AnchorType

directionSymbolPlacement(self)QgsLabelLineSettings.DirectionSymbolPlacement

Returns the placement for direction symbols.

This setting controls whether to place direction symbols to the left/right, above or below label.

Return type

QgsLabelLineSettings.DirectionSymbolPlacement

leftDirectionSymbol(self) → str

Returns the string to use for left direction arrows.

Return type

str

lineAnchorPercent(self) → float

Returns the percent along the line at which labels should be placed.

By default, this is 0.5 which indicates that labels should be placed as close to the center of the line as possible. A value of 0.0 indicates that the labels should be placed as close to the start of the line as possible, while a value of 1.0 pushes labels towards the end of the line.

See also

anchorType()

Return type

float

mergeLines(self) → bool

Returns True if connected line features with identical label text should be merged prior to generating label positions.

See also

setMergeLines()

Return type

bool

overrunDistance(self) → float

Returns the distance which labels are allowed to overrun past the start or end of line features.

Return type

float

overrunDistanceMapUnitScale(self)QgsMapUnitScale

Returns the map unit scale for label overrun distance.

Return type

QgsMapUnitScale

overrunDistanceUnit(self)QgsUnitTypes.RenderUnit

Returns the units for label overrun distance.

Return type

QgsUnitTypes.RenderUnit

placementFlags(self)QgsLabeling.LinePlacementFlags

Returns the line placement flags, which dictate how line labels can be placed above or below the lines.

Return type

QgsLabeling.LinePlacementFlags

reverseDirectionSymbol(self) → bool

Returns True if direction symbols should be reversed.

Return type

bool

rightDirectionSymbol(self) → str

Returns the string to use for right direction arrows.

Return type

str

setAddDirectionSymbol(self, enabled: bool)

Sets whether ‘<’ or ‘>’ (or custom strings set via leftDirectionSymbol and rightDirectionSymbol) will be automatically added to the label text, pointing in the direction of the line or polygon ring.

Parameters

enabled (bool) –

setAnchorType(self, type: QgsLabelLineSettings.AnchorType)

Sets the line anchor type, which dictates how the lineAnchorPercent() setting is handled.

See also

anchorType()

Parameters

type (QgsLabelLineSettings.AnchorType) –

setDirectionSymbolPlacement(self, placement: QgsLabelLineSettings.DirectionSymbolPlacement)

Sets the placement for direction symbols.

This setting controls whether to place direction symbols to the left/right, above or below label.

Parameters

placement (QgsLabelLineSettings.DirectionSymbolPlacement) –

setLeftDirectionSymbol(self, symbol: str)

Sets the string to use for left direction arrows.

Parameters

symbol (str) –

setLineAnchorPercent(self, percent: float)

Sets the percent along the line at which labels should be placed.

By default, this is 0.5 which indicates that labels should be placed as close to the center of the line as possible. A value of 0.0 indicates that the labels should be placed as close to the start of the line as possible, while a value of 1.0 pushes labels towards the end of the line.

See also

setAnchorType()

Parameters

percent (float) –

setMergeLines(self, merge: bool)

Sets whether connected line features with identical label text should be merged prior to generating label positions.

See also

mergeLines()

Parameters

merge (bool) –

setOverrunDistance(self, distance: float)

Sets the distance which labels are allowed to overrun past the start or end of line features.

Parameters

distance (float) –

setOverrunDistanceMapUnitScale(self, scale: QgsMapUnitScale)

Sets the map unit scale for label overrun distance.

Parameters

scale (QgsMapUnitScale) –

setOverrunDistanceUnit(self, unit: QgsUnitTypes.RenderUnit)

Sets the unit for label overrun distance.

Parameters

unit (QgsUnitTypes.RenderUnit) –

setPlacementFlags(self, flags: Union[QgsLabeling.LinePlacementFlags, QgsLabeling.LinePlacementFlag])

Returns the line placement flags, which dictate how line labels can be placed above or below the lines.

See also

placementFlags()

Parameters

flags (Union[QgsLabeling.LinePlacementFlags) –

setReverseDirectionSymbol(self, reversed: bool)

Sets whether the direction symbols should be reversed.

Parameters

reversed (bool) –

setRightDirectionSymbol(self, symbol: str)

Sets the string to use for right direction arrows.

Parameters

symbol (str) –

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

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

Parameters