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.
defaultRenderer return a new renderer - used by default in vector layers
deleteAllClasses
deleteClass
dump
embeddedRenderer Returns the current embedded renderer (subrenderer) for this feature renderer.
filter If a renderer does not require all the features this method may be overridden and return an expression used as where clause.
filterNeedsGeometry Returns true if this renderer requires the geometry to apply the filter.
forceRasterRender Returns whether the renderer must render as a raster.
graduatedMethod return the method used for graduation (either size or color)
labelFormat Return the label format used to generate default classification labels
legendClassificationAttribute
legendKeyForValue Returns the matching legend key for a value.
legendKeysForFeature
legendSymbolItemChecked
legendSymbolItems
legendSymbolItemsCheckable
load create a renderer from XML element
loadSld Create a new renderer according to the information contained in
maxSymbolSize return the max symbol size when graduated by size
minSymbolSize return the min symbol size when graduated by size
mode
modifyRequestExtent Allows for a renderer to modify the extent of a feature request prior to rendering
moveClass Moves the category at index position from to index position to.
orderBy Get the order in which features shall be processed by this renderer.
orderByEnabled Returns whether custom ordering will be applied before features are processed by this renderer.
originalSymbolForFeature
originalSymbolsForFeature Equivalent of originalSymbolsForFeature() call
paintEffect Returns the current paint effect for the renderer.
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.
renderFeature Render a feature using this renderer in the given context.
renderFeatureWithSymbol
renderVertexMarker
renderVertexMarkerPolygon
renderVertexMarkerPolyline
save
setClassAttribute
setDataDefinedSizeLegend Configures appearance of legend when renderer is configured to use data-defined size for marker symbols.
setEmbeddedRenderer Sets an embedded renderer (subrenderer) for this feature renderer.
setForceRasterRender Sets whether the renderer should be rendered to a raster destination.
setGraduatedMethod set the method used for graduation (either size or color)
setLabelFormat Set the label format used to generate default classification labels
setLegendSymbolItem
setMode
setOrderBy Define the order in which features shall be processed by this renderer.
setOrderByEnabled Sets whether custom ordering should be applied before features are processed by this renderer.
setPaintEffect Sets the current paint effect for the renderer.
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
setUsingSymbolLevels
setVertexMarkerAppearance set type and size of editing vertex markers for subsequent rendering
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 attribute index (derived from attribute name in startRender)
symbols
symbolsForFeature Returns list of symbols used for rendering the feature.
toSld
type
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
usingSymbolLevels
willRenderFeature Returns whether the renderer will render a feature or not.
writeSld create the SLD UserStyle element following the SLD v1.1 specs with the given name

Attributes

Custom
EqualInterval
Filter
GraduatedColor
GraduatedSize
Jenks
MoreSymbolsPerFeature
Pretty
Quantile
ScaleDependent
StdDev
SymbolLevels
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

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

New in version 2.10.

labelFormat(self) → QgsRendererRangeLabelFormat

Return 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

return the max symbol size when graduated by size

New in version 2.10.

minSymbolSize(self) → float

return 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

attribute index (derived from attribute name in startRender)

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]