Class: QgsSymbolLayerUtils

Contains utility functions for working with symbols and symbol layers.

Enums

VertexMarkerType

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

Methods

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

Static 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

clearSymbolLayerMasks

Remove recursively masks from all symbol symbol layers

clearSymbolMap

collectSymbolLayerClipGeometries

Returns a list of the symbol layer clip geometries to be used for the symbol layer with the specified ID.

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

createExpressionElement

Creates a OGC Expression element based on the provided function expression

createFillLayerFromSld

Creates a new fill layer from a SLD DOM element.

createFunctionElement

Creates an OGC function element

createGeometryElement

Creates an SLD geometry element.

createLineLayerFromSld

Creates a new line layer from a SLD DOM element.

createMarkerLayerFromSld

Creates a new marker layer from a SLD DOM element.

createOnlineResourceElement

createOpacityElement

Creates SLD opacity element.

createRotationElement

Creates SLD rotation element.

createSvgParameterElement

createSymbolLayerListFromSld

Creates a symbol layer list from a DOM element.

createVendorOptionElement

decodeArrowHeadType

Decodes a value representing an arrow head type.

decodeArrowType

Decodes a value representing an arrow type.

decodeBlendMode

decodeBrushStyle

decodeColor

decodeCoordinateReference

Decodes a string representing a symbol coordinate reference mode.

decodeLineClipMode

Decodes a string representing a line clip mode.

decodeMapUnitScale

decodeMarkerClipMode

Decodes a string representing a marker clip mode.

decodePenCapStyle

decodePenJoinStyle

decodePenStyle

decodePoint

Decodes a QSizeF from a string.

decodeRealVector

decodeScaleMethod

Decodes a symbol scale method from a string.

decodeSize

Decodes a QSizeF from a string.

decodeSldAlpha

decodeSldBrushStyle

decodeSldFontStyle

decodeSldFontWeight

decodeSldLineCapStyle

decodeSldLineJoinStyle

decodeSldRealVector

decodeSldUom

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

displacementFromSldElement

drawStippledBackground

drawVertexMarker

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

encodeBrushStyle

encodeColor

encodeCoordinateReference

Encodes a symbol coordinate reference mode to a string.

encodeLineClipMode

Encodes a line clip mode to a string.

encodeMapUnitScale

encodeMarkerClipMode

Encodes a marker clip mode to a string.

encodePenCapStyle

encodePenJoinStyle

encodePenStyle

encodePoint

Encodes a QPointF to a string.

encodeRealVector

encodeScaleMethod

Encodes a symbol scale method to a string.

encodeSize

Encodes a QSizeF to a string.

encodeSldAlpha

encodeSldBrushStyle

encodeSldFontStyle

encodeSldFontWeight

encodeSldLineCapStyle

encodeSldLineJoinStyle

encodeSldRealVector

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

externalGraphicToSld

externalMarkerFromSld

externalMarkerToSld

Exports a marker to an SLD definition.

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

fillToSld

Exports fill details to an SLD element.

functionFromSldElement

geometryFromSldElement

getSvgParameterList

getSvgParametricPath

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

getVendorOptionList

hasExternalGraphic

Checks if element contains an ExternalGraphic element with format "image/svg+xml"

hasExternalGraphicV2

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

hasSldSymbolizer

Returns True if a DOM element contains an SLD Symbolizer element.

hasWellKnownMark

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

Exports label text to SLD

lineFromSld

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

needFontMarker

needLinePatternFill

needMarkerLine

needPointPatternFill

needRasterImageFill

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

needRasterMarker

Checks if element contains an ExternalGraphic element that should translate to a raster marker.

needSvgFill

needSvgMarker

Checks if element contains an ExternalGraphic element that should translate to an SVG marker.

ogrFeatureStyleBrush

Create ogr feature style string for brush

ogrFeatureStylePen

Create ogr feature style string for pen

onlineResourceFromSldElement

opacityFromSldElement

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

penCapStyleToEndCapStyle

Converts a Qt pen cap style to a QGIS end cap style.

penJoinStyleToJoinStyle

Converts a Qt pen joinstyle to a QGIS join style.

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.

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

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.

toQPolygonF

Converts a geometry to a set of QPolygonF objects representing how the geometry should be drawn for a symbol of the given type, as a list of geometry parts and rings.

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

Extracts properties from an SLD marker definition.

wellKnownMarkerToSld

Exports a marker to SLD

class qgis.core.QgsSymbolLayerUtils[source]

Bases: object

class VertexMarkerType(*values)

Bases: IntEnum

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

Added in version 3.22.

  • SemiTransparentCircle: Semi-transparent circle marker

  • Cross: Cross marker

  • NoMarker: No marker

static appendPolyline(target: QPolygonF, line: QPolygonF)[source]

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.

Added in version 3.16.

Parameters:
  • target (QPolygonF)

  • line (QPolygonF)

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

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, Any])

static blurImageInPlace(image: QImage, rect: QRect, radius: int, alphaOnly: bool)[source]

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

Parameters:
  • image (QImage)

  • rect (QRect)

  • radius (int)

  • alphaOnly (bool)

static clearSymbolLayerIds(symbol: QgsSymbol | None)[source]

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

Added in version 3.30.

Parameters:

symbol (Optional[QgsSymbol])

static clearSymbolLayerIds(symbolLayer: QgsSymbolLayer | None)[source]

Remove recursively unique id from symbolLayer and its children and set an empty string instead

Added in version 3.30.

Parameters:

symbolLayer (Optional[QgsSymbolLayer])

static clearSymbolLayerMasks(symbol: QgsSymbol | None)[source]

Remove recursively masks from all symbol symbol layers

Added in version 3.42.

Parameters:

symbol (Optional[QgsSymbol])

static clearSymbolMap(symbols: Any)[source]
Parameters:

symbols (Any)

static collectSymbolLayerClipGeometries(context: QgsRenderContext, symbolLayerId: str | None, bounds: QRectF) List[QgsGeometry]

Returns a list of the symbol layer clip geometries to be used for the symbol layer with the specified ID.

The bounds argument specifies the target bounds (in painter coordinates) for matching geometries. Only mask geometries which intersect bounds will be returned. If bounds is a null QRectF then all clip geometries for the symbol layer will be returned.

Added in version 3.38.

Parameters:
Return type:

List[QgsGeometry]

static colorFromMimeData(data: QMimeData | None)[source]

Attempts to parse mime data as a color

Parameters:

data (Optional[QMimeData]) -> (QColor) – mime data to parse

Returns:

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

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

static colorListFromMimeData(data: QMimeData | None) List[Tuple[QColor, str]][source]

Attempts to parse mime data as a list of named colors

Parameters:

data (Optional[QMimeData]) – mime data to parse

Return type:

List[Tuple[QColor, str]]

Returns:

list of parsed colors

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

Creates mime data from a list of named colors

Parameters:
  • colorList (Iterable[Tuple[Union[QColor, Qt.GlobalColor], Optional[str]]]) – list of named colors

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

Return type:

Optional[QMimeData]

Returns:

mime data containing encoded colors

static colorRampPreviewIcon(ramp: QgsColorRamp | None, size: QSize, padding: int = 0) QIcon[source]

Returns an icon preview for a color ramp.

Parameters:
  • ramp (Optional[QgsColorRamp]) – color ramp

  • size (QSize) – target icon size

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

Return type:

QIcon

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

Returns a pixmap preview for a color ramp.

Parameters:
  • ramp (Optional[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

static colorRampToVariant(name: str | None, ramp: QgsColorRamp | None) Any[source]

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

static colorToMimeData(color: QColor | Qt.GlobalColor) QMimeData | None[source]

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, Qt.GlobalColor]) – color to encode as mime data

Return type:

Optional[QMimeData]

static colorToName(color: QColor | Qt.GlobalColor) str[source]

Returns a friendly display name for a color

Parameters:

color (Union[QColor, Qt.GlobalColor]) – source color

Return type:

str

Returns:

display name for color

static condenseFillAndOutline(fill: QgsFillSymbolLayer | None, outline: QgsLineSymbolLayer | None) bool[source]

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.

Added in version 3.20.

Parameters:
Return type:

bool

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

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

Parameters:
Return type:

bool

static createAnchorPointElement(doc: QDomDocument, element: QDomElement, anchor: QPointF | QPoint)[source]

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, QPoint]) – An anchor specification, with values between 0 and 1

static createDisplacementElement(doc: QDomDocument, element: QDomElement, offset: QPointF | QPoint)[source]
Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • offset (Union[QPointF, QPoint])

static createExpressionElement(doc: QDomDocument, element: QDomElement, function: str | None) bool[source]

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 (Optional[str]) – The expression to be encoded

Deprecated since version 3.44: Use the version with QgsSldExportContext instead.

Return type:

bool

static createExpressionElement(doc: QDomDocument, element: QDomElement, function: str | None, context: QgsSldExportContext) bool[source]

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 (Optional[str]) – The expression to be encoded

  • context (QgsSldExportContext) – export context

Added in version 3.44.

Return type:

bool

static createFillLayerFromSld(element: QDomElement) QgsSymbolLayer | None

Creates a new fill layer from a SLD DOM element.

Parameters:

element (QDomElement)

Return type:

Optional[QgsSymbolLayer]

static createFunctionElement(doc: QDomDocument, element: QDomElement, function: str | None) bool[source]

Creates an OGC function element

Deprecated since version 3.44: Use the version with QgsSldExportContext instead.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • function (Optional[str])

Return type:

bool

static createFunctionElement(doc: QDomDocument, element: QDomElement, function: str | None, context: QgsSldExportContext) bool[source]

Creates an OGC function element

Added in version 3.44.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • function (Optional[str])

  • context (QgsSldExportContext)

Return type:

bool

static createGeometryElement(doc: QDomDocument, element: QDomElement, geomFunc: str | None)[source]

Creates an SLD geometry element.

Deprecated since version 3.44: Use the version with QgsSldExportContext instead.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • geomFunc (Optional[str])

static createGeometryElement(doc: QDomDocument, element: QDomElement, geomFunc: str | None, context: QgsSldExportContext)[source]

Creates an SLD geometry element.

Added in version 3.44.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • geomFunc (Optional[str])

  • context (QgsSldExportContext)

static createLineLayerFromSld(element: QDomElement) QgsSymbolLayer | None

Creates a new line layer from a SLD DOM element.

Parameters:

element (QDomElement)

Return type:

Optional[QgsSymbolLayer]

static createMarkerLayerFromSld(element: QDomElement) QgsSymbolLayer | None

Creates a new marker layer from a SLD DOM element.

Parameters:

element (QDomElement)

Return type:

Optional[QgsSymbolLayer]

static createOnlineResourceElement(doc: QDomDocument, element: QDomElement, path: str | None, format: str | None)[source]
Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • path (Optional[str])

  • format (Optional[str])

static createOpacityElement(doc: QDomDocument, element: QDomElement, alphaFunc: str | None)[source]

Creates SLD opacity element.

Deprecated since version 3.44: Use the version with QgsSldExportContext instead.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • alphaFunc (Optional[str])

static createOpacityElement(doc: QDomDocument, element: QDomElement, alphaFunc: str | None, context: QgsSldExportContext)[source]

Creates SLD opacity element.

Added in version 3.44.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • alphaFunc (Optional[str])

  • context (QgsSldExportContext)

static createRotationElement(doc: QDomDocument, element: QDomElement, rotationFunc: str | None)[source]

Creates SLD rotation element.

Deprecated since version 3.44: Use the version with QgsSldExportContext instead.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • rotationFunc (Optional[str])

static createRotationElement(doc: QDomDocument, element: QDomElement, rotationFunc: str | None, context: QgsSldExportContext)[source]

Creates SLD rotation element.

Added in version 3.44.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • rotationFunc (Optional[str])

  • context (QgsSldExportContext)

static createSvgParameterElement(doc: QDomDocument, name: str | None, value: str | None) QDomElement[source]
Parameters:
  • doc (QDomDocument)

  • name (Optional[str])

  • value (Optional[str])

Return type:

QDomElement

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

Creates a symbol layer list from a DOM element.

Parameters:
Return type:

bool

static createVendorOptionElement(doc: QDomDocument, name: str | None, value: str | None) QDomElement[source]
Parameters:
  • doc (QDomDocument)

  • name (Optional[str])

  • value (Optional[str])

Return type:

QDomElement

static decodeArrowHeadType(value: Any)[source]

Decodes a value representing an arrow head type.

Added in version 3.2.

Parameters:

value (Any) -> (QgsArrowSymbolLayer.HeadType)

static decodeArrowType(value: Any)[source]

Decodes a value representing an arrow type.

Added in version 3.2.

Parameters:

value (Any) -> (QgsArrowSymbolLayer.ArrowType)

static decodeBlendMode(s: str | None) QPainter.CompositionMode[source]
Parameters:

s (Optional[str])

Return type:

QPainter.CompositionMode

static decodeBrushStyle(str: str | None) Qt.BrushStyle[source]
Parameters:

str (Optional[str])

Return type:

Qt.BrushStyle

static decodeColor(str: str | None) QColor[source]
Parameters:

str (Optional[str])

Return type:

QColor

static decodeCoordinateReference(string: str | None)[source]

Decodes a string representing a symbol coordinate reference mode.

Parameters:

string (Optional[str]) -> (Qgis.SymbolCoordinateReference) – string to decode

Returns:

  • decoded marker clip mode

  • ok: True if string was successfully decoded

Added in version 3.24.

static decodeLineClipMode(string: str | None)[source]

Decodes a string representing a line clip mode.

Parameters:

string (Optional[str]) -> (Qgis.LineClipMode) – string to decode

Returns:

  • decoded line clip mode

  • ok: True if string was successfully decoded

Added in version 3.24.

static decodeMapUnitScale(str: str | None) QgsMapUnitScale[source]
Parameters:

str (Optional[str])

Return type:

QgsMapUnitScale

static decodeMarkerClipMode(string: str | None)[source]

Decodes a string representing a marker clip mode.

Parameters:

string (Optional[str]) -> (Qgis.MarkerClipMode) – string to decode

Returns:

  • decoded marker clip mode

  • ok: True if string was successfully decoded

Added in version 3.24.

static decodePenCapStyle(str: str | None) Qt.PenCapStyle[source]
Parameters:

str (Optional[str])

Return type:

Qt.PenCapStyle

static decodePenJoinStyle(str: str | None) Qt.PenJoinStyle[source]
Parameters:

str (Optional[str])

Return type:

Qt.PenJoinStyle

static decodePenStyle(str: str | None) Qt.PenStyle[source]
Parameters:

str (Optional[str])

Return type:

Qt.PenStyle

static decodePoint(string: str | None) QPointF[source]

Decodes a QSizeF from a string.

See also

encodePoint()

See also

decodeSize()

Parameters:

string (Optional[str])

Return type:

QPointF

static decodeRealVector(s: str | None) List[float]
Parameters:

s (Optional[str])

Return type:

List[float]

static decodeScaleMethod(str: str | None) Qgis.ScaleMethod[source]

Decodes a symbol scale method from a string.

Parameters:

str (Optional[str])

Return type:

Qgis.ScaleMethod

static decodeSize(string: str | None) QSizeF[source]

Decodes a QSizeF from a string.

See also

encodeSize()

See also

decodePoint()

Parameters:

string (Optional[str])

Return type:

QSizeF

static decodeSldAlpha(str: str | None) int[source]
Parameters:

str (Optional[str])

Return type:

int

static decodeSldBrushStyle(str: str | None) Qt.BrushStyle[source]
Parameters:

str (Optional[str])

Return type:

Qt.BrushStyle

static decodeSldFontStyle(str: str | None) QFont.Style[source]
Parameters:

str (Optional[str])

Return type:

QFont.Style

static decodeSldFontWeight(str: str | None) int[source]
Parameters:

str (Optional[str])

Return type:

int

static decodeSldLineCapStyle(str: str | None) Qt.PenCapStyle[source]
Parameters:

str (Optional[str])

Return type:

Qt.PenCapStyle

static decodeSldLineJoinStyle(str: str | None) Qt.PenJoinStyle[source]
Parameters:

str (Optional[str])

Return type:

Qt.PenJoinStyle

static decodeSldRealVector(s: str | None) List[float]
Parameters:

s (Optional[str])

Return type:

List[float]

static decodeSldUom(str: str | None)[source]

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

Parameters:
  • str (Optional[str]) -> (Qgis.RenderUnit) – string to decode

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

Returns:

matching render unit

See also

encodeSldUom()

static displacementFromSldElement(element: QDomElement, offset: QPointF | QPoint) bool[source]
Parameters:
  • element (QDomElement)

  • offset (Union[QPointF, QPoint])

Return type:

bool

static drawStippledBackground(painter: QPainter | None, rect: QRect)[source]
Parameters:
  • painter (Optional[QPainter])

  • rect (QRect)

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

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

Added in version 3.4.5.

Parameters:
static encodeBrushStyle(style: Qt.BrushStyle) str[source]
Parameters:

style (Qt.BrushStyle)

Return type:

str

static encodeColor(color: QColor | Qt.GlobalColor) str[source]
Parameters:

color (Union[QColor, Qt.GlobalColor])

Return type:

str

static encodeCoordinateReference(coordinateReference: Qgis.SymbolCoordinateReference) str[source]

Encodes a symbol coordinate reference mode to a string.

Parameters:

coordinateReference (Qgis.SymbolCoordinateReference) – coordinate reference mode

Added in version 3.24.

Return type:

str

static encodeLineClipMode(mode: Qgis.LineClipMode) str[source]

Encodes a line clip mode to a string.

Added in version 3.24.

Parameters:

mode (Qgis.LineClipMode)

Return type:

str

static encodeMapUnitScale(mapUnitScale: QgsMapUnitScale) str[source]
Parameters:

mapUnitScale (QgsMapUnitScale)

Return type:

str

static encodeMarkerClipMode(mode: Qgis.MarkerClipMode) str[source]

Encodes a marker clip mode to a string.

Added in version 3.24.

Parameters:

mode (Qgis.MarkerClipMode)

Return type:

str

static encodePenCapStyle(style: Qt.PenCapStyle) str[source]
Parameters:

style (Qt.PenCapStyle)

Return type:

str

static encodePenJoinStyle(style: Qt.PenJoinStyle) str[source]
Parameters:

style (Qt.PenJoinStyle)

Return type:

str

static encodePenStyle(style: Qt.PenStyle) str[source]
Parameters:

style (Qt.PenStyle)

Return type:

str

static encodePoint(point: QPointF | QPoint) str[source]

Encodes a QPointF to a string.

See also

decodePoint()

See also

encodeSize()

Parameters:

point (Union[QPointF, QPoint])

Return type:

str

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

v (Iterable[float])

Return type:

str

static encodeScaleMethod(scaleMethod: Qgis.ScaleMethod) str[source]

Encodes a symbol scale method to a string.

Parameters:

scaleMethod (Qgis.ScaleMethod)

Return type:

str

static encodeSize(size: QSizeF) str[source]

Encodes a QSizeF to a string.

See also

decodeSize()

See also

encodePoint()

Parameters:

size (QSizeF)

Return type:

str

static encodeSldAlpha(alpha: int) str[source]
Parameters:

alpha (int)

Return type:

str

static encodeSldBrushStyle(style: Qt.BrushStyle) str[source]
Parameters:

style (Qt.BrushStyle)

Return type:

str

static encodeSldFontStyle(style: QFont.Style) str[source]
Parameters:

style (QFont.Style)

Return type:

str

static encodeSldFontWeight(weight: int) str[source]
Parameters:

weight (int)

Return type:

str

static encodeSldLineCapStyle(style: Qt.PenCapStyle) str[source]
Parameters:

style (Qt.PenCapStyle)

Return type:

str

static encodeSldLineJoinStyle(style: Qt.PenJoinStyle) str[source]
Parameters:

style (Qt.PenJoinStyle)

Return type:

str

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

v (Iterable[float])

Return type:

str

static encodeSldUom(unit: Qgis.RenderUnit)[source]

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

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

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

Returns:

encoded string

See also

decodeSldUom()

static estimateMaxSymbolBleed(symbol: QgsSymbol | None, context: QgsRenderContext) float[source]

Returns the maximum estimated bleed for the symbol

Parameters:
Return type:

float

static evaluatePropertiesMap(propertiesMap: Dict[str | None, QgsProperty], context: QgsExpressionContext) Dict[str, str][source]

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

Added in version 3.18.

Parameters:
Return type:

Dict[str, str]

static externalGraphicFromSld(element: QDomElement, path: str | None, mime: str | None, color: QColor | Qt.GlobalColor)[source]
Parameters:
  • element (QDomElement)

  • path (Optional[str])

  • mime (Optional[str])

  • color (Union[QColor, Qt.GlobalColor]) -> (bool)

static externalGraphicToSld(doc: QDomDocument, element: QDomElement, path: str | None, mime: str | None, color: QColor | Qt.GlobalColor, size: float = -1)[source]
Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • path (Optional[str])

  • mime (Optional[str])

  • color (Union[QColor, Qt.GlobalColor])

  • size (float = -1)

static externalMarkerFromSld(element: QDomElement, path: str | None, format: str | None, color: QColor | Qt.GlobalColor)[source]
Parameters:
  • element (QDomElement)

  • path (Optional[str])

  • format (Optional[str])

  • color (Union[QColor, Qt.GlobalColor]) -> (bool)

static externalMarkerToSld(doc: QDomDocument, element: QDomElement, path: str | None, format: str | None, color: QColor | Qt.GlobalColor = QColor(), size: float = -1) int | None[source]

Exports a marker to an SLD definition.

Deprecated since version 3.44: Use the version with QgsSldExportContext instead.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • path (Optional[str])

  • format (Optional[str])

  • color (Union[QColor, Qt.GlobalColor] = QColor())

  • size (float = -1)

Return type:

Optional[int]

static externalMarkerToSld(doc: QDomDocument, element: QDomElement, path: str | None, format: str | None, context: QgsSldExportContext, color: QColor | Qt.GlobalColor = QColor(), size: float = -1) int | None[source]

Exports a marker to an SLD definition.

Added in version 3.44.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • path (Optional[str])

  • format (Optional[str])

  • context (QgsSldExportContext)

  • color (Union[QColor, Qt.GlobalColor] = QColor())

  • size (float = -1)

Return type:

Optional[int]

static fieldOrExpressionFromExpression(expression: QgsExpression | None) str[source]

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 (Optional[QgsExpression])

Return type:

str

static fieldOrExpressionToExpression(fieldOrExpression: str | None) QgsExpression | None

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 (Optional[str])

Return type:

Optional[QgsExpression]

static fillFromSld(element: QDomElement, color: QColor | Qt.GlobalColor)[source]
Parameters:
  • element (QDomElement)

  • color (Union[QColor, Qt.GlobalColor]) -> (bool)

static fillToSld(doc: QDomDocument, element: QDomElement, brushStyle: Qt.BrushStyle, color: QColor | Qt.GlobalColor = QColor())[source]

Exports fill details to an SLD element.

Deprecated since version 3.44: Use the version with QgsSldExportContext instead.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • brushStyle (Qt.BrushStyle)

  • color (Union[QColor, Qt.GlobalColor] = QColor())

static fillToSld(doc: QDomDocument, element: QDomElement, context: QgsSldExportContext, brushStyle: Qt.BrushStyle, color: QColor | Qt.GlobalColor = QColor())[source]

Exports fill details to an SLD element.

Added in version 3.44.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • context (QgsSldExportContext)

  • brushStyle (Qt.BrushStyle)

  • color (Union[QColor, Qt.GlobalColor] = QColor())

static functionFromSldElement(element: QDomElement, function: str | None) bool[source]
Parameters:
  • element (QDomElement)

  • function (Optional[str])

Return type:

bool

static geometryFromSldElement(element: QDomElement, geomFunc: str | None) bool[source]
Parameters:
  • element (QDomElement)

  • geomFunc (Optional[str])

Return type:

bool

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

element (QDomElement)

Return type:

Dict[str, str]

static getSvgParametricPath(basePath: str | None, fillColor: QColor | Qt.GlobalColor, strokeColor: QColor | Qt.GlobalColor, strokeWidth: float) str[source]

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

Parameters:
  • basePath (Optional[str])

  • fillColor (Union[QColor, Qt.GlobalColor])

  • strokeColor (Union[QColor, Qt.GlobalColor])

  • strokeWidth (float)

Return type:

str

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

element (QDomElement)

Return type:

Dict[str, str]

static hasExternalGraphic(element: QDomElement) bool[source]

Checks if element contains an ExternalGraphic element with format “image/svg+xml”

Return type:

bool

Returns:

True if the ExternalGraphic with format “image/svg+xml” is found .

Parameters:

element (QDomElement)

static hasExternalGraphicV2(element: QDomElement, format: str | None = '') bool[source]

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

Return type:

bool

Returns:

True if the ExternalGraphic element is found and the optionally specified format matches.

Added in version 3.30.

Parameters:
  • element (QDomElement)

  • format (Optional[str] = '')

static hasSldSymbolizer(element: QDomElement) bool[source]

Returns True if a DOM element contains an SLD Symbolizer element.

Added in version 3.42.

Parameters:

element (QDomElement)

Return type:

bool

static hasWellKnownMark(element: QDomElement) bool[source]
Parameters:

element (QDomElement)

Return type:

bool

static importColorsFromGpl(file: QFile, name: str | None)[source]

Imports colors from a gpl GIMP palette file

Parameters:
  • file (QFile) – source gpl file

  • ok – will be True if file was successfully read

  • name (Optional[str]) -> (List[Tuple[QColor, str]]) – will be set to palette name from gpl file, if present

Returns:

list of imported colors

static isSharpCorner(p1: QPointF | QPoint, p2: QPointF | QPoint, p3: QPointF | QPoint) bool[source]

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.

Added in version 3.16.

Parameters:
  • p1 (Union[QPointF, QPoint])

  • p2 (Union[QPointF, QPoint])

  • p3 (Union[QPointF, QPoint])

Return type:

bool

static labelTextToSld(doc: QDomDocument, element: QDomElement, label: str | None, font: QFont, color: QColor | Qt.GlobalColor = QColor(), size: float = -1)[source]

Exports label text to SLD

Deprecated since version 3.44: Use the version with QgsSldExportContext instead.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • label (Optional[str])

  • font (QFont)

  • color (Union[QColor, Qt.GlobalColor] = QColor())

  • size (float = -1)

static labelTextToSld(doc: QDomDocument, element: QDomElement, label: str | None, font: QFont, context: QgsSldExportContext, color: QColor | Qt.GlobalColor = QColor(), size: float = -1)[source]

Exports label text to SLD

Added in version 3.44.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • label (Optional[str])

  • font (QFont)

  • context (QgsSldExportContext)

  • color (Union[QColor, Qt.GlobalColor] = QColor())

  • size (float = -1)

static lineFromSld(element: QDomElement, color: QColor | Qt.GlobalColor, customDashPattern: Iterable[float] | None = [])[source]
Parameters:
  • element (QDomElement)

  • color (Union[QColor, Qt.GlobalColor])

  • customDashPattern (Optional[Iterable[float]] = []) -> (bool)

static listSvgFiles() List[str][source]

Returns a list of all available svg files

Return type:

List[str]

static listSvgFilesAt(directory: str | None) List[str][source]

Returns a list of svg files at the specified directory

Parameters:

directory (Optional[str])

Return type:

List[str]

static loadColorRamp(element: QDomElement) QgsColorRamp | None

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

Parameters:

element (QDomElement) – DOM element

Return type:

Optional[QgsColorRamp]

Returns:

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

See also

saveColorRamp()

static loadColorRamp(value: Any) QgsColorRamp | None

Load a color ramp from a QVariantMap, wrapped in a QVariant. You can use QgsXmlUtils.readVariant to load it from an XML document.

Parameters:

value (Any)

Return type:

Optional[QgsColorRamp]

static loadSymbol(element: QDomElement, context: QgsReadWriteContext) QgsSymbol | None

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:

Optional[QgsSymbol]

Returns:

decoded symbol, if possible

static loadSymbolLayer(element: QDomElement, context: QgsReadWriteContext) QgsSymbolLayer | None

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

Parameters:
Return type:

Optional[QgsSymbolLayer]

static loadSymbols(element: QDomElement, context: QgsReadWriteContext) Any[source]

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

Parameters:
Return type:

Any

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

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

Parameters:
  • mScaleMinDenom (float)

  • mScaleMaxDenom (float)

  • props (Dict[str, Any])

static multiplyImageOpacity(image: QImage | None, opacity: float)[source]

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

Parameters:
  • image (Optional[QImage])

  • opacity (float)

static needEllipseMarker(element: QDomElement) bool[source]
Parameters:

element (QDomElement)

Return type:

bool

static needFontMarker(element: QDomElement) bool[source]
Parameters:

element (QDomElement)

Return type:

bool

static needLinePatternFill(element: QDomElement) bool[source]
Parameters:

element (QDomElement)

Return type:

bool

static needMarkerLine(element: QDomElement) bool[source]
Parameters:

element (QDomElement)

Return type:

bool

static needPointPatternFill(element: QDomElement) bool[source]
Parameters:

element (QDomElement)

Return type:

bool

static needRasterImageFill(element: QDomElement) bool[source]

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

Return type:

bool

Returns:

True if element contains a graphic fill with a raster image.

Added in version 3.30.

Parameters:

element (QDomElement)

static needRasterMarker(element: QDomElement) bool[source]

Checks if element contains an ExternalGraphic element that should translate to a raster marker.

This is the case for any type of ExternalGraphic that is not an SVG.

Return type:

bool

Returns:

True if the ExternalGraphic element is found and is not of type SVG.

Added in version 3.44.

Parameters:

element (QDomElement)

static needSvgFill(element: QDomElement) bool[source]
Parameters:

element (QDomElement)

Return type:

bool

static needSvgMarker(element: QDomElement) bool[source]

Checks if element contains an ExternalGraphic element that should translate to an SVG marker.

Return type:

bool

Returns:

True if the ExternalGraphic element is found and is of type SVG.

Parameters:

element (QDomElement)

static ogrFeatureStyleBrush(fillColr: QColor | Qt.GlobalColor) str[source]

Create ogr feature style string for brush

Parameters:

fillColr (Union[QColor, Qt.GlobalColor]) – fill color

Return type:

str

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

Create ogr feature style string for pen

Parameters:
  • width (float)

  • mmScaleFactor (float)

  • mapUnitsScaleFactor (float)

  • c (Union[QColor, Qt.GlobalColor])

  • joinStyle (Qt.PenJoinStyle = Qt.MiterJoin)

  • capStyle (Qt.PenCapStyle = Qt.FlatCap)

  • offset (float = 0)

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

Return type:

str

static onlineResourceFromSldElement(element: QDomElement, path: str | None, format: str | None) bool[source]
Parameters:
  • element (QDomElement)

  • path (Optional[str])

  • format (Optional[str])

Return type:

bool

static opacityFromSldElement(element: QDomElement, alphaFunc: str | None) bool[source]
Parameters:
  • element (QDomElement)

  • alphaFunc (Optional[str])

Return type:

bool

static parametricSvgToSld(doc: QDomDocument, graphicElem: QDomElement, path: str | None, fillColor: QColor | Qt.GlobalColor, size: float, strokeColor: QColor | Qt.GlobalColor, strokeWidth: float)[source]

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

Deprecated since version 3.44: Use the version with QgsSldExportContext instead.

Parameters:
  • doc (QDomDocument)

  • graphicElem (QDomElement)

  • path (Optional[str])

  • fillColor (Union[QColor, Qt.GlobalColor])

  • size (float)

  • strokeColor (Union[QColor, Qt.GlobalColor])

  • strokeWidth (float)

static parametricSvgToSld(doc: QDomDocument, graphicElem: QDomElement, path: str | None, fillColor: QColor | Qt.GlobalColor, size: float, strokeColor: QColor | Qt.GlobalColor, strokeWidth: float, context: QgsSldExportContext)[source]

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

Added in version 3.44.

Parameters:
  • doc (QDomDocument)

  • graphicElem (QDomElement)

  • path (Optional[str])

  • fillColor (Union[QColor, Qt.GlobalColor])

  • size (float)

  • strokeColor (Union[QColor, Qt.GlobalColor])

  • strokeWidth (float)

  • context (QgsSldExportContext)

static parseColor(colorStr: str | None, strictEval: bool = False) QColor[source]

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

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

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

Return type:

QColor

Returns:

parsed color

static parseColorList(colorStr: str | None) 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 (Optional[str]) – string representing the color list

Return type:

List[QColor]

Returns:

list of parsed colors

static parseColorWithAlpha(colorStr: str | None, strictEval: bool = False)[source]

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 (Optional[str]) – string representing the color

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

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

Returns:

parsed color

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

Parses the properties from XML and returns a map

Parameters:

element (QDomElement)

Return type:

Dict[str, Any]

static penCapStyleToEndCapStyle(style: Qt.PenCapStyle) Qgis.EndCapStyle[source]

Converts a Qt pen cap style to a QGIS end cap style.

Added in version 3.42.

Parameters:

style (Qt.PenCapStyle)

Return type:

Qgis.EndCapStyle

static penJoinStyleToJoinStyle(style: Qt.PenJoinStyle) Qgis.JoinStyle[source]

Converts a Qt pen joinstyle to a QGIS join style.

Added in version 3.42.

Parameters:

style (Qt.PenJoinStyle)

Return type:

Qgis.JoinStyle

static pointInPolygon(points: QPolygonF, point: QPointF | QPoint) bool[source]

Calculate whether a point is within of a QPolygonF

Parameters:
  • points (QPolygonF)

  • point (Union[QPointF, QPoint])

Return type:

bool

static pointOnLineWithDistance(startPoint: QPointF | QPoint, directionPoint: QPointF | QPoint, distance: float) QPointF[source]

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

Parameters:
  • startPoint (Union[QPointF, QPoint])

  • directionPoint (Union[QPointF, QPoint])

  • distance (float)

Return type:

QPointF

static polygonCentroid(points: QPolygonF) QPointF[source]

Calculate the centroid point of a QPolygonF

Parameters:

points (QPolygonF)

Return type:

QPointF

static polygonPointOnSurface(points: QPolygonF, rings: Iterable[QPolygonF] | None = []) QPointF[source]

Calculate a point on the surface of a QPolygonF

Parameters:
  • points (QPolygonF)

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

Return type:

QPointF

static polylineLength(polyline: QPolygonF) float[source]

Returns the total length of a polyline.

Added in version 3.20.

Parameters:

polyline (QPolygonF)

Return type:

float

static polylineSubstring(polyline: QPolygonF, startOffset: float, endOffset: float) QPolygonF[source]

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.

Added in version 3.16.

Parameters:
  • polyline (QPolygonF)

  • startOffset (float)

  • endOffset (float)

Return type:

QPolygonF

static premultiplyColor(rgb: QColor | Qt.GlobalColor, alpha: int)[source]

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

Parameters:
  • rgb (Union[QColor, Qt.GlobalColor])

  • alpha (int)

static 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]

static rendererFrameRate(renderer: QgsFeatureRenderer | None) float[source]

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

Returns -1 if the renderer is not animated.

Added in version 3.26.

Parameters:

renderer (Optional[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:
Return type:

List[float]

rescalePointUom(point: QPointF | QPoint, 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, QPoint])

  • unit (Qgis.RenderUnit)

  • props (Dict[str, Any])

Return type:

QPointF

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

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

static resetSymbolLayerIds(symbol: QgsSymbol | None)[source]

Regenerate recursively unique id from all symbol symbol layers

Added in version 3.30.

Parameters:

symbol (Optional[QgsSymbol])

static resetSymbolLayerIds(symbolLayer: QgsSymbolLayer | None)[source]

Regenerate recursively unique id from symbolLayer and its children

Added in version 3.30.

Parameters:

symbolLayer (Optional[QgsSymbolLayer])

static restrictedSizeSymbol(s: QgsSymbol | None, minSize: float, maxSize: float, context: QgsRenderContext | None)[source]

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

Parameters:
  • s (Optional[QgsSymbol]) – the original symbol

  • minSize (float) – the minimum size in mm

  • maxSize (float) – the maximum size in mm

  • context (Optional[QgsRenderContext]) -> (Optional[QgsSymbol]) – 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)

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

static rotationFromSldElement(element: QDomElement, rotationFunc: str | None) bool[source]
Parameters:
  • element (QDomElement)

  • rotationFunc (Optional[str])

Return type:

bool

static saveColorRamp(name: str | None, ramp: QgsColorRamp | None, doc: QDomDocument) QDomElement[source]

Encodes a color ramp’s settings to an XML element

Parameters:
  • name (Optional[str]) – name of ramp

  • ramp (Optional[QgsColorRamp]) – color ramp to save

  • doc (QDomDocument) – XML document

Return type:

QDomElement

Returns:

DOM element representing state of color ramp

See also

loadColorRamp()

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

Exports colors to a gpl GIMP palette file

Parameters:
  • file (QFile) – destination file

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

  • colors (Iterable[Tuple[Union[QColor, Qt.GlobalColor], Optional[str]]]) – colors to export

Return type:

bool

Returns:

True if export was successful

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

Saves the map of properties to XML

Parameters:
  • props (Dict[str, Any])

  • doc (QDomDocument)

  • element (QDomElement)

static saveSymbol(symbolName: str | None, symbol: QgsSymbol | None, doc: QDomDocument, context: QgsReadWriteContext) QDomElement[source]

Writes a symbol definition to XML

Parameters:
Return type:

QDomElement

static saveSymbols(symbols: Any, tagName: str | None, doc: QDomDocument, context: QgsReadWriteContext) QDomElement[source]

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

Parameters:
Return type:

QDomElement

static sizeInPixelsFromSldUom(uom: str | None, size: float) float[source]

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

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

  • size (float) – The original size

Return type:

float

Returns:

the size in pixels

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

Sorts the passed list in requested order

Parameters:
  • list (Iterable[Any])

  • order (Qt.SortOrder)

static svgSymbolNameToPath(name: str | None, pathResolver: QgsPathResolver) str[source]

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

static svgSymbolPathToName(path: str | None, pathResolver: QgsPathResolver) str[source]

Determines an SVG symbol’s name from its path.

Parameters:
Return type:

str

static symbolFromMimeData(data: QMimeData | None) QgsSymbol | None

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 (Optional[QMimeData])

Return type:

Optional[QgsSymbol]

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

Draws a symbol layer preview to an icon.

Parameters:
  • layer (Optional[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 (Optional[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

static symbolLayerPreviewPicture(layer: QgsSymbolLayer | None, units: Qgis.RenderUnit, size: QSize, scale: QgsMapUnitScale = QgsMapUnitScale(), parentSymbolType: Qgis.SymbolType = Qgis.SymbolType.Hybrid) QPicture[source]

Draws a symbol layer preview to a QPicture

Parameters:
  • layer (Optional[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

static symbolPreviewIcon(symbol: QgsSymbol | None, size: QSize, padding: int = 0, shape: QgsLegendPatchShape | None = None, screen: QgsScreenProperties = QgsScreenProperties()) QIcon[source]

Returns an icon preview for a color ramp.

Parameters:
  • symbol (Optional[QgsSymbol]) – symbol

  • size (QSize) – target pixmap size

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

  • shape (Optional[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

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

Returns a pixmap preview for a color ramp.

Parameters:
  • symbol (Optional[QgsSymbol]) – symbol

  • size (QSize) – target pixmap size

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

  • customContext (Optional[QgsRenderContext] = None) – custom rendering context

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

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

  • shape (Optional[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

static symbolProperties(symbol: QgsSymbol | None) str[source]

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

Parameters:

symbol (Optional[QgsSymbol])

Return type:

str

static symbolToMimeData(symbol: QgsSymbol | None) QMimeData | None[source]

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 (Optional[QgsSymbol])

Return type:

Optional[QMimeData]

static tileSize(width: int, height: int, angleRad: float)[source]

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) -> (QSize) – symbol layer rotation angle in radians (counter clockwise), it may be approximated by the method to minimize the tile size.

Returns:

the size of the tile

Added in version 3.30.

static toPoint(value: Any)[source]

Converts a value to a point.

Parameters:

value (Any) -> (QPointF) – value to convert

Returns:

  • converted point

  • ok: True if value was successfully converted

See also

decodePoint()

See also

toSize()

Added in version 3.10.

static toQPolygonF(geometry: QgsGeometry, type: Qgis.SymbolType) Any

Converts a geometry to a set of QPolygonF objects representing how the geometry should be drawn for a symbol of the given type, as a list of geometry parts and rings.

Added in version 3.40.

Parameters:
Return type:

Any

static toQPolygonF(geometry: QgsAbstractGeometry | None, type: Qgis.SymbolType) Any

Converts a geometry to a set of QPolygonF objects representing how the geometry should be drawn for a symbol of the given type, as a list of geometry parts and rings.

Added in version 3.42.

Parameters:
Return type:

Any

static toSize(value: Any)[source]

Converts a value to a size.

Parameters:

value (Any) -> (QSizeF) – value to convert

Returns:

  • converted size

  • ok: True if value was successfully converted

See also

decodeSize()

See also

toPoint()

Added in version 3.10.

static toSymbolLayerPointers(renderer: QgsFeatureRenderer | None, 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.

Added in version 3.12.

Deprecated since version 3.30: Because it was related to old QgsSymbolLayerReference system.

Parameters:
Return type:

Set[QgsSymbolLayer]

static wellKnownMarkerFromSld2(element: QDomElement, name: str | None, color: QColor | Qt.GlobalColor, strokeColor: QColor | Qt.GlobalColor)

Extracts properties from an SLD marker definition.

Parameters:
  • element (QDomElement)

  • name (Optional[str])

  • color (Union[QColor, Qt.GlobalColor])

  • strokeColor (Union[QColor, Qt.GlobalColor]) -> (bool)

static wellKnownMarkerToSld(doc: QDomDocument, element: QDomElement, name: str | None, color: QColor | Qt.GlobalColor, strokeColor: QColor | Qt.GlobalColor, strokeStyle: Qt.PenStyle, strokeWidth: float = -1, size: float = -1)[source]

Exports a marker to SLD

Deprecated since version 3.44: Use the version with QgsSldExportContext instead.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • name (Optional[str])

  • color (Union[QColor, Qt.GlobalColor])

  • strokeColor (Union[QColor, Qt.GlobalColor])

  • strokeStyle (Qt.PenStyle)

  • strokeWidth (float = -1)

  • size (float = -1)

static wellKnownMarkerToSld(doc: QDomDocument, element: QDomElement, name: str | None, color: QColor | Qt.GlobalColor, strokeColor: QColor | Qt.GlobalColor, strokeStyle: Qt.PenStyle, context: QgsSldExportContext, strokeWidth: float = -1, size: float = -1)[source]

Exports a marker to SLD

Added in version 3.44.

Parameters:
  • doc (QDomDocument)

  • element (QDomElement)

  • name (Optional[str])

  • color (Union[QColor, Qt.GlobalColor])

  • strokeColor (Union[QColor, Qt.GlobalColor])

  • strokeStyle (Qt.PenStyle)

  • context (QgsSldExportContext)

  • strokeWidth (float = -1)

  • size (float = -1)