Class: QgsMapLayerFactory

Contains utility functions for creating map layers.

Added in version 3.18.1.

Static Methods

createLayer

Creates a map layer, given a uri, name, layer type and provider name.

typeFromString

Returns the map layer type corresponding a string value.

typeToString

Converts a map layer type to a string value.

class qgis.core.QgsMapLayerFactory[source]

Bases: object

class LayerOptions

Bases: object

Setting options for loading layers.

Added in version 3.22.

loadAllStoredStyles: bool

Controls whether the stored styles will be all loaded.

If True and the layer’s provider supports style stored in the data source all the available styles will be loaded in addition to the default one.

If False (the default), the layer’s provider will only load the default style.

Added in version 3.30.

loadDefaultStyle: bool

Set to True if the default layer style should be loaded

transformContext: QgsCoordinateTransformContext

Transform context

static createLayer(uri: str | None, name: str | None, type: Qgis.LayerType, options: QgsMapLayerFactory.LayerOptions, provider: str | None = '') QgsMapLayer | None[source]

Creates a map layer, given a uri, name, layer type and provider name.

Caller takes ownership of the returned layer.

Added in version 3.22.

Parameters:
Return type:

Optional[QgsMapLayer]

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

Returns the map layer type corresponding a string value.

Parameters:

string (Optional[str]) -> (Qgis.LayerType) – string to convert to map layer type

Returns:

  • converted map layer type

  • ok: True if string was successfully converted to a map layer type

See also

typeToString()

static typeToString(type: Qgis.LayerType) str[source]

Converts a map layer type to a string value.

See also

typeFromString()

Parameters:

type (Qgis.LayerType)

Return type:

str