Class: QgsMapLayer

class qgis.core.QgsMapLayer

Bases: PyQt5.QtCore.QObject

Base class for all map layer types. This is the base class for all map layer types (vector, raster).

QgsMapLayer(type: Qgis.LayerType = Qgis.LayerType.Vector, name: Optional[str] = ‘’, source: Optional[str] = ‘’) Constructor for QgsMapLayer

Parameters:
Actions = 64
AllStyleCategories = 262143
AttributeTable = 512
CustomProperties = 2048
Diagrams = 256
Elevation = 65536
Fields = 16
FlagDontResolveLayers = 1
FlagForceReadOnly = 8
FlagReadExtentFromXml = 4
FlagTrustLayerMetadata = 2
Forms = 32
GeometryOptions = 4096
Identifiable = 1
Labeling = 8
LayerConfiguration = 1
class LayerFlag

Bases: int

baseClass

alias of QgsMapLayer

class LayerFlags
class LayerFlags(f: QgsMapLayer.LayerFlags | QgsMapLayer.LayerFlag)
class LayerFlags(a0: QgsMapLayer.LayerFlags)

Bases: sip.wrapper

baseClass

alias of QgsMapLayer

class LayerType(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: enum.IntEnum

Types of layers that can be added to a map

Added in version 3.30..

  • VectorLayer: Vector layer

  • RasterLayer: Raster layer

  • PluginLayer: Plugin based layer

  • MeshLayer: Mesh layer. Added in QGIS 3.2

  • VectorTileLayer: Vector tile layer. Added in QGIS 3.14

  • AnnotationLayer: Contains freeform, georeferenced annotations. Added in QGIS 3.16

  • PointCloudLayer: Point cloud layer. Added in QGIS 3.18

  • GroupLayer: Composite group layer. Added in QGIS 3.24

  • TiledScene: Tiled scene layer. Added in QGIS 3.34

baseClass

alias of Qgis

Legend = 32768
MapTips = 128
Metadata = 1
Notes = 131072
Private = 8
class PropertyType

Bases: int

class ReadFlag

Bases: int

class ReadFlags
class ReadFlags(f: QgsMapLayer.ReadFlags | QgsMapLayer.ReadFlag)
class ReadFlags(a0: QgsMapLayer.ReadFlags)

Bases: sip.wrapper

Relations = 8192
Removable = 2
Rendering = 1024
Searchable = 4
Style = 0
class StyleCategories
class StyleCategories(f: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory)
class StyleCategories(a0: QgsMapLayer.StyleCategories)

Bases: sip.wrapper

baseClass

alias of QgsMapLayer

class StyleCategory

Bases: int

baseClass

alias of QgsMapLayer

Symbology = 2
Symbology3D = 4
Temporal = 16384
abstract(self) str

Returns the abstract of the layer used by QGIS Server in GetCapabilities request.

Return type:

str

Returns:

the layer abstract

See also

setAbstract()

accept(self, visitor: QgsStyleEntityVisitorInterface | None) bool

Accepts the specified symbology visitor, causing it to visit all symbols associated with the layer.

Returns True if the visitor should continue visiting other objects, or False if visiting should be canceled.

Added in version 3.10.

Parameters:

visitor (Optional[QgsStyleEntityVisitorInterface])

Return type:

bool

appendError(self, error: QgsErrorMessage)

Add error message

Parameters:

error (QgsErrorMessage)

attribution(self) str

Returns the attribution of the layer used by QGIS Server in GetCapabilities request. Attribution indicates the provider of a layer or collection of layers.

Return type:

str

Returns:

the layer attribution

See also

setAttribution()

attributionUrl(self) str

Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request. Attribution indicates the provider of a layer or collection of layers.

Return type:

str

Returns:

the layer attribution URL

autoRefreshInterval(self) int

Returns the auto refresh interval (in milliseconds). Note that auto refresh is only active when hasAutoRefreshEnabled() is True.

Added in version 3.0.

Return type:

int

autoRefreshIntervalChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

autoRefreshMode(self) Qgis.AutoRefreshMode

Returns the layer’s automatical refresh mode.

Added in version 3.34.

Return type:

Qgis.AutoRefreshMode

beforeResolveReferences

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

blendMode(self) QPainter.CompositionMode

Returns the current blending mode for a layer.

See also

setBlendMode()

Return type:

QPainter.CompositionMode

blendModeChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

childEvent(self, a0: QChildEvent | None)
clone(self) QgsMapLayer | None

Returns a new instance equivalent to this one except for the id which is still unique.

Return type:

Optional[QgsMapLayer]

Returns:

a new layer instance

Added in version 3.0.

clone(self, layer: Optional[QgsMapLayer]) Copies attributes like name, short name, … into another layer.

Parameters:

layer – The copy recipient

Added in version 3.0.

configChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

connectNotify(self, signal: QMetaMethod)
createMapRenderer(self, rendererContext: QgsRenderContext) QgsMapLayerRenderer | None

Returns new instance of QgsMapLayerRenderer that will be used for rendering of given context

Added in version 2.4.

Parameters:

rendererContext (QgsRenderContext)

Return type:

Optional[QgsMapLayerRenderer]

crs(self) QgsCoordinateReferenceSystem

Returns the layer’s spatial reference system.

Added in version 1.4.

Return type:

QgsCoordinateReferenceSystem

crsChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

customEvent(self, a0: QEvent | None)
customProperties(self) QgsObjectCustomProperties

Read all custom properties from layer. Properties are stored in a map and saved in project file.

Added in version 3.14.

Return type:

QgsObjectCustomProperties

customProperty(self, value: str | None, defaultValue: Any = None) Any

Read a custom property from layer. Properties are stored in a map and saved in project file.

Parameters:
  • value (Optional[str])

  • defaultValue (Any = None)

Return type:

Any

customPropertyChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

customPropertyKeys(self) List[str]

Returns list of all keys within custom properties. Properties are stored in a map and saved in project file.

See also

customProperty()

Added in version 3.0.

Return type:

List[str]

dataChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

dataProvider(self) QgsDataProvider | None

Returns the layer’s data provider, it may be None.

Return type:

Optional[QgsDataProvider]

dataSourceChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

dataUrl(self) str

Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request. DataUrl is a a link to the underlying data represented by a particular layer.

Return type:

str

Returns:

the layer DataUrl

See also

setDataUrl()

dataUrlFormat(self) str

Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request. DataUrl is a a link to the underlying data represented by a particular layer.

Return type:

str

Returns:

the layer DataUrl format

decodedSource(self, source: str | None, dataProvider: str | None, context: QgsReadWriteContext) str

Called by readLayerXML(), used by derived classes to decode provider’s specific data source from project files. Typically resolving absolute or relative paths, usernames and passwords or drivers prefixes (“HDF5:”)

Parameters:
  • source (Optional[str]) – data source to decode, typically read from layer’s DOM element “datasource”

  • dataProvider (Optional[str]) – string identification of data provider (e.g. “ogr”), typically read from layer’s DOM element

  • context (QgsReadWriteContext) – reading context (e.g. for conversion between relative and absolute paths)

Return type:

str

Returns:

decoded source, typically to be used as the layer’s datasource

Added in version 3.2.

deleteStyleFromDatabase(self, styleId: str | None)

Deletes a style from the database

Parameters:

styleId (Optional[str]) -> (bool) – the provider’s layer_styles table id of the style to delete

Returns:

  • True in case of success

  • msgError: will be set to a descriptive error message if any occurs

Added in version 3.0.

dependencies(self) Set[QgsMapLayerDependency]

Gets the list of dependencies. This includes data dependencies set by the user (setDataDependencies()) as well as dependencies given by the provider

Return type:

Set[QgsMapLayerDependency]

Returns:

a set of QgsMapLayerDependency

Added in version 3.0.

dependenciesChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

disconnectNotify(self, signal: QMetaMethod)
editingStarted

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

editingStopped

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

elevationProperties(self) QgsMapLayerElevationProperties | None

Returns the layer’s elevation properties. This may be None, depending on the layer type.

Added in version 3.18.

Return type:

Optional[QgsMapLayerElevationProperties]

emitStyleChanged(self)

Triggers an emission of the styleChanged() signal.

Added in version 2.16.

encodedSource(self, source: str | None, context: QgsReadWriteContext) str

Called by writeLayerXML(), used by derived classes to encode provider’s specific data source to project files. Typically resolving absolute or relative paths, usernames and passwords or drivers prefixes (“HDF5:”)

Parameters:
Return type:

str

Returns:

encoded source, typically to be written in the DOM element “datasource”

Added in version 3.2.

error(self) QgsError

Gets current status error. This error describes some principal problem for which layer cannot work and thus is not valid. It is not last error after accessing data by draw() etc.

Return type:

QgsError

exportNamedMetadata(self, doc: QDomDocument, errorMsg: str | None)

Export the current metadata of this layer as named metadata in a QDomDocument

Parameters:
  • doc (QDomDocument) – the target QDomDocument

  • errorMsg (Optional[str]) – this QString will be initialized on error

Added in version 3.0.

exportNamedStyle(self, doc: QDomDocument, context: QgsReadWriteContext = QgsReadWriteContext(), categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories) str

Export the properties of this layer as named style in a QDomDocument

Parameters:
  • doc (QDomDocument) – the target QDomDocument

  • errorMsg – this QString will be initialized on error

  • context (QgsReadWriteContext = QgsReadWriteContext()) – read write context

  • categories (Union[QgsMapLayer.StyleCategories) – the style categories to export during the execution of writeSymbology

Return type:

str

exportSldStyle(self, doc: QDomDocument, errorMsg: str | None)

Export the properties of this layer as SLD style in a QDomDocument

Parameters:
  • doc (QDomDocument) – the target QDomDocument

  • errorMsg (Optional[str]) – this QString will be initialized on error during the execution of writeSymbology

exportSldStyleV2(self, doc: QDomDocument, errorMsg: str | None, exportContext: QgsSldExportContext)

Export the properties of this layer as SLD style in a QDomDocument

Parameters:
  • doc (QDomDocument) – the target QDomDocument

  • errorMsg (Optional[str]) – this QString will be initialized on error during the execution of writeSymbology

  • exportContext (QgsSldExportContext) – SLD export context

Added in version 3.30.

extensionPropertyType(type: QgsMapLayer.PropertyType) str

Returns the extension of a Property.

Return type:

str

Returns:

The extension

Added in version 3.0.

Parameters:

type (QgsMapLayer.PropertyType)

extent(self) QgsRectangle

Returns the extent of the layer.

Return type:

QgsRectangle

flags(self) QgsMapLayer.LayerFlags

Returns the flags for this layer.

Note

Flags are options specified by the user used for the UI but are not preventing any API call. For instance, even if the Removable flag is not set, the layer can still be removed with the API but the action will not be listed in the legend menu.

See also

properties()

Added in version 3.4.

Return type:

QgsMapLayer.LayerFlags

flagsChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

formatLayerName(name: str | None) str

A convenience function to capitalize and format a layer name.

Added in version 3.0.

Parameters:

name (Optional[str])

Return type:

str

generateId(layerName: str | None) str

Generates an unique identifier for this layer, the generate ID is prefixed by layerName

Added in version 3.8.

Parameters:

layerName (Optional[str])

Return type:

str

getStyleFromDatabase(self, styleId: str | None)

Returns the named style corresponding to style id provided

Parameters:

styleId (Optional[str]) -> (str)

hasAutoRefreshEnabled(self) bool

Returns True if auto refresh is enabled for the layer.

Deprecated since version use: autoRefreshMode() instead.

Return type:

bool

hasDependencyCycle(self, a0: Iterable[QgsMapLayerDependency]) bool

Checks whether a new set of dependencies will introduce a cycle this method is now deprecated and always return False, because circular dependencies are now correctly managed.

Deprecated since version QGIS: 3.10

Parameters:

a0 (Iterable[QgsMapLayerDependency])

Return type:

bool

hasMapTips(self) bool

Returns True if the layer contains map tips.

See also

mapTipTemplate()

Return type:

bool

hasScaleBasedVisibility(self) bool

Returns whether scale based visibility is enabled for the layer.

Return type:

bool

Returns:

True if scale based visibility is enabled

See also

minimumScale()

See also

maximumScale()

See also

isInScaleRange()

htmlMetadata(self) str

Obtain a formatted HTML string containing assorted metadata for this layer.

Added in version 3.0.

Return type:

str

id(self) str

Returns the layer’s unique ID, which is used to access this layer from QgsProject.

Return type:

str

importNamedMetadata(self, document: QDomDocument, errorMessage: str | None) bool

Import the metadata of this layer from a QDomDocument

Parameters:
  • document (QDomDocument) – source QDomDocument

  • errorMessage (Optional[str]) – this QString will be initialized on error

Return type:

bool

Returns:

True on success

Added in version 3.0.

importNamedStyle(self, doc: QDomDocument, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories)

Import the properties of this layer from a QDomDocument

Parameters:
  • doc (QDomDocument) – source QDomDocument

  • errorMsg – this QString will be initialized on error during the execution of readSymbology

  • categories (Union[QgsMapLayer.StyleCategories) – the style categories to import

Returns:

True on success

Added in version 2.8.

invalidateWgs84Extent(self)

Invalidates the WGS84 extent. If FlagTrustLayerMetadata is enabled, the extent is not invalidated because we want to trust metadata whatever happens.

Added in version 3.20.

isEditable(self) bool

Returns True if the layer can be edited.

Return type:

bool

isInScaleRange(self, scale: float) bool

Tests whether the layer should be visible at the specified scale. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

Return type:

bool

Returns:

True if the layer is visible at the given scale.

See also

minimumScale()

See also

maximumScale()

Added in version 2.16.

Parameters:

scale (float)

isModified(self) bool

Returns True if the layer has been modified since last commit/save.

Note

default implementation returns False.

Added in version 3.22.

Return type:

bool

isRefreshOnNotifyEnabled(self) bool

Returns True if the refresh on provider nofification is enabled

Added in version 3.0.

Return type:

bool

isSignalConnected(self, signal: QMetaMethod) bool
isSpatial(self) bool

Returns True if the layer is considered a spatial layer, ie it has some form of geometry associated with it.

Added in version 2.16.

Return type:

bool

isTemporary(self) bool

Returns True if the layer is considered a temporary layer.

These include memory-only layers such as those created by the “memory” data provider, layers stored inside a local temporary folder (such as the “/tmp” folder on Linux) or layer with temporary data (as temporary mesh layer dataset)

Added in version 3.10.1.

Return type:

bool

isValid(self) bool

Returns the status of the layer. An invalid layer is one which has a bad datasource or other problem. Child classes set this flag when initialized.

Return type:

bool

Returns:

True if the layer is valid and can be accessed

isValidChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

keywordList(self) str

Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.

Return type:

str

Returns:

the layer keyword list

See also

setKeywordList()

layerModified

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

legend(self) QgsMapLayerLegend | None

Can be None.

Added in version 2.6.

Return type:

Optional[QgsMapLayerLegend]

legendChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

legendPlaceholderImage(self) str

Returns path to the placeholder image or an empty string if a generated legend is shown

Return type:

str

Returns:

placholder image path

Added in version 3.22.

legendUrl(self) str

Returns the URL for the layer’s legend.

Return type:

str

legendUrlFormat(self) str

Returns the format for a URL based layer legend.

Return type:

str

listStylesInDatabase(self)

Lists all the style in db split into related to the layer and not related to

Parameters:
  • ids – the list in which will be stored the style db ids

  • names – the list in which will be stored the style names

Returns:

  • the number of styles related to current layer (-1 on not implemented)

  • descriptions: the list in which will be stored the style descriptions

  • msgError: will be set to a descriptive error message if any occurs

Note

Since QGIS 3.2 Styles related to the layer are ordered with the default style first then by update time for Postgres, MySQL and Spatialite.

loadDefaultMetadata(self)

Retrieve the default metadata for this layer if one exists (either as a .qmd file on disk or as a record in the users metadata table in their personal qgis.db)

Parameters:

resultFlag – a reference to a flag that will be set to False if we did not manage to load the default metadata.

Returns:

a QString with any status messages

Added in version 3.0.

loadDefaultStyle(self)

Retrieve the default style for this layer if one exists (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)

Returns:

  • a QString with any status messages

  • resultFlag: a reference to a flag that will be set to False if we did not manage to load the default style.

See also

loadNamedStyle()

loadNamedMetadata(self, uri: str | None)

Retrieve a named metadata for this layer if one exists (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db)

Parameters:

uri (Optional[str]) -> (str) –

  • the file name or other URI for the

metadata file. First an attempt will be made to see if this is a file and load that, if that fails the qgis.db metadata table will be consulted to see if there is a metadata who’s key matches the URI.

Returns:

  • a QString with any status messages

  • resultFlag: a reference to a flag that will be set to False if we did not manage to load the default metadata.

Added in version 3.0.

loadNamedMetadataFromDatabase(self, db: str | None, uri: str | None, qmd: str | None) bool

Retrieve a named metadata for this layer from a sqlite database.

Parameters:
  • db (Optional[str]) – path to sqlite database

  • uri (Optional[str]) – uri for table

  • qmd (Optional[str]) – will be set to QMD xml metadata content from database

Return type:

bool

Returns:

True if style was successfully loaded

Added in version 3.0.

loadNamedStyle(self, theURI: str | None, loadFromLocalDb: bool, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories)

Loads a named style from file/local db/datasource db

Parameters:
  • theURI (Optional[str]) – the URI of the style or the URI of the layer

  • resultFlag – will be set to True if a named style is correctly loaded

  • loadFromLocalDb (bool) – if True forces to load from local db instead of datasource one

  • categories (Union[QgsMapLayer.StyleCategories) – the style categories to be loaded.

loadNamedStyle(self, uri: Optional[str], categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) -> (str, bool) Retrieve a named style for this layer if one exists (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)

Parameters:
  • uri

    • the file name or other URI for the

    style file. First an attempt will be made to see if this is a file and load that, if that fails the qgis.db styles table will be consulted to see if there is a style who’s key matches the URI.

  • categories – the style categories to be loaded.

Returns:

  • a QString with any status messages

  • resultFlag: a reference to a flag that will be set to False if we did not manage to load the default style.

loadNamedStyleFromDatabase(self, db: str | None, uri: str | None)

Retrieve a named style for this layer from a sqlite database.

Parameters:
  • db (Optional[str]) – path to sqlite database

  • uri (Optional[str]) -> (bool) – uri for table

Returns:

  • True if style was successfully loaded

  • qml: will be set to QML style content from database

loadSldStyle(self, uri: str | None)

Attempts to style the layer using the formatting from an SLD type file.

Parameters:
  • uri (Optional[str]) -> (str) – uri of source SLD file

  • resultFlag – a reference to a flag that will be set to False if the SLD file could not be loaded

Returns:

a string with any status or error messages

See also

saveSldStyle()

mapTipTemplate(self) str

The mapTip is a pretty, html representation for feature information.

It may also contain embedded expressions.

Note

this method was only available for vector layers since QGIS 3.0

Added in version 3.30.

Return type:

str

mapTipTemplateChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

mapTipsEnabled(self) bool

Returns true if map tips are enabled for this layer

Added in version 3.32.

Return type:

bool

mapTipsEnabledChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

maximumScale(self) float

Returns the maximum map scale (i.e. most “zoomed in” scale) at which the layer will be visible. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no maximum scale visibility.

Note

Scale based visibility is only used if setScaleBasedVisibility() is set to True.

See also

minimumScale()

See also

isInScaleRange()

Return type:

float

metadata(self) QgsLayerMetadata

Returns a reference to the layer’s metadata store.

See also

setMetadata()

Added in version 3.0.

Return type:

QgsLayerMetadata

metadataChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

metadataUri(self) str

Retrieve the metadata URI for this layer (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db)

Return type:

str

Returns:

a QString with the metadata file name

Added in version 3.0.

metadataUrl(self) str

Returns the metadata URL of the layer used by QGIS Server in GetCapabilities request. MetadataUrl is a a link to the detailed, standardized metadata about the data. Since QGIS 3.22, it returns the first metadata URL link.

Return type:

str

Returns:

the layer metadata URL

Deprecated since version QGIS: 3.22

metadataUrlFormat(self) str

Returns the metadata format of the layer used by QGIS Server in GetCapabilities request. MetadataUrlType indicates how the metadata is structured. Since QGIS 3.22, it returns the first metadata URL format.

Return type:

str

Returns:

the layer metadata format

Deprecated since version QGIS: 3.22

metadataUrlType(self) str

Returns the metadata type of the layer used by QGIS Server in GetCapabilities request. MetadataUrlType indicates the standard to which the metadata complies. Since QGIS 3.22, it returns the first metadata URL type.

Return type:

str

Returns:

the layer metadata type

Deprecated since version QGIS: 3.22

minimumScale(self) float

Returns the minimum map scale (i.e. most “zoomed out” scale) at which the layer will be visible. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no minimum scale visibility.

Note

Scale based visibility is only used if setScaleBasedVisibility() is set to True.

See also

maximumScale()

See also

isInScaleRange()

Return type:

float

name(self) str

Returns the display name of the layer.

See also

setName()

Return type:

str

nameChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

opacity(self) float

Returns the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque).

See also

setOpacity()

See also

opacityChanged()

Note

Prior to QGIS 3.18, this method was available for vector layers only

Added in version 3.18.

Return type:

float

opacityChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

originalXmlProperties(self) str

Returns the XML properties of the original layer as they were when the layer was first read from the project file. In case of new layers this is normally empty.

The storage format for the XML is qlr

Added in version 3.6.

Return type:

str

project(self) QgsProject | None

Returns the parent project if this map layer is added to a project. Otherwise returns None

Added in version 3.18.

Return type:

Optional[QgsProject]

properties(self) Qgis.MapLayerProperties

Returns the map layer properties of this layer.

Note

properties() differ from flags() in that flags() are user settable, and reflect options that users can enable for map layers. In contrast properties() are reflections of inherent capabilities for the layer, which cannot be directly changed by users.

Added in version 3.22.

Return type:

Qgis.MapLayerProperties

providerReadFlags(layerNode: QDomNode, layerReadFlags: QgsMapLayer.ReadFlags | QgsMapLayer.ReadFlag) QgsDataProvider.ReadFlags

Returns provider read flag deduced from layer read flags layerReadFlags and a dom node layerNode that describes a layer (corresponding to ``maplayer’’ tag in a DOM document project file read by QgsProject). This static method is used when loading a project.

Added in version 3.32.

Parameters:
Return type:

QgsDataProvider.ReadFlags

providerType(self) str

Returns the provider type (provider key) for this layer

Return type:

str

publicSource(self, hidePassword: bool = False) str

Gets a version of the internal layer definition that has sensitive bits removed (for example, the password). This function should be used when displaying the source name for general viewing.

Parameters:

hidePassword (bool = False) – False, if the password should be removed or replaced by an arbitrary string, since QGIS 3.34

See also

source()

Return type:

str

readCommonStyle(self, layerElement: QDomElement, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories)

Read style data common to all layer types

Added in version 3.0.

Parameters:
readCustomProperties(self, layerNode: QDomNode, keyStartsWith: str | None = '')

Read custom properties from project file.

Parameters:
  • layerNode (QDomNode) – note to read from

  • keyStartsWith (Optional[str] = '') – reads only properties starting with the specified string (or all if the string is empty)

readLayerXml(self, layerElement: QDomElement, context: QgsReadWriteContext, flags: QgsMapLayer.ReadFlags | QgsMapLayer.ReadFlag = QgsMapLayer.ReadFlags(), preloadedProvider: QgsDataProvider | None = None) bool

Sets state from DOM document

Parameters:
  • layerElement (QDomElement) – The DOM element corresponding to ``maplayer’’ tag

  • context (QgsReadWriteContext) – writing context (e.g. for conversion between relative and absolute paths)

  • flags (Union[QgsMapLayer.ReadFlags) – optional argument which can be used to control layer reading behavior.

  • preloadedProvider (Optional[QgsDataProvider] = None) – optional preloaded data provider that will be used as data provider for this layer, takes ownership (since QGIS 3.32)

note

The DOM node corresponds to a DOM document project file XML element read by QgsProject.

This, in turn, calls readXml() (and then readSymbology()), which is overridable by sub-classes so that they can read their own specific state from the given DOM node.

Invoked by QgsProject.read().

Return type:

bool

Returns:

True if successful

readOnly(self) bool

Returns if this layer is read only.

Return type:

bool

readSld(self, node: QDomNode, errorMessage: str | None) bool
Parameters:
  • node (QDomNode)

  • errorMessage (Optional[str])

Return type:

bool

readStyle(self, node: QDomNode, errorMessage: str | None, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories) bool

Read the style for the current layer from the DOM node supplied.

Parameters:
  • node (QDomNode) – node that will contain the style definition for this layer.

  • errorMessage (Optional[str]) – reference to string that will be updated with any error messages

  • context (QgsReadWriteContext) – reading context (used for transform from relative to absolute paths)

  • categories (Union[QgsMapLayer.StyleCategories) – the style categories to be read

Return type:

bool

Returns:

True in case of success.

Note

To be implemented in subclasses. Default implementation does nothing and returns False.

Added in version 2.16.

readStyleManager(self, layerNode: QDomNode)

Read style manager’s configuration (if any). To be called by subclasses.

Parameters:

layerNode (QDomNode)

readSymbology(self, node: QDomNode, errorMessage: str | None, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories) bool

Read the symbology for the current layer from the DOM node supplied.

Parameters:
  • node (QDomNode) – node that will contain the symbology definition for this layer.

  • errorMessage (Optional[str]) – reference to string that will be updated with any error messages

  • context (QgsReadWriteContext) – reading context (used for transform from relative to absolute paths)

  • categories (Union[QgsMapLayer.StyleCategories) – the style categories to be read

Return type:

bool

Returns:

True in case of success.

readXml(self, layer_node: QDomNode, context: QgsReadWriteContext) bool

Called by readLayerXML(), used by children to read state specific to them from project files.

Parameters:
Return type:

bool

recalculateExtents

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

receivers(self, signal: PYQT_SIGNAL) int
refreshOnNotifyMessage(self) str

Returns the message that should be notified by the provider to triggerRepaint

Added in version 3.0.

Return type:

str

reload(self)

Synchronises with changes in the datasource

removeCustomProperty(self, key: str | None)

Remove a custom property from layer. Properties are stored in a map and saved in project file.

Parameters:

key (Optional[str])

renderer3D(self) QgsAbstract3DRenderer | None

Returns 3D renderer associated with the layer. May be None.

Added in version 3.0.

Return type:

Optional[QgsAbstract3DRenderer]

renderer3DChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

rendererChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

repaintRequested

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

request3DUpdate

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

resolveReferences(self, project: QgsProject | None)

Resolve references to other layers (kept as layer IDs after reading XML) into layer objects.

Added in version 3.0.

Parameters:

project (Optional[QgsProject])

saveDefaultMetadata(self)

Save the current metadata of this layer as the default metadata (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db)

Returns:

  • a QString with any status messages

  • resultFlag: a reference to a flag that will be set to False if we did not manage to save the default metadata.

Added in version 3.0.

saveDefaultStyle(self, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory)

Save the properties of this layer as the default style (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)

Parameters:

categories (Union[QgsMapLayer.StyleCategories) – the style categories to be saved (since QGIS 3.26)

Returns:

  • a QString with any status messages

  • resultFlag: a reference to a flag that will be set to False if we did not manage to save the default style.

See also

loadNamedStyle()

See also

saveNamedStyle()

saveDefaultStyle(self) -> (str, bool) Save the properties of this layer as the default style (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)

Returns:

  • a QString with any status messages

  • resultFlag: a reference to a flag that will be set to False if we did not manage to save the default style.

See also

loadNamedStyle()

See also

saveNamedStyle()

Deprecated since version QGIS: 3.26

saveNamedMetadata(self, uri: str | None)

Save the current metadata of this layer as a named metadata (either as a .qmd file on disk or as a record in the users style table in their personal qgis.db)

Parameters:
  • uri (Optional[str]) -> (str) – the file name or other URI for the metadata file. First an attempt will be made to see if this is a file and save to that, if that fails the qgis.db metadata table will be used to create a metadata entry who’s key matches the URI.

  • resultFlag – a reference to a flag that will be set to False if we did not manage to save the default metadata.

Returns:

a QString with any status messages

Added in version 3.0.

saveNamedStyle(self, uri: str | None, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories)

Save the properties of this layer as a named style (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)

Parameters:
  • uri (Optional[str]) – the file name or other URI for the style file. First an attempt will be made to see if this is a file and save to that, if that fails the qgis.db styles table will be used to create a style entry who’s key matches the URI.

  • categories (Union[QgsMapLayer.StyleCategories) – the style categories to be saved.

Returns:

  • a QString with any status messages

  • resultFlag: a reference to a flag that will be set to False if we did not manage to save the default style.

saveSldStyle(self, uri: str | None)

Saves the properties of this layer to an SLD format file.

Parameters:
  • uri (Optional[str]) -> (str) – uri of destination for exported SLD file.

  • resultFlag – a reference to a flag that will be set to False if the SLD file could not be generated

Returns:

a string with any status or error messages

See also

loadSldStyle()

See also

saveSldStyleV2()

saveSldStyleV2(self, exportContext: QgsSldExportContext)

Saves the properties of this layer to an SLD format file.

Parameters:

exportContext (QgsSldExportContext) -> (str) – SLD export context

Returns:

  • a string with any status or error messages

  • resultFlag: a reference to a flag that will be set to False if the SLD file could not be generated

See also

loadSldStyle()

Added in version 3.30.

saveStyleToDatabase(self, name: str | None, description: str | None, useAsDefault: bool, uiFileContent: str | None, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories) str

Saves named and sld style of the layer to the style table in the db.

Parameters:
  • name (Optional[str]) – Style name

  • description (Optional[str]) – A description of the style

  • useAsDefault (bool) – Set to True if style should be used as the default style for the layer

  • uiFileContent (Optional[str])

  • msgError – will be set to a descriptive error message if any occurs

  • categories (Union[QgsMapLayer.StyleCategories) – the style categories to be saved.

Note

Prior to QGIS 3.24, this method would show a message box warning when a style with the same styleName already existed to confirm replacing the style with the user. Since 3.24, calling this method will ALWAYS overwrite any existing style with the same name. Use QgsProviderRegistry.styleExists() to test in advance if a style already exists and handle this appropriately in your client code.

Return type:

str

selectionProperties(self) QgsMapLayerSelectionProperties | None

Returns the layer’s selection properties. This may be None, depending on the layer type.

Added in version 3.34.

Return type:

Optional[QgsMapLayerSelectionProperties]

sender(self) QObject | None
senderSignalIndex(self) int
serverProperties(self) QgsMapLayerServerProperties | None

Returns QGIS Server Properties for the map layer

Added in version 3.22.

Return type:

Optional[QgsMapLayerServerProperties]

setAbstract(self, abstract: str | None)

Sets the abstract of the layer used by QGIS Server in GetCapabilities request.

See also

abstract()

Parameters:

abstract (Optional[str])

setAttribution(self, attrib: str | None)

Sets the attribution of the layer used by QGIS Server in GetCapabilities request. Attribution indicates the provider of a layer or collection of layers.

See also

attribution()

Parameters:

attrib (Optional[str])

setAttributionUrl(self, attribUrl: str | None)

Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request. Attribution indicates the provider of a layer or collection of layers.

See also

attributionUrl()

Parameters:

attribUrl (Optional[str])

setAutoRefreshEnabled(self, enabled: bool)

Sets whether auto refresh is enabled for the layer.

Deprecated since version Use: setAutoRefreshMode() instead.

Parameters:

enabled (bool)

setAutoRefreshInterval(self, interval: int)

Sets the auto refresh interval (in milliseconds) for the layer. This will cause the layer to be automatically redrawn on a matching interval. Note that auto refresh must be enabled by calling setAutoRefreshMode().

Note that auto refresh triggers deferred repaints of the layer. Any map canvas must be refreshed separately in order to view the refreshed layer.

Added in version 3.0.

Parameters:

interval (int)

setAutoRefreshMode(self, mode: Qgis.AutoRefreshMode)

Sets the automatic refresh mode for the layer.

Added in version 3.34.

Parameters:

mode (Qgis.AutoRefreshMode)

setBlendMode(self, blendMode: QPainter.CompositionMode)

Set the blending mode used for rendering a layer.

Parameters:

blendMode (QPainter.CompositionMode) – new blending mode

See also

blendMode()

setCrs(self, srs: QgsCoordinateReferenceSystem, emitSignal: bool = True)

Sets layer’s spatial reference system

Parameters:
setCustomProperties(self, properties: QgsObjectCustomProperties)

Set custom properties for layer. Current properties are dropped.

Added in version 3.0.

Parameters:

properties (QgsObjectCustomProperties)

setCustomProperty(self, key: str | None, value: Any)

Set a custom property for layer. Properties are stored in a map and saved in project file.

See also

customProperty()

Parameters:
  • key (Optional[str])

  • value (Any)

setDataSource(self, dataSource: str | None, baseName: str | None, provider: str | None, loadDefaultStyleFlag: bool = False)

Updates the data source of the layer.

The dataSource argument must specify the new data source string for the layer. The format varies depending on the specified data provider in use. See QgsDataSourceUri and the documentation for the various QgsMapLayer subclasses for further details on data source strings.

The baseName argument specifies the user-visible name to use for the layer. (See name() or setName()).

The provider argument is used to specify the unique key of the data provider to use for the layer. This must match one of the values returned by QgsProviderRegistry.instance()->:py:func:~QgsMapLayer.providerList. (See providerType()).

If loadDefaultStyleFlag is set to True then the layer’s existing style will be reset to the default for the data source.

Note

If loadDefaultStyleFlag is False then the layer’s renderer and legend will be preserved only if the geometry type of the new data source matches the current geometry type of the layer.

After setting a new data source callers can test isValid() to determine whether the new source and provider are valid and ready for use. If setting the new data source fails and the layer returns False to isValid(), then descriptive errors relating to setting the data source can be retrieved by calling error().

This method was defined in QgsVectorLayer since 2.10 and was marked as deprecated since 3.2

Added in version 3.20.

setDataSource(self, dataSource: Optional[str], baseName: Optional[str], provider: Optional[str], options: QgsDataProvider.ProviderOptions, loadDefaultStyleFlag: bool = False) Updates the data source of the layer.

The dataSource argument must specify the new data source string for the layer. The format varies depending on the specified data provider in use. See QgsDataSourceUri and the documentation for the various QgsMapLayer subclasses for further details on data source strings.

The baseName argument specifies the user-visible name to use for the layer. (See name() or setName()).

The provider argument is used to specify the unique key of the data provider to use for the layer. This must match one of the values returned by QgsProviderRegistry.instance()->:py:func:~QgsMapLayer.providerList. (See providerType()).

The options argument can be used to pass additional layer properties to the new data provider.

If loadDefaultStyleFlag is set to True then the layer’s existing style will be reset to the default for the data source.

Note

If loadDefaultStyleFlag is False then the layer’s renderer and legend will be preserved only if the geometry type of the new data source matches the current geometry type of the layer.

After setting a new data source callers can test isValid() to determine whether the new source and provider are valid and ready for use. If setting the new data source fails and the layer returns False to isValid(), then descriptive errors relating to setting the data source can be retrieved by calling error().

Added in version 3.6.

setDataSource(self, dataSource: Optional[str], baseName: Optional[str], provider: Optional[str], options: QgsDataProvider.ProviderOptions, flags: Union[QgsDataProvider.ReadFlags, QgsDataProvider.ReadFlag]) Updates the data source of the layer.

The dataSource argument must specify the new data source string for the layer. The format varies depending on the specified data provider in use. See QgsDataSourceUri and the documentation for the various QgsMapLayer subclasses for further details on data source strings.

The baseName argument specifies the user-visible name to use for the layer. (See name() or setName()).

The provider argument is used to specify the unique key of the data provider to use for the layer. This must match one of the values returned by QgsProviderRegistry.instance()->:py:func:~QgsMapLayer.providerList. (See providerType()).

The options argument can be used to pass additional layer properties to the new data provider.

The flags argument specifies provider read flags which control the data provider construction, such as QgsDataProvider.ReadFlag.FlagTrustDataSource, QgsDataProvider.ReadFlag.FlagLoadDefaultStyle, etc.

Note

The layer’s renderer and legend will be preserved only if the geometry type of the new data source matches the current geometry type of the layer.

After setting a new data source callers can test isValid() to determine whether the new source and provider are valid and ready for use. If setting the new data source fails and the layer returns False to isValid(), then descriptive errors relating to setting the data source can be retrieved by calling error().

Added in version 3.20.

Parameters:
  • dataSource (Optional[str])

  • baseName (Optional[str])

  • provider (Optional[str])

  • loadDefaultStyleFlag (bool = False)

setDataUrl(self, dataUrl: str | None)

Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request. DataUrl is a a link to the underlying data represented by a particular layer.

See also

dataUrl()

Parameters:

dataUrl (Optional[str])

setDataUrlFormat(self, dataUrlFormat: str | None)

Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request. DataUrl is a a link to the underlying data represented by a particular layer.

See also

dataUrlFormat()

Parameters:

dataUrlFormat (Optional[str])

setDependencies(self, layers: Iterable[QgsMapLayerDependency]) bool

Sets the list of dependencies.

See also

dependencies()

Parameters:

layers (Iterable[QgsMapLayerDependency]) – set of QgsMapLayerDependency. Only user-defined dependencies will be added

Return type:

bool

Returns:

False if a dependency cycle has been detected

Added in version 3.0.

setError(self, error: QgsError)

Sets error message

Parameters:

error (QgsError)

setExtent(self, rect: QgsRectangle)

Sets the extent

Parameters:

rect (QgsRectangle)

setFlags(self, flags: QgsMapLayer.LayerFlags | QgsMapLayer.LayerFlag)

Returns the flags for this layer.

Note

Flags are options specified by the user used for the UI but are not preventing any API call. For instance, even if the Removable flag is not set, the layer can still be removed with the API but the action will not be listed in the legend menu.

See also

properties()

Added in version 3.4.

Parameters:

flags (Union[QgsMapLayer.LayerFlags)

setKeywordList(self, keywords: str | None)

Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.

See also

keywordList()

Parameters:

keywords (Optional[str])

setLayerOrder(self, layers: Iterable[str | None])

Reorders the previously selected sublayers of this layer from bottom to top. (Useful for providers that manage their own layers, such as WMS).

Parameters:

layers (Iterable[Optional[str]])

setLegend(self, legend: QgsMapLayerLegend | None)

Assign a legend controller to the map layer. The object will be responsible for providing legend items.

Parameters:

legend (Optional[QgsMapLayerLegend]) – Takes ownership of the object. Can be None.

Added in version 2.6.

setLegendPlaceholderImage(self, imgPath: str | None)

Set placeholder image for legend. If the string is empty, a generated legend will be shown.

Parameters:

imgPath (Optional[str]) – file path to the placeholder image

Added in version 3.22.

setLegendUrl(self, legendUrl: str | None)

Sets the URL for the layer’s legend.

Parameters:

legendUrl (Optional[str])

setLegendUrlFormat(self, legendUrlFormat: str | None)

Sets the format for a URL based layer legend.

Parameters:

legendUrlFormat (Optional[str])

setMapTipTemplate(self, mapTipTemplate: str | None)

The mapTip is a pretty, html representation for feature information.

It may also contain embedded expressions.

Note

this method was only available for vector layers since QGIS 3.0

Added in version 3.30.

Parameters:

mapTipTemplate (Optional[str])

setMapTipsEnabled(self, enabled: bool)

Enable or disable map tips for this layer

Parameters:

enabled (bool) – Whether map tips are enabled for this layer

Added in version 3.32.

setMaximumScale(self, scale: float)

Sets the maximum map scale (i.e. most “zoomed in” scale) at which the layer will be visible. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no maximum scale visibility.

Note

Scale based visibility is only used if setScaleBasedVisibility() is set to True.

See also

maximumScale()

Parameters:

scale (float)

setMetadata(self, metadata: QgsLayerMetadata)

Sets the layer’s metadata store.

See also

metadata()

Added in version 3.0.

Parameters:

metadata (QgsLayerMetadata)

setMetadataUrl(self, metaUrl: str | None)

Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request. MetadataUrl is a a link to the detailed, standardized metadata about the data. Since QGIS 3.22, it edits the first metadata URL link.

Deprecated since version QGIS: 3.22

Parameters:

metaUrl (Optional[str])

setMetadataUrlFormat(self, metaUrlFormat: str | None)

Sets the metadata format of the layer used by QGIS Server in GetCapabilities request. MetadataUrlType indicates how the metadata is structured. Since QGIS 3.22, it edits the first metadata URL format.

Deprecated since version QGIS: 3.22

Parameters:

metaUrlFormat (Optional[str])

setMetadataUrlType(self, metaUrlType: str | None)

Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType indicates the standard to which the metadata complies. Since QGIS 3.22, it edits the first metadata URL type.

Deprecated since version QGIS: 3.22

Parameters:

metaUrlType (Optional[str])

setMinimumScale(self, scale: float)

Sets the minimum map scale (i.e. most “zoomed out” scale) at which the layer will be visible. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no minimum scale visibility.

Note

Scale based visibility is only used if setScaleBasedVisibility() is set to True.

See also

minimumScale()

Parameters:

scale (float)

setName(self, name: str | None)

Set the display name of the layer.

See also

name()

Added in version 2.16.

Parameters:

name (Optional[str])

setOpacity(self, opacity: float)

Sets the opacity for the layer, where opacity is a value between 0 (totally transparent) and 1.0 (fully opaque).

See also

opacity()

See also

opacityChanged()

Note

Prior to QGIS 3.18, this method was available for vector layers only

Added in version 3.18.

Parameters:

opacity (float)

setOriginalXmlProperties(self, originalXmlProperties: str | None)

Sets the original XML properties for the layer to originalXmlProperties

The storage format for the XML is qlr

Added in version 3.6.

Parameters:

originalXmlProperties (Optional[str])

setProviderType(self, providerType: str | None)

Sets the providerType (provider key)

Parameters:

providerType (Optional[str])

setRefreshOnNofifyMessage(self, message: str | None)

Set the notification message that triggers repaint If refresh on notification is enabled, the notification will triggerRepaint only if the notification message is equal to:param message:

Added in version 3.0.

Parameters:

message (Optional[str])

setRefreshOnNotifyEnabled(self, enabled: bool)

Set whether provider notification is connected to triggerRepaint

Added in version 3.0.

Parameters:

enabled (bool)

setRenderer3D(self, renderer: QgsAbstract3DRenderer | None)

Sets 3D renderer for the layer. Takes ownership of the renderer.

Added in version 3.0.

Parameters:

renderer (Optional[QgsAbstract3DRenderer])

setScaleBasedVisibility(self, enabled: bool)

Sets whether scale based visibility is enabled for the layer.

Parameters:

enabled (bool) – set to True to enable scale based visibility

setShortName(self, shortName: str | None)

Sets the short name of the layer used by QGIS Server to identify the layer.

See also

shortName()

Parameters:

shortName (Optional[str])

setSubLayerVisibility(self, name: str | None, visible: bool)

Set the visibility of the given sublayer name.

Parameters:
  • name (Optional[str]) – sublayer name

  • visible (bool) – sublayer visibility

setTitle(self, title: str | None)

Sets the title of the layer used by QGIS Server in GetCapabilities request.

See also

title()

Parameters:

title (Optional[str])

setTransformContext(self, transformContext: QgsCoordinateTransformContext)

Sets the coordinate transform context to transformContext

Added in version 3.8.

Parameters:

transformContext (QgsCoordinateTransformContext)

setValid(self, valid: bool)

Sets whether layer is valid or not

Parameters:

valid (bool)

shortName(self) str

Returns the short name of the layer used by QGIS Server to identify the layer.

See also

setShortName()

Return type:

str

source(self) str

Returns the source for the layer. This source may contain usernames, passwords and other sensitive information.

See also

publicSource()

Return type:

str

statusChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

styleChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

styleLoaded

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

styleManager(self) QgsMapLayerStyleManager | None

Gets access to the layer’s style manager. Style manager allows switching between multiple styles.

Added in version 2.8.

Return type:

Optional[QgsMapLayerStyleManager]

styleURI(self) str

Retrieve the style URI for this layer (either as a .qml file on disk or as a record in the users style table in their personal qgis.db)

Return type:

str

Returns:

a QString with the style file name

See also

loadNamedStyle()

See also

saveNamedStyle()

subLayers(self) List[str]

Returns the sublayers of this layer. (Useful for providers that manage their own layers, such as WMS).

Return type:

List[str]

supportsEditing(self) bool

Returns whether the layer supports editing or not.

Return type:

bool

Returns:

False if the layer is read only or the data provider has no editing capabilities.

Note

default implementation returns False.

Added in version 3.22.

temporalProperties(self) QgsMapLayerTemporalProperties | None

Returns the layer’s temporal properties. This may be None, depending on the layer type.

Added in version 3.14.

Return type:

Optional[QgsMapLayerTemporalProperties]

timerEvent(self, a0: QTimerEvent | None)
timestamp(self) QDateTime

Time stamp of data source in the moment when data/metadata were loaded by provider

Return type:

QDateTime

title(self) str

Returns the title of the layer used by QGIS Server in GetCapabilities request.

Return type:

str

Returns:

the layer title

See also

setTitle()

transformContext(self) QgsCoordinateTransformContext

Returns the layer data provider coordinate transform context or a default transform context if the layer does not have a valid data provider.

Added in version 3.8.

Return type:

QgsCoordinateTransformContext

trigger3DUpdate(self)

Will advise any 3D maps that this layer requires to be updated in the scene. Will emit a request3DUpdate() signal.

Added in version 3.18.

triggerRepaint(self, deferredUpdate: bool = False)

Will advise the map canvas (and any other interested party) that this layer requires to be repainted. Will emit a repaintRequested() signal. If deferredUpdate is True then the layer will only be repainted when the canvas is next re-rendered, and will not trigger any canvas redraws itself.

Note

in 2.6 function moved from vector/raster subclasses to QgsMapLayer

Parameters:

deferredUpdate (bool = False)

type(self) Qgis.LayerType

Returns the type of the layer.

Return type:

Qgis.LayerType

undoStack(self) QUndoStack | None

Returns pointer to layer’s undo stack

Return type:

Optional[QUndoStack]

undoStackStyles(self) QUndoStack | None

Returns pointer to layer’s style undo stack

Added in version 2.16.

Return type:

Optional[QUndoStack]

wgs84Extent(self, forceRecalculate: bool = False) QgsRectangle

Returns the WGS84 extent (EPSG:4326) of the layer according to ReadFlag.FlagTrustLayerMetadata. If that flag is activated, then the WGS84 extent read in the qgs project is returned. Otherwise, the actual WGS84 extent is returned.

Parameters:

forceRecalculate (bool = False) – True to return the current WGS84 extent whatever the read flags

Added in version 3.20.

Return type:

QgsRectangle

willBeDeleted

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

writeCommonStyle(self, layerElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories)

Write style data common to all layer types

Added in version 3.0.

Parameters:
writeCustomProperties(self, layerNode: QDomNode, doc: QDomDocument)

Write custom properties to project file.

Parameters:
  • layerNode (QDomNode)

  • doc (QDomDocument)

writeLayerXml(self, layerElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool

Stores state in DOM node

Parameters:
  • layerElement (QDomElement) – is a DOM element corresponding to ``maplayer’’ tag

  • document (QDomDocument) – is a the DOM document being written

  • context (QgsReadWriteContext) – reading context (e.g. for conversion between relative and absolute paths)

note

The DOM node corresponds to a DOM document project file XML element to be written by QgsProject.

This, in turn, calls writeXml() (and then writeSymbology), which is over-rideable by sub-classes so that they can write their own specific state to the given DOM node.

Invoked by QgsProject.write().

Return type:

bool

Returns:

True if successful

writeStyle(self, node: QDomNode, doc: QDomDocument, errorMessage: str | None, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories) bool

Write just the symbology information for the layer into the document

Parameters:
  • node (QDomNode) – the node that will have the style element added to it.

  • doc (QDomDocument) – the document that will have the QDomNode added.

  • errorMessage (Optional[str]) – reference to string that will be updated with any error messages

  • context (QgsReadWriteContext) – writing context (used for transform from absolute to relative paths)

  • categories (Union[QgsMapLayer.StyleCategories) – the style categories to be written

Return type:

bool

Returns:

True in case of success.

Note

To be implemented in subclasses. Default implementation does nothing and returns False.

Note

There is a confusion of terms with the GUI. This method actually writes what is known as the symbology in the application.

Added in version 2.16.

writeStyleManager(self, layerNode: QDomNode, doc: QDomDocument)

Write style manager’s configuration (if exists). To be called by subclasses.

Parameters:
  • layerNode (QDomNode)

  • doc (QDomDocument)

writeSymbology(self, node: QDomNode, doc: QDomDocument, errorMessage: str | None, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories) bool

Write the style for the layer into the document provided.

Parameters:
  • node (QDomNode) – the node that will have the style element added to it.

  • doc (QDomDocument) – the document that will have the QDomNode added.

  • errorMessage (Optional[str]) – reference to string that will be updated with any error messages

  • context (QgsReadWriteContext) – writing context (used for transform from absolute to relative paths)

  • categories (Union[QgsMapLayer.StyleCategories) – the style categories to be written

Note

There is a confusion of terms with the GUI. This method actually writes what is called a style in the application.

Return type:

bool

Returns:

True in case of success.

writeXml(self, layer_node: QDomNode, document: QDomDocument, context: QgsReadWriteContext) bool

Called by writeLayerXML(), used by children to write state specific to them to project files.

Parameters:
Return type:

bool