Class: QgsSymbolLayerUtils

class qgis.core.QgsSymbolLayerUtils
class qgis.core.QgsSymbolLayerUtils(QgsSymbolLayerUtils)

Bases: sip.wrapper

Enums

VertexMarkerType

Bases: enum.IntEnum

Methods

appendPolyline

Appends a polyline line to an existing target polyline.

applyScaleDependency

Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into the SE Rule element

blurImageInPlace

Blurs an image in place, e.g. creating Qt-independent drop shadows.

clearSymbolLayerIds

Remove recursively unique id from all symbol symbol layers and set an empty string instead

clearSymbolMap

param symbols:

colorFromMimeData

Attempts to parse mime data as a color

colorListFromMimeData

Attempts to parse mime data as a list of named colors

colorListToMimeData

Creates mime data from a list of named colors

colorRampPreviewIcon

Returns an icon preview for a color ramp.

colorRampPreviewPixmap

Returns a pixmap preview for a color ramp.

colorRampToVariant

Saves a color ramp to a QVariantMap, wrapped in a QVariant.

colorToMimeData

Creates mime data from a color.

colorToName

Returns a friendly display name for a color

condenseFillAndOutline

Attempts to condense a fill and outline layer, by moving the outline layer to the fill symbol's stroke.

convertPolygonSymbolizerToPointMarker

Converts a polygon symbolizer element to a list of marker symbol layers.

createAnchorPointElement

Creates a SE 1.1 anchor point element as a child of the specified element

createDisplacementElement

param doc:

createExpressionElement

Creates a OGC Expression element based on the provided function expression

createFillLayerFromSld

param element:

createFunctionElement

param doc:

createGeometryElement

param doc:

createLineLayerFromSld

param element:

createMarkerLayerFromSld

param element:

createOnlineResourceElement

param doc:

createOpacityElement

param doc:

createRotationElement

param doc:

createSvgParameterElement

param doc:

createSymbolLayerListFromSld

Creates a symbol layer list from a DOM element.

createVendorOptionElement

param doc:

decodeArrowHeadType

Decodes a value representing an arrow head type.

decodeArrowType

Decodes a value representing an arrow type.

decodeBlendMode

param s:

decodeBrushStyle

param str:

decodeColor

param str:

decodeCoordinateReference

Decodes a string representing a symbol coordinate reference mode.

decodeLineClipMode

Decodes a string representing a line clip mode.

decodeMapUnitScale

param str:

decodeMarkerClipMode

Decodes a string representing a marker clip mode.

decodePenCapStyle

param str:

decodePenJoinStyle

param str:

decodePenStyle

param str:

decodePoint

Decodes a QSizeF from a string.

decodeRealVector

param s:

decodeScaleMethod

Decodes a symbol scale method from a string.

decodeSize

Decodes a QSizeF from a string.

decodeSldAlpha

param str:

decodeSldBrushStyle

param str:

decodeSldFontStyle

param str:

decodeSldFontWeight

param str:

decodeSldLineCapStyle

param str:

decodeSldLineJoinStyle

param str:

decodeSldRealVector

param s:

decodeSldUom

Decodes a SLD unit of measure string to a render unit.

displacementFromSldElement

param element:

drawStippledBackground

param painter:

drawVertexMarker

Draws a vertex symbol at (painter) coordinates x, y.

encodeBrushStyle

param style:

encodeColor

param color:

encodeCoordinateReference

Encodes a symbol coordinate reference mode to a string.

encodeLineClipMode

Encodes a line clip mode to a string.

encodeMapUnitScale

param mapUnitScale:

encodeMarkerClipMode

Encodes a marker clip mode to a string.

encodePenCapStyle

param style:

encodePenJoinStyle

param style:

encodePenStyle

param style:

encodePoint

Encodes a QPointF to a string.

encodeRealVector

param v:

encodeScaleMethod

Encodes a symbol scale method to a string.

encodeSize

Encodes a QSizeF to a string.

encodeSldAlpha

param alpha:

encodeSldBrushStyle

param style:

encodeSldFontStyle

param style:

encodeSldFontWeight

param weight:

encodeSldLineCapStyle

param style:

encodeSldLineJoinStyle

param style:

encodeSldRealVector

param v:

encodeSldUom

Encodes a render unit into an SLD unit of measure string.

estimateMaxSymbolBleed

Returns the maximum estimated bleed for the symbol

evaluatePropertiesMap

Evaluates a map of properties using the given context and returns a variant map with evaluated expressions from the properties.

externalGraphicFromSld

param element:

externalGraphicToSld

param doc:

externalMarkerFromSld

param element:

externalMarkerToSld

param doc:

fieldOrExpressionFromExpression

Returns a field name if the whole expression is just a name of the field .

fieldOrExpressionToExpression

Returns a new valid expression instance for given field or expression string.

fillFromSld

param element:

fillToSld

param doc:

functionFromSldElement

param element:

geometryFromSldElement

param element:

getSvgParameterList

param element:

getSvgParametricPath

Encodes a reference to a parametric SVG into a path with parameters according to the SVG Parameters spec

getVendorOptionList

param element:

hasExternalGraphic

Checks if element contains an ExternalGraphic element with format "image/svg+xml" @return True if the ExternalGraphic with format "image/svg+xml" is found .

hasExternalGraphicV2

Checks if element contains an ExternalGraphic element, if the optional format is specified it will also be checked.

hasWellKnownMark

param element:

importColorsFromGpl

Imports colors from a gpl GIMP palette file

isSharpCorner

Returns True if the angle formed by the line p1 - p2 - p3 forms a "sharp" corner.

labelTextToSld

param doc:

lineFromSld

param element:

listSvgFiles

Returns a list of all available svg files

listSvgFilesAt

Returns a list of svg files at the specified directory

loadColorRamp

Creates a color ramp from the settings encoded in an XML element

loadSymbol

Attempts to load a symbol from a DOM element

loadSymbolLayer

Reads and returns symbol layer from XML.

loadSymbols

Reads a collection of symbols from XML and returns them in a map.

mergeScaleDependencies

Merges the local scale limits, if any, with the ones already in the map, if any

multiplyImageOpacity

Multiplies opacity of image pixel values with a (global) transparency value.

needEllipseMarker

param element:

needFontMarker

param element:

needLinePatternFill

param element:

needMarkerLine

param element:

needPointPatternFill

param element:

needRasterImageFill

Checks if element contains a graphic fill with a raster image of type PNG, JPEG or GIF.

needSvgFill

param element:

needSvgMarker

param element:

ogrFeatureStyleBrush

Create ogr feature style string for brush

ogrFeatureStylePen

Create ogr feature style string for pen

onlineResourceFromSldElement

param element:

opacityFromSldElement

param element:

parametricSvgToSld

Encodes a reference to a parametric SVG into SLD, as a succession of parametric SVG using URL parameters, a fallback SVG without parameters, and a final fallback as a mark with the right colors and stroke for systems that cannot do SVG at all

parseColor

Attempts to parse a string as a color using a variety of common formats, including hex codes, rgb and rgba strings.

parseColorList

Attempts to parse a string as a list of colors using a variety of common formats, including hex codes, rgb and rgba strings.

parseColorWithAlpha

Attempts to parse a string as a color using a variety of common formats, including hex codes, rgb and rgba, hsl and hsla strings.

parseProperties

Parses the properties from XML and returns a map

pointInPolygon

Calculate whether a point is within of a QPolygonF

pointOnLineWithDistance

Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point

polygonCentroid

Calculate the centroid point of a QPolygonF

polygonPointOnSurface

Calculate a point on the surface of a QPolygonF

polylineLength

Returns the total length of a polyline.

polylineSubstring

Returns the substring of a polyline which starts at startOffset from the beginning of the line and ends at endOffset from the start of the line.

premultiplyColor

Converts a QColor into a premultiplied ARGB QColor value using a specified alpha value

prettyBreaks

Computes a sequence of about 'classes' equally spaced round values which cover the range of values from 'minimum' to 'maximum'.

rendererFrameRate

Calculates the frame rate (in frames per second) at which the given renderer must be redrawn.

rescaleArrayUom

Rescales the given array based on the uomScale found in the props, if any is found, otherwise returns a copy of the original point

rescalePointUom

Rescales the given point based on the uomScale found in the props, if any is found, otherwise returns a copy of the original point

rescaleUom

Rescales the given size based on the uomScale found in the props, if any is found, otherwise returns the value un-modified

resetSymbolLayerIds

Regenerate recursively unique id from all symbol symbol layers

restrictedSizeSymbol

Creates a new symbol with size restricted to min/max size if original size is out of min/max range

rotationFromSldElement

param element:

saveColorRamp

Encodes a color ramp's settings to an XML element

saveColorsToGpl

Exports colors to a gpl GIMP palette file

saveProperties

Saves the map of properties to XML

saveSymbol

Writes a symbol definition to XML

saveSymbols

Writes a collection of symbols to XML with specified tagName for the top-level element

sizeInPixelsFromSldUom

Returns the size scaled in pixels according to the uom attribute.

sortVariantList

Sorts the passed list in requested order

svgSymbolNameToPath

Determines an SVG symbol's path from its name.

svgSymbolPathToName

Determines an SVG symbol's name from its path.

symbolFromMimeData

Attempts to parse mime data as a symbol.

symbolLayerPreviewIcon

Draws a symbol layer preview to an icon.

symbolLayerPreviewPicture

Draws a symbol layer preview to a QPicture

symbolPreviewIcon

Returns an icon preview for a color ramp.

symbolPreviewPixmap

Returns a pixmap preview for a color ramp.

symbolProperties

Returns a string representing the symbol.

symbolToMimeData

Creates new mime data from a symbol.

tileSize

Calculate the minimum size in pixels of a symbol tile given the symbol width and height and the symbol layer rotation angleRad in radians (counter clockwise).

toPoint

Converts a value to a point.

toSize

Converts a value to a size.

toSymbolLayerPointers

Converts a set of symbol layer id to a set of pointers to actual symbol layers carried by the feature renderer.

wellKnownMarkerFromSld2

wellKnownMarkerToSld

param doc:

class VertexMarkerType(value)

Bases: enum.IntEnum

Editing vertex markers, used for showing vertices during a edit operation.

New in version 3.22.

  • SemiTransparentCircle: Semi-transparent circle marker

  • Cross: Cross marker

  • NoMarker: No marker

baseClass

alias of Qgis

appendPolyline(target: QPolygonF, line: QPolygonF)

Appends a polyline line to an existing target polyline.

Any duplicate points at the start line which match the end point from target will be skipped.

New in version 3.16.

Parameters:
  • target (QPolygonF) –

  • line (QPolygonF) –

applyScaleDependency(doc: QDomDocument, ruleElem: QDomElement, props: Dict[str, Any])

Checks if the properties contain scaleMinDenom and scaleMaxDenom, if available, they are added into the SE Rule element

Parameters:
  • doc (QDomDocument) –

  • ruleElem (QDomElement) –

  • props (Dict[str) –

blurImageInPlace(image: QImage, rect: QRect, radius: int, alphaOnly: bool)

Blurs an image in place, e.g. creating Qt-independent drop shadows

Parameters:
  • image (QImage) –

  • rect (QRect) –

  • radius (int) –

  • alphaOnly (bool) –

clearSymbolLayerIds(symbol: QgsSymbol)

Remove recursively unique id from all symbol symbol layers and set an empty string instead

New in version 3.30.

clearSymbolLayerIds(symbolLayer: QgsSymbolLayer) Remove recursively unique id from symbolLayer and its children and set an empty string instead

New in version 3.30.

Parameters:

symbol (QgsSymbol) –

clearSymbolMap(symbols: object)
Parameters:

symbols (object) –

colorFromMimeData(data: QMimeData) Tuple[QColor, bool]

Attempts to parse mime data as a color

Parameters:

data (QMimeData) – mime data to parse

Return type:

Tuple[QColor, bool]

Returns:

  • valid color if mimedata could be interpreted as a color, otherwise an invalid color

  • hasAlpha: will be set to True if mime data was interpreted as a color containing an explicit alpha value

colorListFromMimeData(data: QMimeData) List[Tuple[QColor, str]]

Attempts to parse mime data as a list of named colors

Parameters:

data (QMimeData) – mime data to parse

Return type:

List[Tuple[QColor, str]]

Returns:

list of parsed colors

colorListToMimeData(colorList: Iterable[Tuple[QColor | Qt.GlobalColor | QGradient, str]], allFormats: bool = True) QMimeData

Creates mime data from a list of named colors

Parameters:
  • colorList (Iterable[Tuple[Union[QColor) – list of named colors

  • allFormats (bool = True) – set to True to include additional mime formats, include text/plain and application/x-color

Return type:

QMimeData

Returns:

mime data containing encoded colors

colorRampPreviewIcon(ramp: QgsColorRamp, size: QSize, padding: int = 0) QIcon

Returns an icon preview for a color ramp.

Parameters:
  • ramp (QgsColorRamp) – color ramp

  • size (QSize) – target icon size

  • padding (int = 0) – space between icon edge and color ramp

Return type:

QIcon

colorRampPreviewPixmap(ramp: QgsColorRamp, size: QSize, padding: int = 0, direction: Qt.Orientation = Qt.Horizontal, flipDirection: bool = False, drawTransparentBackground: bool = True) QPixmap

Returns a pixmap preview for a color ramp.

Parameters:
  • ramp (QgsColorRamp) – color ramp

  • size (QSize) – target pixmap size

  • padding (int = 0) – space between icon edge and color ramp

  • direction (Qt.Orientation = Qt.Horizontal) – direction to render pixmap (since QGIS 3.18)

  • flipDirection (bool = False) – set to True to flip the direction of the ramp. For horizontal directions, ramps will be rendered left to right by default. For vertical directions, ramps will be rendered top to bottom by default. Setting this flag to True will reverse these default directions.

  • drawTransparentBackground (bool = True) – set to False to disable the checkerboard effect drawn below transparent colors in the ramp

Return type:

QPixmap

colorRampToVariant(name: str, ramp: QgsColorRamp) Any

Saves a color ramp to a QVariantMap, wrapped in a QVariant. You can use QgsXmlUtils.writeVariant to save it to an XML document.

See also

loadColorRamp()

Parameters:
Return type:

Any

colorToMimeData(color: QColor | Qt.GlobalColor | QGradient) QMimeData

Creates mime data from a color. Sets both the mime data’s color data, and the mime data’s text with the color’s hex code.

Parameters:

color (Union[QColor) – color to encode as mime data

Return type:

QMimeData

colorToName(color: QColor | Qt.GlobalColor | QGradient) str

Returns a friendly display name for a color

Parameters:

color (Union[QColor) – source color

Return type:

str

Returns:

display name for color

condenseFillAndOutline(fill: QgsFillSymbolLayer, outline: QgsLineSymbolLayer) bool

Attempts to condense a fill and outline layer, by moving the outline layer to the fill symbol’s stroke.

This will only be done if the outline can be transformed into a stroke on the fill layer losslessly. If so, fill will be updated in place with the new stroke. Any existing stroke settings in fill will be replaced.

Returns True if the fill and outline were successfully condensed.

New in version 3.20.

Parameters:
Return type:

bool

convertPolygonSymbolizerToPointMarker(element: QDomElement, layerList: Iterable[QgsSymbolLayer]) bool

Converts a polygon symbolizer element to a list of marker symbol layers.

Parameters:
Return type:

bool

createAnchorPointElement(doc: QDomDocument, element: QDomElement, anchor: QPointF | QPoint | float)

Creates a SE 1.1 anchor point element as a child of the specified element

Parameters:
  • doc (QDomDocument) – The document

  • element (QDomElement) – The parent element

  • anchor (Union[QPointF) – An anchor specification, with values between 0 and 1

createDisplacementElement(doc: QDomDocument, element: QDomElement, offset: QPointF | QPoint | float)
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • offset (Union[QPointF) –

createExpressionElement(doc: QDomDocument, element: QDomElement, function: str) bool

Creates a OGC Expression element based on the provided function expression

Parameters:
  • doc (QDomDocument) – The document owning the element

  • element (QDomElement) – The element parent

  • function (str) – The expression to be encoded

Return type:

bool

createFillLayerFromSld(element: QDomElement) QgsSymbolLayer
Parameters:

element (QDomElement) –

Return type:

QgsSymbolLayer

createFunctionElement(doc: QDomDocument, element: QDomElement, function: str) bool
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • function (str) –

Return type:

bool

createGeometryElement(doc: QDomDocument, element: QDomElement, geomFunc: str)
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • geomFunc (str) –

createLineLayerFromSld(element: QDomElement) QgsSymbolLayer
Parameters:

element (QDomElement) –

Return type:

QgsSymbolLayer

createMarkerLayerFromSld(element: QDomElement) QgsSymbolLayer
Parameters:

element (QDomElement) –

Return type:

QgsSymbolLayer

createOnlineResourceElement(doc: QDomDocument, element: QDomElement, path: str, format: str)
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • path (str) –

  • format (str) –

createOpacityElement(doc: QDomDocument, element: QDomElement, alphaFunc: str)
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • alphaFunc (str) –

createRotationElement(doc: QDomDocument, element: QDomElement, rotationFunc: str)
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • rotationFunc (str) –

createSvgParameterElement(doc: QDomDocument, name: str, value: str) QDomElement
Parameters:
  • doc (QDomDocument) –

  • name (str) –

  • value (str) –

Return type:

QDomElement

createSymbolLayerListFromSld(element: QDomElement, geomType: Qgis.GeometryType, layers: Iterable[QgsSymbolLayer]) bool

Creates a symbol layer list from a DOM element.

Parameters:
Return type:

bool

createVendorOptionElement(doc: QDomDocument, name: str, value: str) QDomElement
Parameters:
  • doc (QDomDocument) –

  • name (str) –

  • value (str) –

Return type:

QDomElement

decodeArrowHeadType(value: Any) Tuple[QgsArrowSymbolLayer.HeadType, bool]

Decodes a value representing an arrow head type.

New in version 3.2.

Parameters:

value (Any) –

Return type:

Tuple[QgsArrowSymbolLayer.HeadType, bool]

decodeArrowType(value: Any) Tuple[QgsArrowSymbolLayer.ArrowType, bool]

Decodes a value representing an arrow type.

New in version 3.2.

Parameters:

value (Any) –

Return type:

Tuple[QgsArrowSymbolLayer.ArrowType, bool]

decodeBlendMode(s: str) QPainter.CompositionMode
Parameters:

s (str) –

Return type:

QPainter.CompositionMode

decodeBrushStyle(str: str) Qt.BrushStyle
Parameters:

str (str) –

Return type:

Qt.BrushStyle

decodeColor(str: str) QColor
Parameters:

str (str) –

Return type:

QColor

decodeCoordinateReference(string: str) Tuple[Qgis.SymbolCoordinateReference, bool]

Decodes a string representing a symbol coordinate reference mode.

Parameters:

string (str) – string to decode

Return type:

Tuple[Qgis.SymbolCoordinateReference, bool]

Returns:

  • decoded marker clip mode

  • ok: will be set to True if string was successfully decoded

New in version 3.24.

decodeLineClipMode(string: str) Tuple[Qgis.LineClipMode, bool]

Decodes a string representing a line clip mode.

Parameters:

string (str) – string to decode

Return type:

Tuple[Qgis.LineClipMode, bool]

Returns:

  • decoded line clip mode

  • ok: will be set to True if string was successfully decoded

New in version 3.24.

decodeMapUnitScale(str: str) QgsMapUnitScale
Parameters:

str (str) –

Return type:

QgsMapUnitScale

decodeMarkerClipMode(string: str) Tuple[Qgis.MarkerClipMode, bool]

Decodes a string representing a marker clip mode.

Parameters:

string (str) – string to decode

Return type:

Tuple[Qgis.MarkerClipMode, bool]

Returns:

  • decoded marker clip mode

  • ok: will be set to True if string was successfully decoded

New in version 3.24.

decodePenCapStyle(str: str) Qt.PenCapStyle
Parameters:

str (str) –

Return type:

Qt.PenCapStyle

decodePenJoinStyle(str: str) Qt.PenJoinStyle
Parameters:

str (str) –

Return type:

Qt.PenJoinStyle

decodePenStyle(str: str) Qt.PenStyle
Parameters:

str (str) –

Return type:

Qt.PenStyle

decodePoint(string: str) QPointF

Decodes a QSizeF from a string.

See also

encodePoint()

See also

decodeSize()

Parameters:

string (str) –

Return type:

QPointF

decodeRealVector(s: str) List[float]
Parameters:

s (str) –

Return type:

List[float]

decodeScaleMethod(str: str) Qgis.ScaleMethod

Decodes a symbol scale method from a string.

Parameters:

str (str) –

Return type:

Qgis.ScaleMethod

decodeSize(string: str) QSizeF

Decodes a QSizeF from a string.

See also

encodeSize()

See also

decodePoint()

Parameters:

string (str) –

Return type:

QSizeF

decodeSldAlpha(str: str) int
Parameters:

str (str) –

Return type:

int

decodeSldBrushStyle(str: str) Qt.BrushStyle
Parameters:

str (str) –

Return type:

Qt.BrushStyle

decodeSldFontStyle(str: str) QFont.Style
Parameters:

str (str) –

Return type:

QFont.Style

decodeSldFontWeight(str: str) int
Parameters:

str (str) –

Return type:

int

decodeSldLineCapStyle(str: str) Qt.PenCapStyle
Parameters:

str (str) –

Return type:

Qt.PenCapStyle

decodeSldLineJoinStyle(str: str) Qt.PenJoinStyle
Parameters:

str (str) –

Return type:

Qt.PenJoinStyle

decodeSldRealVector(s: str) List[float]
Parameters:

s (str) –

Return type:

List[float]

decodeSldUom(str: str) Tuple[Qgis.RenderUnit, float]

Decodes a SLD unit of measure string to a render unit.

Parameters:
  • str (str) – string to decode

  • scaleFactor – if specified, will be set to scale factor for unit of measure

Return type:

Tuple[Qgis.RenderUnit, float]

Returns:

matching render unit

See also

encodeSldUom()

displacementFromSldElement(element: QDomElement, offset: QPointF | QPoint | float) bool
Parameters:
  • element (QDomElement) –

  • offset (Union[QPointF) –

Return type:

bool

drawStippledBackground(painter: QPainter, rect: QRect)
Parameters:
  • painter (QPainter) –

  • rect (QRect) –

drawVertexMarker(x: float, y: float, p: QPainter, type: Qgis.VertexMarkerType, markerSize: int)

Draws a vertex symbol at (painter) coordinates x, y. (Useful to assist vertex editing.)

New in version 3.4.5.

Parameters:
encodeBrushStyle(style: Qt.BrushStyle) str
Parameters:

style (Qt.BrushStyle) –

Return type:

str

encodeColor(color: QColor | Qt.GlobalColor | QGradient) str
Parameters:

color (Union[QColor) –

Return type:

str

encodeCoordinateReference(coordinateReference: Qgis.SymbolCoordinateReference) str

Encodes a symbol coordinate reference mode to a string.

Parameters:

coordinateReference (Qgis.SymbolCoordinateReference) – coordinate reference mode

New in version 3.24.

Return type:

str

encodeLineClipMode(mode: Qgis.LineClipMode) str

Encodes a line clip mode to a string.

New in version 3.24.

Parameters:

mode (Qgis.LineClipMode) –

Return type:

str

encodeMapUnitScale(mapUnitScale: QgsMapUnitScale) str
Parameters:

mapUnitScale (QgsMapUnitScale) –

Return type:

str

encodeMarkerClipMode(mode: Qgis.MarkerClipMode) str

Encodes a marker clip mode to a string.

New in version 3.24.

Parameters:

mode (Qgis.MarkerClipMode) –

Return type:

str

encodePenCapStyle(style: Qt.PenCapStyle) str
Parameters:

style (Qt.PenCapStyle) –

Return type:

str

encodePenJoinStyle(style: Qt.PenJoinStyle) str
Parameters:

style (Qt.PenJoinStyle) –

Return type:

str

encodePenStyle(style: Qt.PenStyle) str
Parameters:

style (Qt.PenStyle) –

Return type:

str

encodePoint(point: QPointF | QPoint | float) str

Encodes a QPointF to a string.

See also

decodePoint()

See also

encodeSize()

Parameters:

point (Union[QPointF) –

Return type:

str

encodeRealVector(v: Iterable[float]) str
Parameters:

v (Iterable[float]) –

Return type:

str

encodeScaleMethod(scaleMethod: Qgis.ScaleMethod) str

Encodes a symbol scale method to a string.

Parameters:

scaleMethod (Qgis.ScaleMethod) –

Return type:

str

encodeSize(size: QSizeF) str

Encodes a QSizeF to a string.

See also

decodeSize()

See also

encodePoint()

Parameters:

size (QSizeF) –

Return type:

str

encodeSldAlpha(alpha: int) str
Parameters:

alpha (int) –

Return type:

str

encodeSldBrushStyle(style: Qt.BrushStyle) str
Parameters:

style (Qt.BrushStyle) –

Return type:

str

encodeSldFontStyle(style: QFont.Style) str
Parameters:

style (QFont.Style) –

Return type:

str

encodeSldFontWeight(weight: int) str
Parameters:

weight (int) –

Return type:

str

encodeSldLineCapStyle(style: Qt.PenCapStyle) str
Parameters:

style (Qt.PenCapStyle) –

Return type:

str

encodeSldLineJoinStyle(style: Qt.PenJoinStyle) str
Parameters:

style (Qt.PenJoinStyle) –

Return type:

str

encodeSldRealVector(v: Iterable[float]) str
Parameters:

v (Iterable[float]) –

Return type:

str

encodeSldUom(unit: Qgis.RenderUnit) Tuple[str, float]

Encodes a render unit into an SLD unit of measure string.

Parameters:
  • unit (Qgis.RenderUnit) – unit to encode

  • scaleFactor – if specified, will be set to scale factor for unit of measure

Return type:

Tuple[str, float]

Returns:

encoded string

See also

decodeSldUom()

estimateMaxSymbolBleed(symbol: QgsSymbol, context: QgsRenderContext) float

Returns the maximum estimated bleed for the symbol

Parameters:
Return type:

float

evaluatePropertiesMap(propertiesMap: Dict[str, QgsProperty], context: QgsExpressionContext) Dict[str, str]

Evaluates a map of properties using the given context and returns a variant map with evaluated expressions from the properties.

New in version 3.18.

Parameters:
Return type:

Dict[str, str]

externalGraphicFromSld(element: QDomElement, path: str, mime: str, color: QColor | Qt.GlobalColor | QGradient) Tuple[bool, float]
Parameters:
  • element (QDomElement) –

  • path (str) –

  • mime (str) –

  • color (Union[QColor) –

Return type:

Tuple[bool, float]

externalGraphicToSld(doc: QDomDocument, element: QDomElement, path: str, mime: str, color: QColor | Qt.GlobalColor | QGradient, size: float = -1)
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • path (str) –

  • mime (str) –

  • color (Union[QColor) –

  • size (float = -1) –

externalMarkerFromSld(element: QDomElement, path: str, format: str, color: QColor | Qt.GlobalColor | QGradient) Tuple[bool, int, float]
Parameters:
  • element (QDomElement) –

  • path (str) –

  • format (str) –

  • color (Union[QColor) –

Return type:

Tuple[bool, int, float]

externalMarkerToSld(doc: QDomDocument, element: QDomElement, path: str, format: str, color: QColor | Qt.GlobalColor | QGradient = QColor(), size: float = -1) int
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • path (str) –

  • format (str) –

  • color (Union[QColor) –

  • size (float = -1) –

Return type:

int

fieldOrExpressionFromExpression(expression: QgsExpression) str

Returns a field name if the whole expression is just a name of the field . Returns full expression string if the expression is more complex than just one field. Using just expression->:py:func:~QgsSymbolLayerUtils.expression method may return quoted field name, but that is not wanted for saving (due to backward compatibility) or display in GUI.

Parameters:

expression (QgsExpression) –

Return type:

str

fieldOrExpressionToExpression(fieldOrExpression: str) QgsExpression

Returns a new valid expression instance for given field or expression string. If the input is not a valid expression, it is assumed that it is a field name and gets properly quoted. If the string is empty, returns None. This is useful when accepting input which could be either a non-quoted field name or expression.

Parameters:

fieldOrExpression (str) –

Return type:

QgsExpression

fillFromSld(element: QDomElement, color: QColor | Qt.GlobalColor | QGradient) Tuple[bool, Qt.BrushStyle]
Parameters:
  • element (QDomElement) –

  • color (Union[QColor) –

Return type:

Tuple[bool, Qt.BrushStyle]

fillToSld(doc: QDomDocument, element: QDomElement, brushStyle: Qt.BrushStyle, color: QColor | Qt.GlobalColor | QGradient = QColor())
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • brushStyle (Qt.BrushStyle) –

  • color (Union[QColor) –

functionFromSldElement(element: QDomElement, function: str) bool
Parameters:
  • element (QDomElement) –

  • function (str) –

Return type:

bool

geometryFromSldElement(element: QDomElement, geomFunc: str) bool
Parameters:
  • element (QDomElement) –

  • geomFunc (str) –

Return type:

bool

getSvgParameterList(element: QDomElement) Dict[str, str]
Parameters:

element (QDomElement) –

Return type:

Dict[str, str]

getSvgParametricPath(basePath: str, fillColor: QColor | Qt.GlobalColor | QGradient, strokeColor: QColor | Qt.GlobalColor | QGradient, strokeWidth: float) str

Encodes a reference to a parametric SVG into a path with parameters according to the SVG Parameters spec

Parameters:
  • basePath (str) –

  • fillColor (Union[QColor) –

  • strokeColor (Union[QColor) –

  • strokeWidth (float) –

Return type:

str

getVendorOptionList(element: QDomElement) Dict[str, str]
Parameters:

element (QDomElement) –

Return type:

Dict[str, str]

hasExternalGraphic(element: QDomElement) bool

Checks if element contains an ExternalGraphic element with format “image/svg+xml” @return True if the ExternalGraphic with format “image/svg+xml” is found .

Parameters:

element (QDomElement) –

Return type:

bool

hasExternalGraphicV2(element: QDomElement, format: str = '') bool

Checks if element contains an ExternalGraphic element, if the optional format is specified it will also be checked. @return True if the ExternalGraphic element is found and the optionally specified format matches.

New in version 3.30.

Parameters:
  • element (QDomElement) –

  • format (str = '') –

Return type:

bool

hasWellKnownMark(element: QDomElement) bool
Parameters:

element (QDomElement) –

Return type:

bool

importColorsFromGpl(file: QFile, name: str) Tuple[List[Tuple[QColor, str]], bool]

Imports colors from a gpl GIMP palette file

Parameters:
  • file (QFile) – source gpl file

  • ok – will be True if file was successfully read

  • name (str) – will be set to palette name from gpl file, if present

Return type:

Tuple[List[Tuple[QColor, str]], bool]

Returns:

list of imported colors

isSharpCorner(p1: QPointF | QPoint | float, p2: QPointF | QPoint | float, p3: QPointF | QPoint | float) bool

Returns True if the angle formed by the line p1 - p2 - p3 forms a “sharp” corner.

Sharp corners form an angle which exceeds a 45 degree threshold.

New in version 3.16.

Parameters:
  • p1 (Union[QPointF) –

  • p2 (Union[QPointF) –

  • p3 (Union[QPointF) –

Return type:

bool

labelTextToSld(doc: QDomDocument, element: QDomElement, label: str, font: QFont, color: QColor | Qt.GlobalColor | QGradient = QColor(), size: float = -1)
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • label (str) –

  • font (QFont) –

  • color (Union[QColor) –

  • size (float = -1) –

lineFromSld(element: QDomElement, color: QColor | Qt.GlobalColor | QGradient, customDashPattern: Iterable[float] = []) Tuple[bool, Qt.PenStyle, float, Qt.PenJoinStyle, Qt.PenCapStyle, float]
Parameters:
  • element (QDomElement) –

  • color (Union[QColor) –

  • customDashPattern (Iterable[float] = []) –

Return type:

Tuple[bool, Qt.PenStyle, float, Qt.PenJoinStyle, Qt.PenCapStyle, float]

listSvgFiles() List[str]

Returns a list of all available svg files

Return type:

List[str]

listSvgFilesAt(directory: str) List[str]

Returns a list of svg files at the specified directory

Parameters:

directory (str) –

Return type:

List[str]

loadColorRamp(element: QDomElement) QgsColorRamp

Creates a color ramp from the settings encoded in an XML element

Parameters:

element (QDomElement) – DOM element

Return type:

QgsColorRamp

Returns:

new color ramp. Caller takes responsibility for deleting the returned value.

See also

saveColorRamp()

loadColorRamp(value: Any) -> QgsColorRamp Load a color ramp from a QVariantMap, wrapped in a QVariant. You can use QgsXmlUtils.readVariant to load it from an XML document.

loadSymbol(element: QDomElement, context: QgsReadWriteContext) QgsSymbol

Attempts to load a symbol from a DOM element

Parameters:
  • element (QDomElement) – DOM element representing symbol

  • context (QgsReadWriteContext) – object to transform relative to absolute paths

Return type:

QgsSymbol

Returns:

decoded symbol, if possible

loadSymbolLayer(element: QDomElement, context: QgsReadWriteContext) QgsSymbolLayer

Reads and returns symbol layer from XML. Caller is responsible for deleting the returned object

Parameters:
Return type:

QgsSymbolLayer

loadSymbols(element: QDomElement, context: QgsReadWriteContext) object

Reads a collection of symbols from XML and returns them in a map. Caller is responsible for deleting returned symbols.

Parameters:
Return type:

object

mergeScaleDependencies(mScaleMinDenom: float, mScaleMaxDenom: float, props: Dict[str, Any])

Merges the local scale limits, if any, with the ones already in the map, if any

Parameters:
  • mScaleMinDenom (float) –

  • mScaleMaxDenom (float) –

  • props (Dict[str) –

multiplyImageOpacity(image: QImage, opacity: float)

Multiplies opacity of image pixel values with a (global) transparency value.

Parameters:
  • image (QImage) –

  • opacity (float) –

needEllipseMarker(element: QDomElement) bool
Parameters:

element (QDomElement) –

Return type:

bool

needFontMarker(element: QDomElement) bool
Parameters:

element (QDomElement) –

Return type:

bool

needLinePatternFill(element: QDomElement) bool
Parameters:

element (QDomElement) –

Return type:

bool

needMarkerLine(element: QDomElement) bool
Parameters:

element (QDomElement) –

Return type:

bool

needPointPatternFill(element: QDomElement) bool
Parameters:

element (QDomElement) –

Return type:

bool

needRasterImageFill(element: QDomElement) bool

Checks if element contains a graphic fill with a raster image of type PNG, JPEG or GIF. @return True if element contains a graphic fill with a raster image.

New in version 3.30.

Parameters:

element (QDomElement) –

Return type:

bool

needSvgFill(element: QDomElement) bool
Parameters:

element (QDomElement) –

Return type:

bool

needSvgMarker(element: QDomElement) bool
Parameters:

element (QDomElement) –

Return type:

bool

ogrFeatureStyleBrush(fillColr: QColor | Qt.GlobalColor | QGradient) str

Create ogr feature style string for brush

Parameters:

fillColr (Union[QColor) – fill color

Return type:

str

ogrFeatureStylePen(width: float, mmScaleFactor: float, mapUnitsScaleFactor: float, c: QColor | Qt.GlobalColor | QGradient, joinStyle: Qt.PenJoinStyle = Qt.MiterJoin, capStyle: Qt.PenCapStyle = Qt.FlatCap, offset: float = 0, dashPattern: Iterable[float] = []) str

Create ogr feature style string for pen

Parameters:
  • width (float) –

  • mmScaleFactor (float) –

  • mapUnitsScaleFactor (float) –

  • c (Union[QColor) –

  • joinStyle (Qt.PenJoinStyle = Qt.MiterJoin) –

  • capStyle (Qt.PenCapStyle = Qt.FlatCap) –

  • offset (float = 0) –

  • dashPattern (Iterable[float] = []) –

Return type:

str

onlineResourceFromSldElement(element: QDomElement, path: str, format: str) bool
Parameters:
  • element (QDomElement) –

  • path (str) –

  • format (str) –

Return type:

bool

opacityFromSldElement(element: QDomElement, alphaFunc: str) bool
Parameters:
  • element (QDomElement) –

  • alphaFunc (str) –

Return type:

bool

parametricSvgToSld(doc: QDomDocument, graphicElem: QDomElement, path: str, fillColor: QColor | Qt.GlobalColor | QGradient, size: float, strokeColor: QColor | Qt.GlobalColor | QGradient, strokeWidth: float)

Encodes a reference to a parametric SVG into SLD, as a succession of parametric SVG using URL parameters, a fallback SVG without parameters, and a final fallback as a mark with the right colors and stroke for systems that cannot do SVG at all

Parameters:
  • doc (QDomDocument) –

  • graphicElem (QDomElement) –

  • path (str) –

  • fillColor (Union[QColor) –

  • size (float) –

  • strokeColor (Union[QColor) –

  • strokeWidth (float) –

parseColor(colorStr: str, strictEval: bool = False) QColor

Attempts to parse a string as a color using a variety of common formats, including hex codes, rgb and rgba strings.

Parameters:
  • colorStr (str) – string representing the color

  • strictEval (bool = False) – set to True for stricter color parsing rules

Return type:

QColor

Returns:

parsed color

parseColorList(colorStr: str) List[QColor]

Attempts to parse a string as a list of colors using a variety of common formats, including hex codes, rgb and rgba strings.

Parameters:

colorStr (str) – string representing the color list

Return type:

List[QColor]

Returns:

list of parsed colors

parseColorWithAlpha(colorStr: str, strictEval: bool = False) Tuple[QColor, bool]

Attempts to parse a string as a color using a variety of common formats, including hex codes, rgb and rgba, hsl and hsla strings.

Parameters:
  • colorStr (str) – string representing the color

  • containsAlpha – if colorStr contains an explicit alpha value then containsAlpha will be set to True

  • strictEval (bool = False) – set to True for stricter color parsing rules

Return type:

Tuple[QColor, bool]

Returns:

parsed color

parseProperties(element: QDomElement) Dict[str, Any]

Parses the properties from XML and returns a map

Parameters:

element (QDomElement) –

Return type:

Dict[str, Any]

pointInPolygon(points: QPolygonF, point: QPointF | QPoint | float) bool

Calculate whether a point is within of a QPolygonF

Parameters:
  • points (QPolygonF) –

  • point (Union[QPointF) –

Return type:

bool

pointOnLineWithDistance(startPoint: QPointF | QPoint | float, directionPoint: QPointF | QPoint | float, distance: float) QPointF

Returns a point on the line from startPoint to directionPoint that is a certain distance away from the starting point

Parameters:
  • startPoint (Union[QPointF) –

  • directionPoint (Union[QPointF) –

  • distance (float) –

Return type:

QPointF

polygonCentroid(points: QPolygonF) QPointF

Calculate the centroid point of a QPolygonF

Parameters:

points (QPolygonF) –

Return type:

QPointF

polygonPointOnSurface(points: QPolygonF, rings: Iterable[QPolygonF] = []) QPointF

Calculate a point on the surface of a QPolygonF

Parameters:
  • points (QPolygonF) –

  • rings (Iterable[QPolygonF] = []) –

Return type:

QPointF

polylineLength(polyline: QPolygonF) float

Returns the total length of a polyline.

New in version 3.20.

Parameters:

polyline (QPolygonF) –

Return type:

float

polylineSubstring(polyline: QPolygonF, startOffset: float, endOffset: float) QPolygonF

Returns the substring of a polyline which starts at startOffset from the beginning of the line and ends at endOffset from the start of the line.

If startOffset is less than 0, then the start point will be calculated by subtracting that distance from the end of the line. Similarly, if endOffset is less than zero then the end point will be subtracted from the end of the line.

May return an empty linestring if the substring is zero length.

New in version 3.16.

Parameters:
  • polyline (QPolygonF) –

  • startOffset (float) –

  • endOffset (float) –

Return type:

QPolygonF

premultiplyColor(rgb: QColor | Qt.GlobalColor | QGradient, alpha: int)

Converts a QColor into a premultiplied ARGB QColor value using a specified alpha value

Parameters:
  • rgb (Union[QColor) –

  • alpha (int) –

prettyBreaks(minimum: float, maximum: float, classes: int) List[float]

Computes a sequence of about ‘classes’ equally spaced round values which cover the range of values from ‘minimum’ to ‘maximum’. The values are chosen so that they are 1, 2 or 5 times a power of 10.

Parameters:
  • minimum (float) –

  • maximum (float) –

  • classes (int) –

Return type:

List[float]

rendererFrameRate(renderer: QgsFeatureRenderer) float

Calculates the frame rate (in frames per second) at which the given renderer must be redrawn.

Returns -1 if the renderer is not animated.

New in version 3.26.

Parameters:

renderer (QgsFeatureRenderer) –

Return type:

float

rescaleArrayUom(array: Iterable[float], unit: Qgis.RenderUnit, props: Dict[str, Any]) List[float]

Rescales the given array based on the uomScale found in the props, if any is found, otherwise returns a copy of the original point

Parameters:
  • array (Iterable[float]) –

  • unit (Qgis.RenderUnit) –

  • props (Dict[str) –

Return type:

List[float]

rescalePointUom(point: QPointF | QPoint | float, unit: Qgis.RenderUnit, props: Dict[str, Any]) QPointF

Rescales the given point based on the uomScale found in the props, if any is found, otherwise returns a copy of the original point

Parameters:
  • point (Union[QPointF) –

  • unit (Qgis.RenderUnit) –

  • props (Dict[str) –

Return type:

QPointF

rescaleUom(size: float, unit: Qgis.RenderUnit, props: Dict[str, Any]) float

Rescales the given size based on the uomScale found in the props, if any is found, otherwise returns the value un-modified

Parameters:
Return type:

float

resetSymbolLayerIds(symbol: QgsSymbol)

Regenerate recursively unique id from all symbol symbol layers

New in version 3.30.

resetSymbolLayerIds(symbolLayer: QgsSymbolLayer) Regenerate recursively unique id from symbolLayer and its children

New in version 3.30.

Parameters:

symbol (QgsSymbol) –

restrictedSizeSymbol(s: QgsSymbol, minSize: float, maxSize: float, context: QgsRenderContext) Tuple[QgsSymbol, float, float, bool]

Creates a new symbol with size restricted to min/max size if original size is out of min/max range

Parameters:
  • s (QgsSymbol) – the original symbol

  • minSize (float) – the minimum size in mm

  • maxSize (float) – the maximum size in mm

  • context (QgsRenderContext) – the render context

  • width – expected width, can be changed by the function

  • height – expected height, can be changed by the function

  • ok – if not None, ok is set to false if it’s not possible to compute a restricted symbol (if geometry generators are involved for instance)

Return type:

Tuple[QgsSymbol, float, float, bool]

Returns:

None if size is within minSize/maxSize range or if it’s not possible to compute a restricted size symbol. New symbol if size was out of min/max range. Caller takes ownership

rotationFromSldElement(element: QDomElement, rotationFunc: str) bool
Parameters:
  • element (QDomElement) –

  • rotationFunc (str) –

Return type:

bool

saveColorRamp(name: str, ramp: QgsColorRamp, doc: QDomDocument) QDomElement

Encodes a color ramp’s settings to an XML element

Parameters:
  • name (str) – name of ramp

  • ramp (QgsColorRamp) – color ramp to save

  • doc (QDomDocument) – XML document

Return type:

QDomElement

Returns:

DOM element representing state of color ramp

See also

loadColorRamp()

saveColorsToGpl(file: QFile, paletteName: str, colors: Iterable[Tuple[QColor | Qt.GlobalColor | QGradient, str]]) bool

Exports colors to a gpl GIMP palette file

Parameters:
  • file (QFile) – destination file

  • paletteName (str) – name of palette, which is stored in gpl file

  • colors (Iterable[Tuple[Union[QColor) – colors to export

Return type:

bool

Returns:

True if export was successful

saveProperties(props: Dict[str, Any], doc: QDomDocument, element: QDomElement)

Saves the map of properties to XML

Parameters:
  • props (Dict[str) –

  • doc (QDomDocument) –

  • element (QDomElement) –

saveSymbol(symbolName: str, symbol: QgsSymbol, doc: QDomDocument, context: QgsReadWriteContext) QDomElement

Writes a symbol definition to XML

Parameters:
Return type:

QDomElement

saveSymbols(symbols: object, tagName: str, doc: QDomDocument, context: QgsReadWriteContext) QDomElement

Writes a collection of symbols to XML with specified tagName for the top-level element

Parameters:
  • symbols (object) –

  • tagName (str) –

  • doc (QDomDocument) –

  • context (QgsReadWriteContext) –

Return type:

QDomElement

sizeInPixelsFromSldUom(uom: str, size: float) float

Returns the size scaled in pixels according to the uom attribute.

Parameters:
  • uom (str) – The uom attribute from SLD 1.1 version

  • size (float) – The original size

Return type:

float

Returns:

the size in pixels

sortVariantList(list: Iterable[Any], order: Qt.SortOrder)

Sorts the passed list in requested order

Parameters:
  • list (Iterable[Any]) –

  • order (Qt.SortOrder) –

svgSymbolNameToPath(name: str, pathResolver: QgsPathResolver) str

Determines an SVG symbol’s path from its name. If name is not an absolute path the file is scanned for in the SVG paths specified in settings svg/searchPathsForSVG.

Parameters:
Return type:

str

svgSymbolPathToName(path: str, pathResolver: QgsPathResolver) str

Determines an SVG symbol’s name from its path.

Parameters:
Return type:

str

symbolFromMimeData(data: QMimeData) QgsSymbol

Attempts to parse mime data as a symbol. A new symbol instance will be returned if the data was successfully converted to a symbol.

Parameters:

data (QMimeData) –

Return type:

QgsSymbol

symbolLayerPreviewIcon(layer: QgsSymbolLayer, u: Qgis.RenderUnit, size: QSize, scale: QgsMapUnitScale = QgsMapUnitScale(), parentSymbolType: Qgis.SymbolType = Qgis.SymbolType.Hybrid, mapLayer: QgsMapLayer = None, screen: QgsScreenProperties = QgsScreenProperties()) QIcon

Draws a symbol layer preview to an icon.

Parameters:
  • layer (QgsSymbolLayer) – symbol layer to draw

  • u (Qgis.RenderUnit) – size units

  • size (QSize) – target size of preview icon

  • scale (QgsMapUnitScale = QgsMapUnitScale()) – map unit scale for preview

  • parentSymbolType (Qgis.SymbolType = Qgis.SymbolType.Hybrid) – since QGIS 3.22, can be used to specify the parent symbol type so that geometry generator preview icons are correctly calculated

  • mapLayer (QgsMapLayer = None) – since QGIS 3.28, can be used to specify the associated map layer so that layer related expressions are correctly calculated

  • screen (QgsScreenProperties = QgsScreenProperties()) – since QGIS 3.32, can be used to specify the destination screen properties for the icon. This allows the icon to be generated using the correct DPI and device pixel ratio for the target screen.

Return type:

QIcon

Returns:

icon containing symbol layer preview

symbolLayerPreviewPicture(layer: QgsSymbolLayer, units: Qgis.RenderUnit, size: QSize, scale: QgsMapUnitScale = QgsMapUnitScale(), parentSymbolType: Qgis.SymbolType = Qgis.SymbolType.Hybrid) QPicture

Draws a symbol layer preview to a QPicture

Parameters:
  • layer (QgsSymbolLayer) – symbol layer to draw

  • units (Qgis.RenderUnit) – size units

  • size (QSize) – target size of preview picture

  • scale (QgsMapUnitScale = QgsMapUnitScale()) – map unit scale for preview

  • parentSymbolType (Qgis.SymbolType = Qgis.SymbolType.Hybrid) – since QGIS 3.22, can be used to specify the parent symbol type so that geometry generator preview icons are correctly calculated

Return type:

QPicture

Returns:

QPicture containing symbol layer preview

symbolPreviewIcon(symbol: QgsSymbol, size: QSize, padding: int = 0, shape: QgsLegendPatchShape = None, screen: QgsScreenProperties = QgsScreenProperties()) QIcon

Returns an icon preview for a color ramp.

Parameters:
  • symbol (QgsSymbol) – symbol

  • size (QSize) – target pixmap size

  • padding (int = 0) – space between icon edge and symbol

  • shape (QgsLegendPatchShape = None) – optional legend patch shape to use for rendering the preview icon

  • screen (QgsScreenProperties = QgsScreenProperties()) – can be used to specify the destination screen properties for the icon. This allows the icon to be generated using the correct DPI and device pixel ratio for the target screen (since QGIS 3.32)

Return type:

QIcon

symbolPreviewPixmap(symbol: QgsSymbol, size: QSize, padding: int = 0, customContext: QgsRenderContext = None, selected: bool = False, expressionContext: QgsExpressionContext = None, shape: QgsLegendPatchShape = None, screen: QgsScreenProperties = QgsScreenProperties()) QPixmap

Returns a pixmap preview for a color ramp.

Parameters:
  • symbol (QgsSymbol) – symbol

  • size (QSize) – target pixmap size

  • padding (int = 0) – space between icon edge and symbol

  • customContext (QgsRenderContext = None) – custom rendering context

  • selected (bool = False) – set to True to render the symbol in a selected state (since QGIS 3.10)

  • expressionContext (QgsExpressionContext = None) – optional custom expression context (since QGIS 3.10)

  • shape (QgsLegendPatchShape = None) – optional legend patch shape to use for rendering the preview icon (since QGIS 3.14)

  • screen (QgsScreenProperties = QgsScreenProperties()) – can be used to specify the destination screen properties for the icon. This allows the icon to be generated using the correct DPI and device pixel ratio for the target screen (since QGIS 3.32)

Return type:

QPixmap

symbolProperties(symbol: QgsSymbol) str

Returns a string representing the symbol. Can be used to test for equality between symbols.

Parameters:

symbol (QgsSymbol) –

Return type:

str

symbolToMimeData(symbol: QgsSymbol) QMimeData

Creates new mime data from a symbol. This also sets the mime color data to match the symbol’s color, so that copied symbols can be paste in places where a color is expected.

Parameters:

symbol (QgsSymbol) –

Return type:

QMimeData

tileSize(width: int, height: int, angleRad: float) Tuple[QSize, float]

Calculate the minimum size in pixels of a symbol tile given the symbol width and height and the symbol layer rotation angleRad in radians (counter clockwise). The method makes approximations and can modify angle in order to generate the smallest possible tile.

Parameters:
  • width (int) – marker width, including margins

  • height (int) – marker height, including margins

  • angleRad (float) – symbol layer rotation angle in radians (counter clockwise), it may be approximated by the method to minimize the tile size.

Return type:

Tuple[QSize, float]

Returns:

the size of the tile

New in version 3.30.

toPoint(value: Any) Tuple[QPointF, bool]

Converts a value to a point.

Parameters:

value (Any) – value to convert

Return type:

Tuple[QPointF, bool]

Returns:

  • converted point

  • ok: will be set to True if value was successfully converted

See also

decodePoint()

See also

toSize()

New in version 3.10.

toSize(value: Any) Tuple[QSizeF, bool]

Converts a value to a size.

Parameters:

value (Any) – value to convert

Return type:

Tuple[QSizeF, bool]

Returns:

  • converted size

  • ok: will be set to True if value was successfully converted

See also

decodeSize()

See also

toPoint()

New in version 3.10.

toSymbolLayerPointers(renderer: QgsFeatureRenderer, symbolLayerIds: Iterable[QgsSymbolLayerId]) Set[QgsSymbolLayer]

Converts a set of symbol layer id to a set of pointers to actual symbol layers carried by the feature renderer.

New in version 3.12.

Deprecated since version QGIS: 3.30 because it was related to old QgsSymbolLayerReference system

Parameters:
Return type:

Set[QgsSymbolLayer]

wellKnownMarkerFromSld2(element: QDomElement, name: str, color: QColor | Qt.GlobalColor | QGradient, strokeColor: QColor | Qt.GlobalColor | QGradient) Tuple[bool, Qt.PenStyle, float, float]

Note

available in Python as wellKnownMarkerFromSld2

Parameters:
  • element (QDomElement) –

  • name (str) –

  • color (Union[QColor) –

  • strokeColor (Union[QColor) –

Return type:

Tuple[bool, Qt.PenStyle, float, float]

wellKnownMarkerToSld(doc: QDomDocument, element: QDomElement, name: str, color: QColor | Qt.GlobalColor | QGradient, strokeColor: QColor | Qt.GlobalColor | QGradient, strokeStyle: Qt.PenStyle, strokeWidth: float = -1, size: float = -1)
Parameters:
  • doc (QDomDocument) –

  • element (QDomElement) –

  • name (str) –

  • color (Union[QColor) –

  • strokeColor (Union[QColor) –

  • strokeStyle (Qt.PenStyle) –

  • strokeWidth (float = -1) –

  • size (float = -1) –