Class: QgsCategorizedSymbolRenderer

class qgis.core.QgsCategorizedSymbolRenderer(attrName: str = '', categories: object = QgsCategoryList())

Bases: qgis._core.QgsFeatureRenderer

Constructor for QgsCategorizedSymbolRenderer.

The attrName argument specifies the layer’s field name, or expression, which the categories will be matched against.

A list of renderer categories can optionally be specified. If no categories are specified in the constructor, they can be added later by calling addCategory().

Enums

Methods

addCategory

Adds a new category to the renderer.

capabilities

categories

Returns a list of all categories recognized by the renderer.

categoryIndexForLabel

Returns the index of the category with the specified label (or -1 if the label was not found, or is not unique).

categoryIndexForValue

Returns the index for the category with the specified value (or -1 if not found).

checkLegendSymbolItem

classAttribute

Returns the class attribute for the renderer, which is the field name or expression string from the layer which will be matched against the renderer categories.

clone

convertFromRenderer

creates a QgsCategorizedSymbolRenderer from an existing renderer.

convertSymbolRotation

convertSymbolSizeScale

copyRendererData

create

Creates a categorized renderer from an XML element.

createCategories

Create categories for a list of values.

dataDefinedSizeLegend

Returns configuration of appearance of legend when using data-defined size for marker symbols.

deleteAllCategories

Deletes all existing categories from the renderer.

deleteCategory

Deletes the category with the specified index from the renderer.

dump

filter

filterNeedsGeometry

legendClassificationAttribute

legendKeysForFeature

legendSymbolItemChecked

legendSymbolItems

legendSymbolItemsCheckable

matchToSymbols

Replaces category symbols with the symbols from a style that have a matching name and symbol type.

moveCategory

Moves an existing category at index position from to index position to.

originalSymbolForFeature

rebuildHash

hashtable for faster access to symbols

renderFeatureWithSymbol

renderVertexMarker

renderVertexMarkerPolygon

renderVertexMarkerPolyline

save

setClassAttribute

Sets the class attribute for the renderer, which is the field name or expression string from the layer which will be matched against the renderer categories.

setDataDefinedSizeLegend

Configures appearance of legend when renderer is configured to use data-defined size for marker symbols.

setLegendSymbolItem

setSourceColorRamp

Sets the source color ramp.

setSourceSymbol

Sets the source symbol for the renderer, which is the base symbol used for the each categories’ symbol before applying the categories’ color.

skipRender

Deprecated since version No: longer used, will be removed in QGIS 4.0

sortByLabel

Sorts the existing categories by their label.

sortByValue

Sorts the existing categories by their value.

sourceColorRamp

Returns the source color ramp, from which each categories’ color is derived.

sourceSymbol

Returns the renderer’s source symbol, which is the base symbol used for the each categories’ symbol before applying the categories’ color.

startRender

stopRender

symbolForFeature

symbolForValue

Returns the matching symbol corresponding to an attribute value.

symbolForValue2

Returns the matching symbol corresponding to an attribute value.

symbols

toSld

updateCategoryLabel

Changes the label for the category with the specified index.

updateCategoryRenderState

Changes the render state for the category with the specified index.

updateCategorySymbol

Changes the symbol for the category with the specified index.

updateCategoryValue

Changes the value for the category with the specified index.

updateColorRamp

Update the color ramp used and all symbols colors.

updateSymbols

Update all the symbols but leave categories and colors.

usedAttributes

Signals

Attributes

addCategory(self, category: QgsRendererCategory)

Adds a new category to the renderer.

See also

categories()

capabilities(self) → QgsFeatureRenderer.Capabilities
categories(self) → object

Returns a list of all categories recognized by the renderer.

categoryIndexForLabel(self, val: str) → int

Returns the index of the category with the specified label (or -1 if the label was not found, or is not unique).

New in version 2.5.

categoryIndexForValue(self, val: Any) → int

Returns the index for the category with the specified value (or -1 if not found).

checkLegendSymbolItem(self, key: str, state: bool = True)
classAttribute(self) → str

Returns the class attribute for the renderer, which is the field name or expression string from the layer which will be matched against the renderer categories.

clone(self) → QgsCategorizedSymbolRenderer
convertFromRenderer(renderer: QgsFeatureRenderer) → QgsCategorizedSymbolRenderer

creates a QgsCategorizedSymbolRenderer from an existing renderer.

Returns

a new renderer if the conversion was possible, otherwise 0.

New in version 2.5.

convertSymbolRotation()
convertSymbolSizeScale()
copyRendererData()
create(element: QDomElement, context: QgsReadWriteContext) → QgsFeatureRenderer

Creates a categorized renderer from an XML element.

createCategories(values: List[Any], symbol: QgsSymbol, layer: QgsVectorLayer = None, fieldName: str = '') → object

Create categories for a list of values. The returned symbols in the category list will be a modification of symbol.

If layer and fieldName are specified it will try to find nicer values to represent the description for the categories based on the respective field configuration.

New in version 3.6.

dataDefinedSizeLegend(self) → QgsDataDefinedSizeLegend

Returns configuration of appearance of legend when using data-defined size for marker symbols. Will return None if the functionality is disabled.

New in version 3.0.

deleteAllCategories(self)

Deletes all existing categories from the renderer.

See also

deleteCategory()

deleteCategory(self, catIndex: int) → bool

Deletes the category with the specified index from the renderer.

dump(self) → str
filter(self, fields: QgsFields = QgsFields()) → str
filterNeedsGeometry(self) → bool
legendClassificationAttribute(self) → str
legendKeysForFeature(self, feature: QgsFeature, context: QgsRenderContext) → Set[str]
legendSymbolItemChecked(self, key: str) → bool
legendSymbolItems(self) → object
legendSymbolItemsCheckable(self) → bool
matchToSymbols(self, style: QgsStyle, type: QgsSymbol.SymbolType, caseSensitive: bool = True, useTolerantMatch: bool = False) → Tuple[int, List[Any], List[str]]

Replaces category symbols with the symbols from a style that have a matching name and symbol type.

The unmatchedCategories list will be filled with all existing categories which could not be matched to a symbol in style.

The unmatchedSymbols list will be filled with all symbol names from style which were not matched to an existing category.

If caseSensitive is False, then a case-insensitive match will be performed. If useTolerantMatch is True, then non-alphanumeric characters in style and category names will be ignored during the match.

Returns the count of symbols matched.

New in version 3.4.

moveCategory(self, from_: int, to: int)

Moves an existing category at index position from to index position to.

originalSymbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) → QgsSymbol
rebuildHash(self)

hashtable for faster access to symbols

renderFeatureWithSymbol()
renderVertexMarker()
renderVertexMarkerPolygon()
renderVertexMarkerPolyline()
save(self, doc: QDomDocument, context: QgsReadWriteContext) → QDomElement
setClassAttribute(self, attr: str)

Sets the class attribute for the renderer, which is the field name or expression string from the layer which will be matched against the renderer categories.

See also

classAttribute()

setDataDefinedSizeLegend(self, settings: QgsDataDefinedSizeLegend)

Configures appearance of legend when renderer is configured to use data-defined size for marker symbols. This allows configuring for which values (symbol sizes) should be shown in the legend, whether to display different symbol sizes collapsed in one legend node or separated across multiple legend nodes etc.

When renderer does not use data-defined size or does not use marker symbols, these settings will be ignored. Takes ownership of the passed settings objects. None is a valid input that disables data-defined size legend.

New in version 3.0.

setLegendSymbolItem(self, key: str, symbol: QgsSymbol)
setSourceColorRamp(self, ramp: QgsColorRamp)

Sets the source color ramp.

Parameters

ramp – color ramp. Ownership is transferred to the renderer

setSourceSymbol(self, sym: QgsSymbol)

Sets the source symbol for the renderer, which is the base symbol used for the each categories’ symbol before applying the categories’ color.

Parameters

sym – source symbol, ownership is transferred to the renderer

See also

sourceSymbol()

skipRender(self) → QgsSymbol

Deprecated since version No: longer used, will be removed in QGIS 4.0

sortByLabel(self, order: Qt.SortOrder = Qt.AscendingOrder)

Sorts the existing categories by their label.

See also

sortByValue()

sortByValue(self, order: Qt.SortOrder = Qt.AscendingOrder)

Sorts the existing categories by their value.

See also

sortByLabel()

sourceColorRamp(self) → QgsColorRamp

Returns the source color ramp, from which each categories’ color is derived.

See also

sourceSymbol()

sourceSymbol(self) → QgsSymbol

Returns the renderer’s source symbol, which is the base symbol used for the each categories’ symbol before applying the categories’ color.

startRender(self, context: QgsRenderContext, fields: QgsFields)
stopRender(self, context: QgsRenderContext)
symbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) → QgsSymbol
symbolForValue(self, value: Any) → QgsSymbol

Returns the matching symbol corresponding to an attribute value.

Deprecated since version use: variant which takes a second bool argument instead.

symbolForValue2(self, value: Any) → Tuple[QgsSymbol, bool]

Returns the matching symbol corresponding to an attribute value.

Will return None if no matching symbol was found for value, or if the category corresponding to value is currently disabled (see QgsRendererCategory.renderState()).

If foundMatchingSymbol is specified then it will be set to True if a matching category was found. This can be used to differentiate between None returned as a result of no matching category vs None as a result of disabled categories.

Note

available in Python bindings as symbolForValue2

symbols(self, context: QgsRenderContext) → object
toSld(self, doc: QDomDocument, element: QDomElement, props: Dict[str, str] = {})
updateCategoryLabel(self, catIndex: int, label: str) → bool

Changes the label for the category with the specified index.

A category’s label is used to represent the category within legends and the layer tree.

updateCategoryRenderState(self, catIndex: int, render: bool) → bool

Changes the render state for the category with the specified index.

The render state indicates whether or not the category will be rendered, and is reflected in whether the category is checked with the project’s layer tree.

New in version 2.5.

updateCategorySymbol(self, catIndex: int, symbol: QgsSymbol) → bool

Changes the symbol for the category with the specified index.

Ownership of symbol is transferred to the renderer.

updateCategoryValue(self, catIndex: int, value: Any) → bool

Changes the value for the category with the specified index.

If value is a list, then the category will match any of the values from this list.

updateColorRamp(self, ramp: QgsColorRamp)

Update the color ramp used and all symbols colors.

Parameters

ramp – color ramp. Ownership is transferred to the renderer

New in version 2.5.

updateSymbols(self, sym: QgsSymbol)

Update all the symbols but leave categories and colors. This method also sets the source symbol for the renderer.

Parameters

sym – source symbol to use for categories. Ownership is not transferred.

usedAttributes(self, context: QgsRenderContext) → Set[str]