Subgroup: other

Class: QgsGraduatedSymbolRenderer

class qgis.core.QgsGraduatedSymbolRenderer(attrName: str = '', ranges: object = QgsRangeList())

Bases: qgis._core.QgsFeatureRenderer

Methods

addBreak Add a breakpoint by splitting existing classes so that the specified value becomes a break between two classes.
addClass
addClassLowerUpper
addClassRange
calculateLabelPrecision Reset the label decimal places to a numberbased on the minimum class interval
capabilities
checkLegendSymbolItem
classAttribute
clone
convertFromRenderer creates a QgsGraduatedSymbolRenderer from an existing renderer.
convertSymbolRotation
convertSymbolSizeScale
copyRendererData
create create renderer from XML element
createRenderer Creates a new graduated renderer.
dataDefinedSizeLegend Returns configuration of appearance of legend when using data-defined size for marker symbols.
deleteAllClasses
deleteClass
dump
graduatedMethod Returns the method used for graduation (either size or color)
labelFormat Returns the label format used to generate default classification labels
legendClassificationAttribute
legendKeyForValue Returns the matching legend key for a value.
legendKeysForFeature
legendSymbolItemChecked
legendSymbolItems
legendSymbolItemsCheckable
maxSymbolSize Returns the max symbol size when graduated by size
minSymbolSize Returns the min symbol size when graduated by size
mode
moveClass Moves the category at index position from to index position to.
originalSymbolForFeature
ranges
rangesHaveGaps Tests whether classes assigned to the renderer have gaps between the ranges.
rangesOverlap Tests whether classes assigned to the renderer have ranges which overlap.
renderFeatureWithSymbol
renderVertexMarker
renderVertexMarkerPolygon
renderVertexMarkerPolyline
save
setClassAttribute
setDataDefinedSizeLegend Configures appearance of legend when renderer is configured to use data-defined size for marker symbols.
setGraduatedMethod set the method used for graduation (either size or color)
setLabelFormat Set the label format used to generate default classification labels
setLegendSymbolItem
setMode
setSourceColorRamp Sets the source color ramp.
setSourceSymbol Sets the source symbol for the renderer, which is the base symbol used for the each classes’ symbol before applying the classes’ color.
setSymbolSizes set varying symbol size for classes
sortByLabel
sortByValue
sourceColorRamp Returns the source color ramp, from which each classes’ color is derived.
sourceSymbol Returns the renderer’s source symbol, which is the base symbol used for the each classes’ symbol before applying the classes’ color.
startRender
stopRender
symbolForFeature
symbolForValue Gets the symbol which is used to represent value.
symbols
toSld
updateClasses Recalculate classes for a layer
updateColorRamp Update the color ramp used.
updateRangeLabel
updateRangeLowerValue
updateRangeRenderState

New in version 2.5.

updateRangeSymbol
updateRangeUpperValue
updateSymbols Update all the symbols but leave breaks and colors.
usedAttributes

Signals

Attributes

Custom
EqualInterval
GraduatedColor
GraduatedSize
Jenks
Pretty
Quantile
StdDev
Custom = 5
EqualInterval = 0
GraduatedColor = 0
class GraduatedMethod

Bases: int

GraduatedSize = 1
Jenks = 2
class Mode

Bases: int

Pretty = 4
Quantile = 1
StdDev = 3
addBreak(self, breakValue: float, updateSymbols: bool = True)

Add a breakpoint by splitting existing classes so that the specified value becomes a break between two classes.

Parameters:
  • breakValue – position to insert break
  • updateSymbols – set to true to reapply ramp colors to the new symbol ranges

New in version 2.9.

addClass(self, symbol: QgsSymbol)
addClassLowerUpper(self, lower: float, upper: float)

Note

available in Python bindings as addClassLowerUpper

addClassRange(self, range: QgsRendererRange)

Note

available in Python bindings as addClassRange

calculateLabelPrecision(self, updateRanges: bool = True)

Reset the label decimal places to a numberbased on the minimum class interval

Parameters:updateRanges – if true then ranges currently using the default label will be updated

New in version 2.6.

capabilities(self) → QgsFeatureRenderer.Capabilities
checkLegendSymbolItem(self, key: str, state: bool = True)
classAttribute(self) → str
clone(self) → QgsGraduatedSymbolRenderer
convertFromRenderer(renderer: QgsFeatureRenderer) → QgsGraduatedSymbolRenderer

creates a QgsGraduatedSymbolRenderer from an existing renderer.

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

New in version 2.6.

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

create renderer from XML element

createRenderer(vlayer: QgsVectorLayer, attrName: str, classes: int, mode: QgsGraduatedSymbolRenderer.Mode, symbol: QgsSymbol, ramp: QgsColorRamp, legendFormat: QgsRendererRangeLabelFormat = QgsRendererRangeLabelFormat()) → QgsGraduatedSymbolRenderer

Creates a new graduated renderer.

Parameters:
  • vlayer – vector layer
  • attrName – attribute to classify
  • classes – number of classes
  • mode – classification mode
  • symbol – base symbol
  • ramp – color ramp for classes
  • legendFormat
Returns:

new QgsGraduatedSymbolRenderer object

dataDefinedSizeLegend(self) → QgsDataDefinedSizeLegend

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

New in version 3.0.

deleteAllClasses(self)
deleteClass(self, idx: int)
dump(self) → str
graduatedMethod(self) → QgsGraduatedSymbolRenderer.GraduatedMethod

Returns the method used for graduation (either size or color)

New in version 2.10.

labelFormat(self) → QgsRendererRangeLabelFormat

Returns the label format used to generate default classification labels

New in version 2.6.

legendClassificationAttribute(self) → str
legendKeyForValue(self, value: float) → str

Returns the matching legend key for a value.

legendKeysForFeature(self, feature: QgsFeature, context: QgsRenderContext) → Set[str]
legendSymbolItemChecked(self, key: str) → bool
legendSymbolItems(self) → object
legendSymbolItemsCheckable(self) → bool
maxSymbolSize(self) → float

Returns the max symbol size when graduated by size

New in version 2.10.

minSymbolSize(self) → float

Returns the min symbol size when graduated by size

New in version 2.10.

mode(self) → QgsGraduatedSymbolRenderer.Mode
moveClass(self, from_: int, to: int)

Moves the category at index position from to index position to.

originalSymbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) → QgsSymbol
ranges(self) → object
rangesHaveGaps(self) → bool

Tests whether classes assigned to the renderer have gaps between the ranges.

Returns:true if ranges have gaps

New in version 2.10.

rangesOverlap(self) → bool

Tests whether classes assigned to the renderer have ranges which overlap.

Returns:true if ranges overlap

New in version 2.10.

renderFeatureWithSymbol()
renderVertexMarker()
renderVertexMarkerPolygon()
renderVertexMarkerPolyline()
save(self, doc: QDomDocument, context: QgsReadWriteContext) → QDomElement
setClassAttribute(self, attr: str)
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. Null pointer is a valid input that disables data-defined size legend.

New in version 3.0.

setGraduatedMethod(self, method: QgsGraduatedSymbolRenderer.GraduatedMethod)

set the method used for graduation (either size or color)

New in version 2.10.

setLabelFormat(self, labelFormat: QgsRendererRangeLabelFormat, updateRanges: bool = False)

Set the label format used to generate default classification labels

Parameters:
  • labelFormat – The string appended to classification labels
  • updateRanges – If true then ranges ending with the old unit string are updated to the new.

New in version 2.6.

setLegendSymbolItem(self, key: str, symbol: QgsSymbol)
setMode(self, mode: QgsGraduatedSymbolRenderer.Mode)
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 classes’ symbol before applying the classes’ color.

Parameters:sym – source symbol, ownership is transferred to the renderer

See also

sourceSymbol()

setSymbolSizes(self, minSize: float, maxSize: float)

set varying symbol size for classes

Note

the classes must already be set so that symbols exist

New in version 2.10.

sortByLabel(self, order: Qt.SortOrder = Qt.AscendingOrder)
sortByValue(self, order: Qt.SortOrder = Qt.AscendingOrder)
sourceColorRamp(self) → QgsColorRamp

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

See also

sourceSymbol()

sourceSymbol(self) → QgsSymbol

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

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

Gets the symbol which is used to represent value.

symbols(self, context: QgsRenderContext) → object
toSld(self, doc: QDomDocument, element: QDomElement, props: Dict[str, str] = {})
updateClasses(self, vlayer: QgsVectorLayer, mode: QgsGraduatedSymbolRenderer.Mode, nclasses: int)

Recalculate classes for a layer

Parameters:
  • vlayer – The layer being rendered (from which data values are calculated)
  • mode – The calculation mode
  • nclasses – The number of classes to calculate (approximate for some modes)

New in version 2.6.

updateColorRamp(self, ramp: QgsColorRamp = None)

Update the color ramp used. Also updates all symbols colors. Doesn’t alter current breaks.

Parameters:ramp – color ramp. Ownership is transferred to the renderer
updateRangeLabel(self, rangeIndex: int, label: str) → bool
updateRangeLowerValue(self, rangeIndex: int, value: float) → bool
updateRangeRenderState(self, rangeIndex: int, render: bool) → bool

New in version 2.5.

updateRangeSymbol(self, rangeIndex: int, symbol: QgsSymbol) → bool
updateRangeUpperValue(self, rangeIndex: int, value: float) → bool
updateSymbols(self, sym: QgsSymbol)

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

Parameters:sym – source symbol to use for classes. Ownership is not transferred.
usedAttributes(self, context: QgsRenderContext) → Set[str]