Class: QgsGraduatedSymbolRenderer¶
- class qgis.core.QgsGraduatedSymbolRenderer(attrName: str = '', ranges: Iterable[QgsRendererRange] = [])¶
Bases:
QgsFeatureRenderer
Enums
Bases:
enum.IntEnum
Methods
- param visitor:
Add a breakpoint by splitting existing classes so that the specified value becomes a break between two classes.
- param symbol:
Returns if we want to have a central class astride the pivot value
Compute the equal interval classification
Reset the label decimal places to a numberbased on the minimum class interval
- rtype:
QgsFeatureRenderer.Capabilities
- param key:
Returns the attribute name (or expression) used for the classification.
Returns the classification method
- rtype:
QgsGraduatedSymbolRenderer
creates a
QgsGraduatedSymbolRenderer
from an existing renderer.create renderer from XML element
Creates a new graduated renderer.
Returns configuration of appearance of legend when using data-defined size for marker symbols.
- param idx:
- rtype:
str
- rtype:
bool
Returns the method used for graduation (either size or color).
Returns the label format used to generate default classification labels
- rtype:
str
Returns the matching legend key for a value.
- param key:
- param feature:
- param key:
- rtype:
List[QgsLegendSymbolItem]
- rtype:
bool
Remove the breaks that are above the existing opposite sign classes to keep colors symmetrically balanced around symmetryPoint Does not put a break on the symmetryPoint.
Returns the max symbol size when graduated by size
Returns the min symbol size when graduated by size
Deprecated since version QGIS: 3.10
Moves the category at index position from to index position to.
- param feature:
Returns the renderer range matching the provided
value
, orNone
if no range matches the value.Returns a list of all ranges used in the classification.
Tests whether classes assigned to the renderer have gaps between the ranges.
Tests whether classes assigned to the renderer have ranges which overlap.
Render the
feature
with thesymbol
usingcontext
.render editing vertex marker at specified point
render editing vertex marker for a polygon
render editing vertex marker for a polyline
- param doc:
Saves generic renderer data into the specified
element
.Set if we want a central class astride the pivot value
Sets the attribute name (or expression) used for the classification.
Defines the classification method This will take ownership of the method
Configures appearance of legend when renderer is configured to use data-defined size for marker symbols.
Set the
method
used for graduation (either size or color).Set the label format used to generate default classification labels
- param key:
Deprecated since version QGIS: 3.10
Sets the source color ramp.
Sets the source symbol for the renderer, which is the base symbol used for the each classes' symbol before applying the classes' color.
set varying symbol size for classes
Set the pivot point
Set if we want to classify symmetric around a given value
- param order:
- param order:
Returns the source color ramp, from which each classes' color is derived.
Returns the renderer's source symbol, which is the base symbol used for the each classes' symbol before applying the classes' color.
- param context:
- param context:
- param feature:
Gets the symbol which is used to represent
value
.- param context:
Returns the pivot value for symmetric classification
- param doc:
Recalculate classes for a layer
Update the color ramp used.
- param rangeIndex:
Updates the labels of the ranges
- param rangeIndex:
- param rangeIndex:
- param rangeIndex:
- param rangeIndex:
Update all the symbols but leave breaks and colors.
Returns if we want to classify symmetric around a given value
- param context:
Attributes
- Custom = 5¶
- EqualInterval = 0¶
- class GraduatedMethod(value)¶
Bases:
enum.IntEnum
Methods for modifying symbols by range in a graduated symbol renderer.
Note
Prior to QGIS 3.26 this was available as
QgsGraduatedSymbolRenderer
.GraduatedMethodNew in version 3.26.
GraduatedColor
: Alter color of symbolsGraduatedSize
: Alter size of symbols
- Jenks = 2¶
- class Mode¶
Bases:
int
- Pretty = 4¶
- Quantile = 1¶
- StdDev = 3¶
- accept(self, visitor: QgsStyleEntityVisitorInterface) bool ¶
- Parameters:
visitor (QgsStyleEntityVisitorInterface) –
- Return type:
bool
- 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 (float) – position to insert break
updateSymbols (bool = True) – set to
True
to reapply ramp colors to the new symbol ranges
- addClassLowerUpper(self, lower: float, upper: float)¶
Note
available in Python bindings as addClassLowerUpper
- Parameters:
lower (float) –
upper (float) –
- addClassRange(self, range: QgsRendererRange)¶
Note
available in Python bindings as addClassRange
- Parameters:
range (QgsRendererRange) –
- astride(self) bool ¶
Returns if we want to have a central class astride the pivot value
New in version 3.4.
Deprecated since version QGIS: 3.10 use classficationMethod instead
- Return type:
bool
- calcEqualIntervalBreaks(minimum: float, maximum: float, classes: int, useSymmetricMode: bool, symmetryPoint: float, astride: bool) List[float] ¶
Compute the equal interval classification
- Parameters:
minimum (float) – The minimum value of the distribution
maximum (float) – The maximum value of the distribution
classes (int) – The number of classes desired
useSymmetricMode (bool) – A bool indicating if we want to have classes and hence colors ramp symmetric around a value
symmetryPoint (float) – The point around which we want a symmetry
astride (bool) – A bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )
Deprecated since version QGIS: 3.10 use
QgsClassificationEqualInterval
class instead- Return type:
List[float]
- calculateLabelPrecision(self, updateRanges: bool = True)¶
Reset the label decimal places to a numberbased on the minimum class interval
- Parameters:
updateRanges (bool = True) – if
True
then ranges currently using the default label will be updated
- capabilities(self) QgsFeatureRenderer.Capabilities ¶
- Return type:
- checkLegendSymbolItem(self, key: str, state: bool = True)¶
- Parameters:
key (str) –
state (bool = True) –
- classAttribute(self) str ¶
Returns the attribute name (or expression) used for the classification.
See also
- Return type:
str
- classificationMethod(self) QgsClassificationMethod ¶
Returns the classification method
New in version 3.10.
- Return type:
- clone(self) QgsGraduatedSymbolRenderer ¶
- Return type:
- convertFromRenderer(renderer: QgsFeatureRenderer) QgsGraduatedSymbolRenderer ¶
creates a
QgsGraduatedSymbolRenderer
from an existing renderer.- Return type:
- Returns:
a new renderer if the conversion was possible, otherwise
None
.- Parameters:
renderer (QgsFeatureRenderer) –
- convertSymbolRotation(symbol: QgsSymbol, field: str)¶
Note
this function is used to convert old rotations expressions to symbol level DataDefined angle
- convertSymbolSizeScale(symbol: QgsSymbol, method: Qgis.ScaleMethod, field: str)¶
Note
this function is used to convert old sizeScale expressions to symbol level DataDefined size
- create(element: QDomElement, context: QgsReadWriteContext) QgsFeatureRenderer ¶
create renderer from XML element
- Parameters:
element (QDomElement) –
context (QgsReadWriteContext) –
- Return type:
- createRenderer(vlayer: QgsVectorLayer, attrName: str, classes: int, mode: QgsGraduatedSymbolRenderer.Mode, symbol: QgsSymbol, ramp: QgsColorRamp, legendFormat: QgsRendererRangeLabelFormat = QgsRendererRangeLabelFormat(), useSymmetricMode: bool = False, symmetryPoint: float = 0, listForCboPrettyBreaks: Iterable[str] = [], astride: bool = False) QgsGraduatedSymbolRenderer ¶
Creates a new graduated renderer.
- Parameters:
vlayer (QgsVectorLayer) – vector layer
attrName (str) – attribute to classify
classes (int) – number of classes
mode (QgsGraduatedSymbolRenderer.Mode) – classification mode
symbol (QgsSymbol) – base symbol
ramp (QgsColorRamp) – color ramp for classes
legendFormat (
QgsRendererRangeLabelFormat
= QgsRendererRangeLabelFormat()) –useSymmetricMode (bool = False) – A bool indicating if we want to have classes and hence colors ramp symmetric around a value
symmetryPoint (float = 0) – The value around which the classes will be symmetric if useSymmetricMode is checked
listForCboPrettyBreaks (Iterable[str] = []) – The list of potential pivot values for symmetric mode with prettybreaks mode
astride (bool = False) – A bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )
- Return type:
- Returns:
new
QgsGraduatedSymbolRenderer
object
Deprecated since version QGIS: 3.10
- 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.- Return type:
- deleteAllClasses(self)¶
- deleteClass(self, idx: int)¶
- Parameters:
idx (int) –
- dump(self) str ¶
- Return type:
str
- filterNeedsGeometry(self) bool ¶
- Return type:
bool
- graduatedMethod(self) Qgis.GraduatedMethod ¶
Returns the method used for graduation (either size or color).
See also
- Return type:
- labelFormat(self) QgsRendererRangeLabelFormat ¶
Returns the label format used to generate default classification labels
Deprecated since version QGIS: 3.10 use
classificationMethod()
andQgsClassificationMethod
.setLabelFormat instead- Return type:
- legendClassificationAttribute(self) str ¶
- Return type:
str
- legendKeyForValue(self, value: float) str ¶
Returns the matching legend key for a value.
- Parameters:
value (float) –
- Return type:
str
- legendKeyToExpression(self, key: str, layer: QgsVectorLayer) Tuple[str, bool] ¶
- Parameters:
key (str) –
layer (QgsVectorLayer) –
- Return type:
Tuple[str, bool]
- legendKeysForFeature(self, feature: QgsFeature, context: QgsRenderContext) Set[str] ¶
- Parameters:
feature (QgsFeature) –
context (QgsRenderContext) –
- Return type:
Set[str]
- legendSymbolItemChecked(self, key: str) bool ¶
- Parameters:
key (str) –
- Return type:
bool
- legendSymbolItems(self) List[QgsLegendSymbolItem] ¶
- Return type:
List[QgsLegendSymbolItem]
- legendSymbolItemsCheckable(self) bool ¶
- Return type:
bool
- makeBreaksSymmetric(breaks: Iterable[float], symmetryPoint: float, astride: bool) List[float] ¶
Remove the breaks that are above the existing opposite sign classes to keep colors symmetrically balanced around symmetryPoint Does not put a break on the symmetryPoint. This is done before.
- Parameters:
breaks (Iterable[float]) – The breaks of an already-done classification
symmetryPoint (float) – The point around which we want a symmetry
astride (bool) – A bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )
New in version 3.4.
Deprecated since version QGIS: 3.10 use
QgsClassificationMethod
.makeBreaksSymmetric instead- Return type:
List[float]
- maxSymbolSize(self) float ¶
Returns the max symbol size when graduated by size
- Return type:
float
- minSymbolSize(self) float ¶
Returns the min symbol size when graduated by size
- Return type:
float
- mode(self) QgsGraduatedSymbolRenderer.Mode ¶
Deprecated since version QGIS: 3.10 use classficationMethod instead
- Return type:
- moveClass(self, from_: int, to: int)¶
Moves the category at index position from to index position to.
- Parameters:
from (int) –
to (int) –
- originalSymbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) QgsSymbol ¶
- Parameters:
feature (QgsFeature) –
context (QgsRenderContext) –
- Return type:
- rangeForValue(self, value: float) QgsRendererRange ¶
Returns the renderer range matching the provided
value
, orNone
if no range matches the value.New in version 3.10.1.
- Parameters:
value (float) –
- Return type:
- ranges(self) List[QgsRendererRange] ¶
Returns a list of all ranges used in the classification.
- Return type:
List[QgsRendererRange]
- rangesHaveGaps(self) bool ¶
Tests whether classes assigned to the renderer have gaps between the ranges.
- Return type:
bool
- Returns:
True
if ranges have gaps
- rangesOverlap(self) bool ¶
Tests whether classes assigned to the renderer have ranges which overlap.
- Return type:
bool
- Returns:
True
if ranges overlap
- renderFeatureWithSymbol(self, feature: QgsFeature, symbol: QgsSymbol, context: QgsRenderContext, layer: int, selected: bool, drawVertexMarker: bool)¶
Render the
feature
with thesymbol
usingcontext
. Uselayer
to specify the symbol layer,selected
to specify if it should be rendered as selected anddrawVertexMarker
to specify if vertex markers should be rendered.
- renderVertexMarker(self, pt: QPointF | QPoint, context: QgsRenderContext)¶
render editing vertex marker at specified point
- renderVertexMarkerPolygon(self, pts: QPolygonF, rings: Iterable[QPolygonF], context: QgsRenderContext)¶
render editing vertex marker for a polygon
- renderVertexMarkerPolyline(self, pts: QPolygonF, context: QgsRenderContext)¶
render editing vertex marker for a polyline
- save(self, doc: QDomDocument, context: QgsReadWriteContext) QDomElement ¶
- Parameters:
doc (QDomDocument) –
context (QgsReadWriteContext) –
- Return type:
QDomElement
- saveRendererData(self, doc: QDomDocument, element: QDomElement, context: QgsReadWriteContext)¶
Saves generic renderer data into the specified
element
.This method should be called in a subclass’
save()
implementation in order to store all common base class properties in the DOMelement
.New in version 3.22.
- setAstride(self, astride: bool)¶
Set if we want a central class astride the pivot value
New in version 3.4.
Deprecated since version QGIS: 3.10 use classficationMethod instead
- Parameters:
astride (bool) –
- setClassAttribute(self, attr: str)¶
Sets the attribute name (or expression) used for the classification.
See also
- Parameters:
attr (str) –
- setClassificationMethod(self, method: QgsClassificationMethod)¶
Defines the classification method This will take ownership of the method
New in version 3.10.
- Parameters:
method (QgsClassificationMethod) –
- 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.- Parameters:
settings (QgsDataDefinedSizeLegend) –
- setGraduatedMethod(self, method: Qgis.GraduatedMethod)¶
Set the
method
used for graduation (either size or color).See also
- Parameters:
method (Qgis.GraduatedMethod) –
- setLabelFormat(self, labelFormat: QgsRendererRangeLabelFormat, updateRanges: bool = False)¶
Set the label format used to generate default classification labels
- Parameters:
labelFormat (QgsRendererRangeLabelFormat) – The string appended to classification labels
updateRanges (bool = False) – If
True
then ranges ending with the old unit string are updated to the new.
Deprecated since version QGIS: 3.10 use
classificationMethod()
andQgsClassificationMethod
.setLabelFormat instead
- setLegendSymbolItem(self, key: str, symbol: QgsSymbol)¶
- Parameters:
key (str) –
symbol (QgsSymbol) –
- setMode(self, mode: QgsGraduatedSymbolRenderer.Mode)¶
Deprecated since version QGIS: 3.10 use classficationMethod instead
- Parameters:
mode (QgsGraduatedSymbolRenderer.Mode) –
- setSourceColorRamp(self, ramp: QgsColorRamp)¶
Sets the source color ramp.
- Parameters:
ramp (QgsColorRamp) – 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 (QgsSymbol) – source symbol, ownership is transferred to the renderer
See also
See also
- setSymbolSizes(self, minSize: float, maxSize: float)¶
set varying symbol size for classes
Note
the classes must already be set so that symbols exist
- Parameters:
minSize (float) –
maxSize (float) –
- setSymmetryPoint(self, symmetryPoint: float)¶
Set the pivot point
New in version 3.4.
Deprecated since version QGIS: 3.10 use classficationMethod instead
- Parameters:
symmetryPoint (float) –
- setUseSymmetricMode(self, useSymmetricMode: bool)¶
Set if we want to classify symmetric around a given value
New in version 3.4.
Deprecated since version QGIS: 3.10 use classficationMethod instead
- Parameters:
useSymmetricMode (bool) –
- sortByLabel(self, order: Qt.SortOrder = Qt.AscendingOrder)¶
- Parameters:
order (Qt.SortOrder = Qt.AscendingOrder) –
- sortByValue(self, order: Qt.SortOrder = Qt.AscendingOrder)¶
- Parameters:
order (Qt.SortOrder = Qt.AscendingOrder) –
- sourceColorRamp(self) QgsColorRamp ¶
Returns the source color ramp, from which each classes’ color is derived.
See also
See also
- Return type:
- 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.
See also
See also
- Return type:
- startRender(self, context: QgsRenderContext, fields: QgsFields)¶
- Parameters:
context (QgsRenderContext) –
fields (QgsFields) –
- stopRender(self, context: QgsRenderContext)¶
- Parameters:
context (QgsRenderContext) –
- symbolForFeature(self, feature: QgsFeature, context: QgsRenderContext) QgsSymbol ¶
- Parameters:
feature (QgsFeature) –
context (QgsRenderContext) –
- Return type:
- symbolForValue(self, value: float) QgsSymbol ¶
Gets the symbol which is used to represent
value
.- Parameters:
value (float) –
- Return type:
- symbols(self, context: QgsRenderContext) List[QgsSymbol] ¶
- Parameters:
context (QgsRenderContext) –
- Return type:
List[QgsSymbol]
- symmetryPoint(self) float ¶
Returns the pivot value for symmetric classification
New in version 3.4.
Deprecated since version QGIS: 3.10 use classficationMethod instead
- Return type:
float
- toSld(self, doc: QDomDocument, element: QDomElement, props: Dict[str, Any] = {})¶
- Parameters:
doc (QDomDocument) –
element (QDomElement) –
props (Dict[str) –
- updateClasses(self, vlayer: QgsVectorLayer, mode: QgsGraduatedSymbolRenderer.Mode, nclasses: int, useSymmetricMode: bool = False, symmetryPoint: float = 0, astride: bool = False)¶
Recalculate classes for a layer
- Parameters:
vlayer (QgsVectorLayer) – The layer being rendered (from which data values are calculated)
mode (QgsGraduatedSymbolRenderer.Mode) – The calculation mode
nclasses (int) – The number of classes to calculate (approximate for some modes)
useSymmetricMode (bool = False) – A bool indicating if we want to have classes and hence colors ramp symmetric around a value
symmetryPoint (float = 0) – The value around which the classes will be symmetric if useSymmetricMode is checked
astride (bool = False) – A bool indicating if the symmetry is made astride the symmetryPoint or not ( [-1,1] vs. [-1,0][0,1] )
Deprecated since version QGIS: 3.10
updateClasses(self, vl:
QgsVectorLayer
, nclasses: int) Recalculate classes for a layer- Parameters:
vl – The layer being rendered (from which data values are calculated)
nclasses – the number of classes
- updateColorRamp(self, ramp: QgsColorRamp = None)¶
Update the color ramp used. Also updates all symbols colors. Doesn’t alter current breaks.
- Parameters:
ramp (
QgsColorRamp
= None) – color ramp. Ownership is transferred to the renderer
- updateRangeLabel(self, rangeIndex: int, label: str) bool ¶
- Parameters:
rangeIndex (int) –
label (str) –
- Return type:
bool
- updateRangeLabels(self)¶
Updates the labels of the ranges
New in version 3.10.
- updateRangeLowerValue(self, rangeIndex: int, value: float) bool ¶
- Parameters:
rangeIndex (int) –
value (float) –
- Return type:
bool
- updateRangeRenderState(self, rangeIndex: int, render: bool) bool ¶
- Parameters:
rangeIndex (int) –
render (bool) –
- Return type:
bool
- updateRangeSymbol(self, rangeIndex: int, symbol: QgsSymbol) bool ¶
- Parameters:
rangeIndex (int) –
symbol (QgsSymbol) –
- Return type:
bool
- updateRangeUpperValue(self, rangeIndex: int, value: float) bool ¶
- Parameters:
rangeIndex (int) –
value (float) –
- Return type:
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 (QgsSymbol) – source symbol to use for classes. Ownership is not transferred.
See also
- useSymmetricMode(self) bool ¶
Returns if we want to classify symmetric around a given value
New in version 3.4.
Deprecated since version QGIS: 3.10 use classficationMethod instead
- Return type:
bool
- usedAttributes(self, context: QgsRenderContext) Set[str] ¶
- Parameters:
context (QgsRenderContext) –
- Return type:
Set[str]