Class: QgsMapLayer

class qgis.core.QgsMapLayer(type: QgsMapLayer.LayerType = QgsMapLayer.VectorLayer, name: str = '', source: str = '')

Bases: PyQt5.QtCore.QObject

Constructor for QgsMapLayer

Parameters
  • type – layer type

  • name – display name for the layer

  • source – datasource of layer

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

Enums

Methods

abstract

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

appendError

Add error message

attribution

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

attributionUrl

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

autoRefreshInterval

Returns the auto refresh interval (in milliseconds).

blendMode

Returns the current blending mode for a layer.

childEvent

clone

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

connectNotify

createMapRenderer

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

crs

Returns the layer’s spatial reference system.

customEvent

customProperty

Read a custom property from layer.

customPropertyKeys

Returns list of all keys within custom properties.

dataProvider

Returns the layer’s data provider.

dataUrl

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

dataUrlFormat

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

decodedSource

Called by readLayerXML(), used by derived classes to decode provider’s specific data source from project files.

dependencies

Gets the list of dependencies.

disconnectNotify

emitStyleChanged

Triggers an emission of the styleChanged() signal.

encodedSource

Called by writeLayerXML(), used by derived classes to encode provider’s specific data source to project files.

error

Gets current status error.

exportNamedMetadata

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

exportNamedStyle

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

exportSldStyle

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

extensionPropertyType

Returns the extension of a Property.

extent

Returns the extent of the layer.

flags

Returns the flags for this layer.

formatLayerName

A convenience function to capitalize and format a layer name.

hasAutoRefreshEnabled

Returns true if auto refresh is enabled for the layer.

hasDependencyCycle

Checks whether a new set of dependencies will introduce a cycle

hasScaleBasedVisibility

Returns whether scale based visibility is enabled for the layer.

htmlMetadata

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

id

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

importNamedMetadata

Import the metadata of this layer from a QDomDocument

importNamedStyle

Import the properties of this layer from a QDomDocument

isEditable

Returns true if the layer can be edited.

isInScaleRange

Tests whether the layer should be visible at the specified scale.

isRefreshOnNotifyEnabled

Returns true if the refresh on provider nofification is enabled

isSignalConnected

isSpatial

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

isValid

Returns the status of the layer.

keywordList

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

legend

Can be null.

legendUrl

Returns the URL for the layer’s legend.

legendUrlFormat

Returns the format for a URL based layer legend.

loadDefaultMetadata

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)

loadDefaultStyle

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)

loadNamedMetadata

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)

loadNamedMetadataFromDatabase

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

loadNamedStyle

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)

loadNamedStyleFromDatabase

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

loadSldStyle

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

maximumScale

Returns the maximum map scale (i.e.

metadata

Returns a reference to the layer’s metadata store.

metadataUri

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)

metadataUrl

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

metadataUrlFormat

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

metadataUrlType

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

minimumScale

Returns the minimum map scale (i.e.

name

Returns the display name of the layer.

publicSource

Gets a version of the internal layer definition that has sensitive bits removed (for example, the password).

readCommonStyle

Read style data common to all layer types

readCustomProperties

Read custom properties from project file.

readLayerXml

Sets state from DOM document

readOnly

Returns if this layer is read only.

readSld

readStyle

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

readStyleManager

Read style manager’s configuration (if any).

readSymbology

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

readXml

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

receivers

refreshOnNotifyMessage

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

reload

Synchronises with changes in the datasource

removeCustomProperty

Remove a custom property from layer.

renderer3D

Returns 3D renderer associated with the layer.

resolveReferences

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

saveDefaultMetadata

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)

saveDefaultStyle

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)

saveNamedMetadata

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)

saveNamedStyle

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)

saveSldStyle

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

sender

senderSignalIndex

setAbstract

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

setAttribution

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

setAttributionUrl

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

setAutoRefreshEnabled

Sets whether auto refresh is enabled for the layer.

setAutoRefreshInterval

Sets the auto refresh interval (in milliseconds) for the layer.

setBlendMode

Set the blending mode used for rendering a layer.

setCrs

Sets layer’s spatial reference system

setCustomProperties

Set custom properties for layer.

setCustomProperty

Set a custom property for layer.

setDataUrl

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

setDataUrlFormat

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

setDependencies

Sets the list of dependencies.

setError

Sets error message

setExtent

Sets the extent

setFlags

Returns the flags for this layer.

setKeywordList

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

setLayerOrder

Reorders the previously selected sublayers of this layer from bottom to top.

setLegend

Assign a legend controller to the map layer.

setLegendUrl

Sets the URL for the layer’s legend.

setLegendUrlFormat

Sets the format for a URL based layer legend.

setMaximumScale

Sets the maximum map scale (i.e.

setMetadata

Sets the layer’s metadata store.

setMetadataUrl

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

setMetadataUrlFormat

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

setMetadataUrlType

Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType indicates the standard to which the metadata complies.

setMinimumScale

Sets the minimum map scale (i.e.

setName

Set the display name of the layer.

setRefreshOnNofifyMessage

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

setRefreshOnNotifyEnabled

Set whether provider notification is connected to triggerRepaint

setRenderer3D

Sets 3D renderer for the layer.

setScaleBasedVisibility

Sets whether scale based visibility is enabled for the layer.

setShortName

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

setSubLayerVisibility

Set the visibility of the given sublayer name.

setTitle

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

setValid

Sets whether layer is valid or not - should be used in constructor.

shortName

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

source

Returns the source for the layer.

styleManager

Gets access to the layer’s style manager.

styleURI

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)

subLayers

Returns the sublayers of this layer.

timerEvent

timestamp

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

title

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

triggerRepaint

Will advise the map canvas (and any other interested party) that this layer requires to be repainted.

type

Returns the type of the layer.

undoStack

Returns pointer to layer’s undo stack

undoStackStyles

Returns pointer to layer’s style undo stack

writeCommonStyle

Write style data common to all layer types

writeCustomProperties

Write custom properties to project file.

writeLayerXml

Stores state in DOM node

writeStyle

Write just the symbology information for the layer into the document

writeStyleManager

Write style manager’s configuration (if exists).

writeSymbology

Write the style for the layer into the docment provided.

writeXml

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

Signals

autoRefreshIntervalChanged

Emitted when the auto refresh interval changes.

blendModeChanged

Signal emitted when the blend mode is changed, through QgsMapLayer.setBlendMode() [signal]

configChanged

Emitted whenever the configuration is changed.

crsChanged

Emit a signal that layer’s CRS has been reset [signal]

dataChanged

Data of layer changed [signal]

dependenciesChanged

Emitted when dependencies are changed.

flagsChanged

Emitted when layer’s flags have been modified.

legendChanged

Signal emitted when legend of the layer has changed

metadataChanged

Emitted when the layer’s metadata is changed.

nameChanged

Emitted when the name has been changed

recalculateExtents

This is used to send a request that any mapcanvas using this layer update its extents [signal]

renderer3DChanged

Signal emitted when 3D renderer associated with the layer has changed.

rendererChanged

Signal emitted when renderer is changed.

repaintRequested

By emitting this signal the layer tells that either appearance or content have been changed and any view showing the rendered layer should refresh itself.

statusChanged

Emit a signal with status (e.g.

styleChanged

Signal emitted whenever a change affects the layer’s style.

willBeDeleted

Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid state: the last chance for other pieces of code for some cleanup if they use the layer.

Attributes

Actions

AllStyleCategories

AttributeTable

CustomProperties

Diagrams

Fields

Forms

GeometryOptions

Identifiable

Labeling

LayerConfiguration

MapTips

MeshLayer

Metadata

PluginLayer

RasterLayer

Removable

Rendering

Searchable

Style

Symbology

Symbology3D

VectorLayer

Actions = 64
AllStyleCategories = 8191
AttributeTable = 512
CustomProperties = 2048
Diagrams = 256
Fields = 16
Forms = 32
GeometryOptions = 4096
Identifiable = 1
Labeling = 8
LayerConfiguration = 1
class LayerFlag

Bases: int

baseClass

alias of QgsMapLayer

class LayerFlags

Bases: sip.wrapper

QgsMapLayer.LayerFlags(Union[QgsMapLayer.LayerFlags, QgsMapLayer.LayerFlag]) QgsMapLayer.LayerFlags(QgsMapLayer.LayerFlags)

baseClass

alias of QgsMapLayer

class LayerType

Bases: int

MapTips = 128
MeshLayer = 3
Metadata = 1
PluginLayer = 2
class PropertyType

Bases: int

RasterLayer = 1
Removable = 2
Rendering = 1024
Searchable = 4
Style = 0
class StyleCategories

Bases: sip.wrapper

QgsMapLayer.StyleCategories(Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory]) QgsMapLayer.StyleCategories(QgsMapLayer.StyleCategories)

baseClass

alias of QgsMapLayer

class StyleCategory

Bases: int

baseClass

alias of QgsMapLayer

Symbology = 2
Symbology3D = 4
VectorLayer = 0
abstract(self) → str

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

Returns

the layer abstract

See also

setAbstract()

appendError(self, error: QgsErrorMessage)

Add error message

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.

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.

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.

New in version 3.0.

autoRefreshIntervalChanged

Emitted when the auto refresh interval changes.

New in version 3.0: [signal]

blendMode(self) → QPainter.CompositionMode

Returns the current blending mode for a layer.

See also

setBlendMode()

blendModeChanged

Signal emitted when the blend mode is changed, through QgsMapLayer.setBlendMode() [signal]

childEvent()
clone(self) → QgsMapLayer

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

Returns

a new layer instance

New in version 3.0.

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

Parameters

layer – The copy recipient

New in version 3.0.

configChanged

Emitted whenever the configuration is changed. The project listens to this signal to be marked as dirty. [signal]

connectNotify()
createMapRenderer(self, rendererContext: QgsRenderContext) → QgsMapLayerRenderer

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

New in version 2.4.

crs(self) → QgsCoordinateReferenceSystem

Returns the layer’s spatial reference system.

New in version 1.4.

crsChanged

Emit a signal that layer’s CRS has been reset [signal]

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

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

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()

New in version 3.0.

dataChanged

Data of layer changed [signal]

dataProvider(self) → QgsDataProvider

Returns the layer’s data provider.

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.

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.

Returns

the layer DataUrl format

decodedSource(self, source: str, dataProvider: str, 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 – data source to decode, typically read from layer’s DOM element “datasource”

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

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

Returns

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

New in version 3.2.

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

Returns

a set of QgsMapLayerDependency

New in version 3.0.

dependenciesChanged

Emitted when dependencies are changed. [signal]

disconnectNotify()
emitStyleChanged(self)

Triggers an emission of the styleChanged() signal.

New in version 2.16.

encodedSource(self, source: str, 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
  • source – data source to encode, typically QgsMapLayer.source()

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

Returns

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

New 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.

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

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

Parameters
  • doc – the target QDomDocument

  • errorMsg – this QString will be initialized on error

New in version 3.0.

exportNamedStyle(self, doc: QDomDocument, context: QgsReadWriteContext = QgsReadWriteContext(), categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) → str

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

Parameters
  • doc – the target QDomDocument

  • errorMsg – this QString will be initialized on error

  • context – read write context

  • categories – the style categories to export during the execution of writeSymbology

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

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

Parameters
  • doc – the target QDomDocument

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

extensionPropertyType(type: QgsMapLayer.PropertyType) → str

Returns the extension of a Property.

Returns

The extension

New in version 3.0.

extent(self) → QgsRectangle

Returns the extent of the layer.

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.

New in version 3.4.

flagsChanged

Emitted when layer’s flags have been modified.

See also

setFlags()

See also

flags()

New in version 3.4: [signal]

formatLayerName(name: str) → str

A convenience function to capitalize and format a layer name.

New in version 3.0.

hasAutoRefreshEnabled(self) → bool

Returns true if auto refresh is enabled for the layer.

New in version 3.0.

hasDependencyCycle(self, layers: Iterable[QgsMapLayerDependency]) → bool

Checks whether a new set of dependencies will introduce a cycle

hasScaleBasedVisibility(self) → bool

Returns whether scale based visibility is enabled for the layer.

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.

New in version 3.0.

id(self) → str

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

importNamedMetadata(self, document: QDomDocument, errorMessage: str) → bool

Import the metadata of this layer from a QDomDocument

Parameters
  • document – source QDomDocument

  • errorMessage – this QString will be initialized on error

Returns

true on success

New in version 3.0.

importNamedStyle(self, doc: QDomDocument, categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) → Tuple[bool, str]

Import the properties of this layer from a QDomDocument

Parameters
  • doc – source QDomDocument

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

  • categories – the style categories to import

Returns

true on success

New in version 2.8.

isEditable(self) → bool

Returns true if the layer can be edited.

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.

Returns

true if the layer is visible at the given scale.

See also

minimumScale()

See also

maximumScale()

New in version 2.16.

isRefreshOnNotifyEnabled(self) → bool

Returns true if the refresh on provider nofification is enabled

New in version 3.0.

isSignalConnected()
isSpatial(self) → bool

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

New in version 2.16.

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.

Returns

true if the layer is valid and can be accessed

keywordList(self) → str

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

Returns

the layer keyword list

See also

setKeywordList()

legend(self) → QgsMapLayerLegend

Can be null.

New in version 2.6.

legendChanged

Signal emitted when legend of the layer has changed

New in version 2.6: [signal]

legendUrl(self) → str

Returns the URL for the layer’s legend.

legendUrlFormat(self) → str

Returns the format for a URL based layer legend.

loadDefaultMetadata(self) → Tuple[str, bool]

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

New in version 3.0.

loadDefaultStyle(self) → Tuple[str, bool]

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)

Parameters

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

Returns

a QString with any status messages

See also

also()

loadNamedMetadata(self, uri: str) → Tuple[str, bool]

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

    • 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.

  • 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

New in version 3.0.

loadNamedMetadataFromDatabase(self, db: str, uri: str, qmd: str) → bool

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

Parameters
  • db – path to sqlite database

  • uri – uri for table

  • qmd – will be set to QMD xml metadata content from database

Returns

true if style was successfully loaded

New in version 3.0.

loadNamedStyle(self, uri: str, categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) → Tuple[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.

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

  • categories – the style categories to be loaded.

Returns

a QString with any status messages

See also

also()

loadNamedStyleFromDatabase(self, db: str, uri: str) → Tuple[bool, str]

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

Parameters
  • db – path to sqlite database

  • uri – uri for table

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

Returns

true if style was successfully loaded

loadSldStyle(self, uri: str) → Tuple[str, bool]

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

Parameters
  • uri – 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()

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()

metadata(self) → QgsLayerMetadata

Returns a reference to the layer’s metadata store.

See also

setMetadata()

New in version 3.0.

metadataChanged

Emitted when the layer’s metadata is changed.

See also

setMetadata()

See also

metadata()

New in version 3.0: [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)

Returns

a QString with the metadata file name

New 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.

Returns

the layer metadata URL

See also

setMetadataUrl()

metadataUrlFormat(self) → str

Returns the metadata format of the layer used by QGIS Server in GetCapabilities request. MetadataUrlType indicates how the metadata is structured.

Returns

the layer metadata format

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.

Returns

the layer metadata type

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()

name(self) → str

Returns the display name of the layer.

See also

setName()

nameChanged

Emitted when the name has been changed

New in version 2.16: [signal]

publicSource(self) → 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.

See also

source()

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

Read style data common to all layer types

New in version 3.0.

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

Read custom properties from project file.

Parameters
  • layerNode – note to read from

  • keyStartsWith – reads only properties starting with the specified string (or all if the string is empty)*

readLayerXml(self, layerElement: QDomElement, context: QgsReadWriteContext) → bool

Sets state from DOM document

Parameters
  • layerElement – The DOM element corresponding to ``maplayer’’ tag

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

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()

Returns

true if successful

readOnly(self) → bool

Returns if this layer is read only.

readSld(self, node: QDomNode, errorMessage: str) → bool
readStyle(self, node: QDomNode, errorMessage: str, context: QgsReadWriteContext, categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) → bool

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

Parameters
  • node – node that will contain the style definition for this layer.

  • errorMessage – reference to string that will be updated with any error messages

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

  • categories – the style categories to be read

Returns

true in case of success.

Note

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

New in version 2.16.

readStyleManager(self, layerNode: QDomNode)

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

readSymbology(self, node: QDomNode, errorMessage: str, context: QgsReadWriteContext, categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) → bool

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

Parameters
  • node – node that will contain the symbology definition for this layer.

  • errorMessage – reference to string that will be updated with any error messages

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

  • categories – the style categories to be read

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.

recalculateExtents

This is used to send a request that any mapcanvas using this layer update its extents [signal]

receivers()
refreshOnNotifyMessage(self) → str

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

New in version 3.0.

reload(self)

Synchronises with changes in the datasource

removeCustomProperty(self, key: str)

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

renderer3D(self) → QgsAbstract3DRenderer

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

New in version 3.0.

renderer3DChanged

Signal emitted when 3D renderer associated with the layer has changed.

New in version 3.0: [signal]

rendererChanged

Signal emitted when renderer is changed.

See also

styleChanged() [signal]

repaintRequested

By emitting this signal the layer tells that either appearance or content have been changed and any view showing the rendered layer should refresh itself. 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. [signal]

resolveReferences(self, project: QgsProject)

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

New in version 3.0.

saveDefaultMetadata(self) → Tuple[str, bool]

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)

Parameters

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

New in version 3.0.

saveDefaultStyle(self) → Tuple[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)

Parameters

resultFlag – a reference to a flag that will be set to false if we did not manage to save the default style.

Returns

a QString with any status messages

See also

loadNamedStyle()

saveNamedMetadata(self, uri: str) → Tuple[str, bool]

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 – 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

New in version 3.0.

saveNamedStyle(self, uri: str, categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) → Tuple[str, bool]

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 – 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.

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

  • categories – the style categories to be saved.

Returns

a QString with any status messages

saveSldStyle(self, uri: str) → Tuple[str, bool]

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

Parameters
  • uri – 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()

sender()
senderSignalIndex()
setAbstract(self, abstract: str)

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

Returns

the layer abstract

See also

abstract()

setAttribution(self, attrib: str)

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

Returns

the layer attribution

See also

attribution()

setAttributionUrl(self, attribUrl: str)

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.

Returns

the layer attribution URL

See also

attributionUrl()

setAutoRefreshEnabled(self, enabled: bool)

Sets whether auto refresh is enabled for the layer.

New in version 3.0.

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 setAutoRefreshEnabled().

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

New in version 3.0.

setBlendMode(self, blendMode: QPainter.CompositionMode)

Set the blending mode used for rendering a layer.

Parameters

blendMode – new blending mode

See also

blendMode()

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

Sets layer’s spatial reference system

setCustomProperties(self, properties: QgsObjectCustomProperties)

Set custom properties for layer. Current properties are dropped.

New in version 3.0.

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

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

See also

customProperty()

setDataUrl(self, dataUrl: str)

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.

Returns

the layer DataUrl

See also

dataUrl()

setDataUrlFormat(self, dataUrlFormat: str)

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.

Returns

the layer DataUrl format

See also

dataUrlFormat()

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

Sets the list of dependencies.

See also

dependencies()

Parameters

layers – set of QgsMapLayerDependency. Only user-defined dependencies will be added

Returns

false if a dependency cycle has been detected

New in version 3.0.

setError(self, error: QgsError)

Sets error message

setExtent(self, rect: QgsRectangle)

Sets the extent

setFlags(self, flags: Union[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.

New in version 3.4.

setKeywordList(self, keywords: str)

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

Returns

the layer keyword list

See also

keywordList()

setLayerOrder(self, layers: Iterable[str])

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

setLegend(self, legend: QgsMapLayerLegend)

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

Parameters

legend – Takes ownership of the object. Can be null pointer

New in version 2.6.

setLegendUrl(self, legendUrl: str)

Sets the URL for the layer’s legend.

setLegendUrlFormat(self, legendUrlFormat: str)

Sets the format for a URL based layer legend.

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()

setMetadata(self, metadata: QgsLayerMetadata)

Sets the layer’s metadata store.

See also

metadata()

New in version 3.0.

setMetadataUrl(self, metaUrl: str)

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.

Returns

the layer metadata URL

See also

metadataUrl()

setMetadataUrlFormat(self, metaUrlFormat: str)

Sets the metadata format of the layer used by QGIS Server in GetCapabilities request. MetadataUrlType indicates how the metadata is structured.

Returns

the layer metadata format

setMetadataUrlType(self, metaUrlType: str)

Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType indicates the standard to which the metadata complies.

Returns

the layer metadata type

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()

setName(self, name: str)

Set the display name of the layer.

See also

name()

New in version 2.16.

setRefreshOnNofifyMessage(self, message: str)

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

New in version 3.0.

setRefreshOnNotifyEnabled(self, enabled: bool)

Set whether provider notification is connected to triggerRepaint

New in version 3.0.

setRenderer3D(self, renderer: QgsAbstract3DRenderer)

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

New in version 3.0.

setScaleBasedVisibility(self, enabled: bool)

Sets whether scale based visibility is enabled for the layer.

Parameters

enabled – set to true to enable scale based visibility

setShortName(self, shortName: str)

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

Returns

the layer short name

See also

shortName()

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

Set the visibility of the given sublayer name.

Parameters
  • name – sublayer name

  • visible – sublayer visibility

setTitle(self, title: str)

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

See also

title()

setValid(self, valid: bool)

Sets whether layer is valid or not - should be used in constructor.

shortName(self) → str

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

See also

setShortName()

source(self) → str

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

See also

publicSource()

statusChanged

Emit a signal with status (e.g. to be caught by QgisApp and display a msg on status bar) [signal]

styleChanged

Signal emitted whenever a change affects the layer’s style. Ie this may be triggered by renderer changes, label style changes, or other style changes such as blend mode or layer opacity changes.

New in version 2.16: [signal]

styleManager(self) → QgsMapLayerStyleManager

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

New in version 2.8.

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)

Returns

a QString with the style file name

See also

also()

subLayers(self) → List[str]

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

timerEvent()
timestamp(self) → QDateTime

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

title(self) → str

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

Returns

the layer title

See also

setTitle()

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

type(self) → QgsMapLayer.LayerType

Returns the type of the layer.

undoStack(self) → QUndoStack

Returns pointer to layer’s undo stack

undoStackStyles(self) → QUndoStack

Returns pointer to layer’s style undo stack

New in version 2.16.

willBeDeleted

Emitted in the destructor when the layer is about to be deleted, but it is still in a perfectly valid state: the last chance for other pieces of code for some cleanup if they use the layer.

New in version 3.0: [signal]

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

Write style data common to all layer types

New in version 3.0.

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

Write custom properties to project file.

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

Stores state in DOM node

Parameters
  • layerElement – is a DOM element corresponding to ``maplayer’’ tag

  • document – is a the DOM document being written

  • context – 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()

Returns

true if successful

writeStyle(self, node: QDomNode, doc: QDomDocument, errorMessage: str, context: QgsReadWriteContext, categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) → bool

Write just the symbology information for the layer into the document

Parameters
  • node – the node that will have the style element added to it.

  • doc – the document that will have the QDomNode added.

  • errorMessage – reference to string that will be updated with any error messages

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

  • categories – the style categories to be written

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.

New in version 2.16.

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

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

writeSymbology(self, node: QDomNode, doc: QDomDocument, errorMessage: str, context: QgsReadWriteContext, categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) → bool

Write the style for the layer into the docment provided.

Parameters
  • node – the node that will have the style element added to it.

  • doc – the document that will have the QDomNode added.

  • errorMessage – reference to string that will be updated with any error messages

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

  • categories – 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.

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.