Class: QgsRuleBasedLabeling

class qgis.core.QgsRuleBasedLabeling(root: QgsRuleBasedLabeling.Rule)

Bases: QgsAbstractVectorLayerLabeling

Constructs the labeling from given tree of rules (takes ownership)

New in version 3.0.

Parameters

root

class Rule(settings: QgsPalLayerSettings, maximumScale: float = 0, minimumScale: float = 0, filterExp: str = '', description: str = '', elseRule: bool = False)

Bases: sip.wrapper

takes ownership of settings, settings may be None

New in version 3.0.

Parameters
  • settings (QgsPalLayerSettings) –

  • maximumScale (float = 0) –

  • minimumScale (float = 0) –

  • filterExp (str = '') –

  • description (str = '') –

  • elseRule (bool = False) –

Filtered = 0
Inactive = 1
class RegisterResult

Bases: int

Registered = 2
active(self) → bool

Returns if this rule is active

Return type

bool

Returns

True if the rule is active

appendChild(self, rule: QgsRuleBasedLabeling.Rule)

add child rule, take ownership, sets this as parent

Parameters

rule (QgsRuleBasedLabeling.Rule) –

children(self) → object

Returns all children rules of this rule

Return type

object

Returns

A list of rules

clone(self) → QgsRuleBasedLabeling.Rule

clone this rule, return new instance

Return type

QgsRuleBasedLabeling.Rule

create(ruleElem: QDomElement, context: QgsReadWriteContext) → QgsRuleBasedLabeling.Rule

Create a rule from an XML definition

Parameters
  • ruleElem (QDomElement) – The XML rule element

  • context (QgsReadWriteContext) – reading context

Return type

QgsRuleBasedLabeling.Rule

Returns

A new rule

dependsOnScale(self) → bool

Determines if scale based labeling is active

Return type

bool

Returns

True if scale based labeling is active

descendants(self) → object

Returns all children, grand-children, grand-grand-children, grand-gra… you get it

Return type

object

Returns

A list of descendant rules

description(self) → str

A human readable description for this rule

Return type

str

Returns

Description

filterExpression(self) → str

A filter that will check if this rule applies

Return type

str

Returns

An expression

findRuleByKey(self, key: str) → QgsRuleBasedLabeling.Rule

Try to find a rule given its unique key

Parameters

key (str) –

Return type

QgsRuleBasedLabeling.Rule

insertChild(self, i: int, rule: QgsRuleBasedLabeling.Rule)

add child rule, take ownership, sets this as parent

Parameters
isElse(self) → bool

Check if this rule is an ELSE rule

Return type

bool

Returns

True if this rule is an else rule

maximumScale(self) → float

Returns the maximum map scale (i.e. most “zoomed in” scale) at which the label rule will be active. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no maximum scale visibility.

See also

minimumScale()

New in version 3.0.

Return type

float

minimumScale(self) → float

Returns the minimum map scale (i.e. most “zoomed out” scale) at which the label rule will be active. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no minimum scale visibility.

See also

maximumScale()

New in version 3.0.

Return type

float

parent(self) → QgsRuleBasedLabeling.Rule

The parent rule

Return type

QgsRuleBasedLabeling.Rule

Returns

Parent rule

removeChildAt(self, i: int)

delete child rule

Parameters

i (int) –

requiresAdvancedEffects(self) → bool

Returns true if this rule or any of its children requires advanced composition effects to render.

Return type

bool

ruleKey(self) → str

Unique rule identifier (for identification of rule within labeling, used as provider ID)

Return type

str

save(self, doc: QDomDocument, context: QgsReadWriteContext) → QDomElement

store labeling info to XML element

Parameters
Return type

QDomElement

setActive(self, state: bool)

Sets if this rule is active

Parameters

state (bool) – Determines if the rule should be activated or deactivated

setDescription(self, description: str)

Set a human readable description for this rule

Parameters

description (str) – Description

setFilterExpression(self, filterExp: str)

Set the expression used to check if a given feature shall be rendered with this rule

Parameters

filterExp (str) – An expression

setIsElse(self, iselse: bool)

Sets if this rule is an ELSE rule

Parameters

iselse (bool) – If true, this rule is an ELSE rule

setMaximumScale(self, scale: float)

Sets the maximum map scale (i.e. most “zoomed in” scale) at which the rule will be active. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no maximum scale visibility.

See also

maximumScale()

Parameters

scale (float) –

setMinimumScale(self, scale: float)

Sets the minimum map scale (i.e. most “zoomed out” scale) at which the label rule will be active. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no minimum scale visibility.

See also

minimumScale()

Parameters

scale (float) –

setRuleKey(self, key: str)

Override the assigned rule key (should be used just internally by rule-based labeling)

Parameters

key (str) –

setSettings(self, settings: QgsPalLayerSettings)

Sets new settings (or NULL). Deletes old settings if any.

Parameters

settings (QgsPalLayerSettings) –

settings(self) → QgsPalLayerSettings

Gets the labeling settings. May return a null pointer.

Return type

QgsPalLayerSettings

clone(self) → QgsRuleBasedLabeling
Return type

QgsRuleBasedLabeling

create(element: QDomElement, context: QgsReadWriteContext) → QgsRuleBasedLabeling

Create the instance from a DOM element with saved configuration

Parameters
Return type

QgsRuleBasedLabeling

requiresAdvancedEffects(self) → bool
Return type

bool

rootRule(self) → QgsRuleBasedLabeling.Rule
Return type

QgsRuleBasedLabeling.Rule

save(self, doc: QDomDocument, context: QgsReadWriteContext) → QDomElement
Parameters
Return type

QDomElement

setSettings(self, settings: QgsPalLayerSettings, providerId: str = '')

Set pal settings for a specific provider (takes ownership).

Parameters
  • settings (QgsPalLayerSettings) – Pal layer settings

  • providerId (str = '') – The id of the provider

New in version 3.0.

settings(self, providerId: str = '') → QgsPalLayerSettings
Parameters

providerId (str = '') –

Return type

QgsPalLayerSettings

subProviders(self) → List[str]
Return type

List[str]

toSld(self, parent: QDomNode, props: Dict[str, str])
Parameters
  • parent (QDomNode) –

  • props (Dict[str) –

type(self) → str
Return type

str

writeTextSymbolizer()