Class: QgsMapLayer¶
-
class
qgis.core.
QgsMapLayer
(type: QgsMapLayerType = QgsMapLayerType.VectorLayer, name: str = '', source: str = '')¶ Bases:
PyQt5.QtCore.QObject
Constructor for QgsMapLayer
- Parameters
type (
QgsMapLayerType
= QgsMapLayerType.VectorLayer) – layer typename (str = '') – display name for the layer
source (str = '') – datasource of layer
Base class for all map layer types. This is the base class for all map layer types (vector, raster).
Enums
alias of
QgsMapLayerType
Methods
Returns the abstract of the layer used by QGIS Server in GetCapabilities request.
Accepts the specified symbology
visitor
, causing it to visit all symbols associated with the layer.Add error message
Returns the attribution of the layer used by QGIS Server in GetCapabilities request.
Returns the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Returns the auto refresh interval (in milliseconds).
Returns the current blending mode for a layer.
Returns a new instance equivalent to this one except for the id which is still unique.
Returns new instance of
QgsMapLayerRenderer
that will be used for rendering of given contextReturns the layer’s spatial reference system.
Read all custom properties from layer.
Read a custom property from layer.
Returns list of all keys within custom properties.
Returns the layer’s data provider, it may be
None
.Returns the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Returns the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Called by
readLayerXML()
, used by derived classes to decode provider’s specific data source from project files.Gets the list of dependencies.
Triggers an emission of the
styleChanged()
signal.Called by
writeLayerXML()
, used by derived classes to encode provider’s specific data source to project files.Gets current status error.
Export the current metadata of this layer as named metadata in a QDomDocument
Export the properties of this layer as named style in a QDomDocument
Export the properties of this layer as SLD style in a QDomDocument
Returns the extension of a Property.
Returns the extent of the layer.
Returns the flags for this layer.
A convenience function to capitalize and format a layer
name
.Generates an unique identifier for this layer, the generate ID is prefixed by
layerName
Returns
True
if auto refresh is enabled for the layer.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.
Returns whether scale based visibility is enabled for the layer.
Obtain a formatted HTML string containing assorted metadata for this layer.
Returns the layer’s unique ID, which is used to access this layer from
QgsProject
.Import the metadata of this layer from a QDomDocument
Import the properties of this layer from a QDomDocument
Returns
True
if the layer can be edited.Tests whether the layer should be visible at the specified
scale
.Returns
True
if the refresh on provider nofification is enabledReturns
True
if the layer is considered a spatial layer, ie it has some form of geometry associated with it.Returns
True
if the layer is considered a temporary layer.Returns the status of the layer.
Returns the keyword list of the layer used by QGIS Server in GetCapabilities request.
Can be
None
.Returns the URL for the layer’s legend.
Returns the format for a URL based layer legend.
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)
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)
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)
Retrieve a named metadata for this layer from a sqlite database.
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)
Retrieve a named style for this layer from a sqlite database.
Attempts to style the layer using the formatting from an SLD type file.
Returns the maximum map scale (i.e.
Returns a reference to the layer’s metadata store.
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 the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Returns the metadata format of the layer used by QGIS Server in GetCapabilities request.
Returns the metadata type of the layer used by QGIS Server in GetCapabilities request.
Returns the minimum map scale (i.e.
Returns the display name of the layer.
Returns the XML properties of the original layer as they were when the layer was first read from the project file.
Returns the provider type (provider key) for this layer
Gets a version of the internal layer definition that has sensitive bits removed (for example, the password).
Read style data common to all layer types
Read custom properties from project file.
Sets state from DOM document
Returns if this layer is read only.
- param node
Read the style for the current layer from the DOM node supplied.
Read style manager’s configuration (if any).
Read the symbology for the current layer from the DOM node supplied.
Called by
readLayerXML()
, used by children to read state specific to them from project files.Returns the message that should be notified by the provider to triggerRepaint
Synchronises with changes in the datasource
Remove a custom property from layer.
Returns 3D renderer associated with the layer.
Resolve references to other layers (kept as layer IDs after reading XML) into layer objects.
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)
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)
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)
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)
Saves the properties of this layer to an SLD format file.
Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
Sets the attribution of the layer used by QGIS Server in GetCapabilities request.
Sets the attribution URL of the layer used by QGIS Server in GetCapabilities request.
Sets whether auto refresh is enabled for the layer.
Sets the auto refresh interval (in milliseconds) for the layer.
Set the blending mode used for rendering a layer.
Sets layer’s spatial reference system
Set custom properties for layer.
Set a custom property for layer.
Updates the data source of the layer.
Sets the DataUrl of the layer used by QGIS Server in GetCapabilities request.
Sets the DataUrl format of the layer used by QGIS Server in GetCapabilities request.
Sets the list of dependencies.
Sets error message
Sets the extent
Returns the flags for this layer.
Sets the keyword list of the layer used by QGIS Server in GetCapabilities request.
Reorders the previously selected sublayers of this layer from bottom to top.
Assign a legend controller to the map layer.
Sets the URL for the layer’s legend.
Sets the format for a URL based layer legend.
Sets the maximum map
scale
(i.e.Sets the layer’s
metadata
store.Sets the metadata URL of the layer used by QGIS Server in GetCapabilities request.
Sets the metadata format of the layer used by QGIS Server in GetCapabilities request.
Set the metadata type of the layer used by QGIS Server in GetCapabilities request MetadataUrlType indicates the standard to which the metadata complies.
Sets the minimum map
scale
(i.e.Set the display
name
of the layer.Sets the original XML properties for the layer to
originalXmlProperties
Sets the
providerType
(provider key)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:
Set whether provider notification is connected to triggerRepaint
Sets 3D renderer for the layer.
Sets whether scale based visibility is enabled for the layer.
Sets the short name of the layer used by QGIS Server to identify the layer.
Set the visibility of the given sublayer name.
Sets the title of the layer used by QGIS Server in GetCapabilities request.
Sets the coordinate transform context to
transformContext
Sets whether layer is valid or not - should be used in constructor.
Returns the short name of the layer used by QGIS Server to identify the layer.
Returns the source for the layer.
Gets access to the layer’s style manager.
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 the sublayers of this layer.
Returns the layer’s temporal properties.
Time stamp of data source in the moment when data/metadata were loaded by provider
Returns the title of the layer used by QGIS Server in GetCapabilities request.
Returns the layer data provider coordinate transform context or a default transform context if the layer does not have a valid data provider.
Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
Returns the type of the layer.
Returns pointer to layer’s undo stack
Returns pointer to layer’s style undo stack
Write style data common to all layer types
Write custom properties to project file.
Stores state in DOM node
Write just the symbology information for the layer into the document
Write style manager’s configuration (if exists).
Write the style for the layer into the docment provided.
Called by
writeLayerXML()
, used by children to write state specific to them to project files.Signals
Emitted when the auto refresh interval changes.
Emitted when all layers are loaded and references can be resolved, just before the references of this layer are resolved.
Signal emitted when the blend mode is changed, through
QgsMapLayer.setBlendMode()
[signal]Emitted whenever the configuration is changed.
Emit a signal that layer’s CRS has been reset [signal]
Data of layer changed [signal]
Emitted whenever the layer’s data source has been changed.
Emitted when dependencies are changed.
Emitted when layer’s flags have been modified.
Signal emitted when legend of the layer has changed
Emitted when the layer’s metadata is changed.
Emitted when the name has been changed
This is used to send a request that any mapcanvas using this layer update its extents [signal]
Signal emitted when 3D renderer associated with the layer has changed.
Signal emitted when renderer is changed.
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.
Emit a signal with status (e.g.
Signal emitted whenever a change affects the layer’s style.
Emitted when a style has been loaded
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
= 64¶
-
AllStyleCategories
= 32767¶
-
AttributeTable
= 512¶
-
CustomProperties
= 2048¶
-
Diagrams
= 256¶
-
Fields
= 16¶
-
FlagDontResolveLayers
= 1¶
-
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
-
-
LayerType
¶ alias of
QgsMapLayerType
-
MapTips
= 128¶
-
MeshLayer
= 3¶
-
Metadata
= 1¶
-
PluginLayer
= 2¶
-
class
PropertyType
¶ Bases:
int
-
RasterLayer
= 1¶
-
class
ReadFlag
¶ Bases:
int
-
class
ReadFlags
¶ Bases:
sip.wrapper
QgsMapLayer.ReadFlags(Union[QgsMapLayer.ReadFlags, QgsMapLayer.ReadFlag]) QgsMapLayer.ReadFlags(QgsMapLayer.ReadFlags)
-
Relations
= 8192¶
-
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¶
-
Temporal
= 16384¶
-
VectorLayer
= 0¶
-
VectorTileLayer
= 4¶
-
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
-
accept
(self, visitor: QgsStyleEntityVisitorInterface) → 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, orFalse
if visiting should be canceled.New in version 3.10.
- Parameters
visitor (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
-
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
See also
-
autoRefreshInterval
(self) → int¶ Returns the auto refresh interval (in milliseconds). Note that auto refresh is only active when
hasAutoRefreshEnabled()
isTrue
.See also
See also
New in version 3.0.
- Return type
int
-
autoRefreshIntervalChanged
¶ Emitted when the auto refresh interval changes.
See also
New in version 3.0: [signal]
- Parameters
interval (int) –
-
beforeResolveReferences
¶ Emitted when all layers are loaded and references can be resolved, just before the references of this layer are resolved.
New in version 3.10: [signal]
- Parameters
project (QgsProject) –
-
blendMode
(self) → QPainter.CompositionMode¶ Returns the current blending mode for a layer.
See also
- Return type
QPainter.CompositionMode
-
blendModeChanged
¶ Signal emitted when the blend mode is changed, through
QgsMapLayer.setBlendMode()
[signal]- Parameters
blendMode (QPainter.CompositionMode) –
-
childEvent
(self, QChildEvent)¶
-
clone
(self) → QgsMapLayer¶ Returns a new instance equivalent to this one except for the id which is still unique.
- Return type
- 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
(self, QMetaMethod)¶
-
createMapRenderer
(self, rendererContext: QgsRenderContext) → QgsMapLayerRenderer¶ Returns new instance of
QgsMapLayerRenderer
that will be used for rendering of given contextNew in version 2.4.
- Parameters
rendererContext (QgsRenderContext) –
- Return type
-
crs
(self) → QgsCoordinateReferenceSystem¶ Returns the layer’s spatial reference system.
New in version 1.4.
- Return type
-
crsChanged
¶ Emit a signal that layer’s CRS has been reset [signal]
-
customEvent
(self, QEvent)¶
-
customProperties
(self) → QgsObjectCustomProperties¶ Read all custom properties from layer. Properties are stored in a map and saved in project file.
See also
New in version 3.14.
- Return type
-
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.
See also
- Parameters
value (str) –
defaultValue (Any = None) –
- Return type
Any
-
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
New in version 3.0.
- Return type
List[str]
-
dataChanged
¶ Data of layer changed [signal]
-
dataProvider
(self) → QgsDataProvider¶ Returns the layer’s data provider, it may be
None
.- Return type
-
dataSourceChanged
¶ Emitted whenever the layer’s data source has been changed.
See also
New in version 3.5: [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
-
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
See also
-
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 (str) – data source to decode, typically read from layer’s DOM element “datasource”
dataProvider (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
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- Return type
- Returns
a set of QgsMapLayerDependency
New in version 3.0.
-
dependenciesChanged
¶ Emitted when dependencies are changed. [signal]
-
disconnectNotify
(self, QMetaMethod)¶
-
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 (str) – data source to encode, typically
QgsMapLayer.source()
context (QgsReadWriteContext) – writing context (e.g. for conversion between relative and absolute paths)
- Return type
str
- 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.- Return type
-
exportNamedMetadata
(self, doc: QDomDocument, errorMsg: str)¶ Export the current metadata of this layer as named metadata in a QDomDocument
- Parameters
doc (QDomDocument) – the target QDomDocument
errorMsg (str) – 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 (QDomDocument) – the target QDomDocument
errorMsg – this QString will be initialized on error
context (
QgsReadWriteContext
= QgsReadWriteContext()) – read write contextcategories (Union[QgsMapLayer.StyleCategories) – the style categories to export during the execution of writeSymbology
- Return type
str
-
exportSldStyle
(self, doc: QDomDocument, errorMsg: str)¶ Export the properties of this layer as SLD style in a QDomDocument
- Parameters
doc (QDomDocument) – the target QDomDocument
errorMsg (str) – this QString will be initialized on error during the execution of writeSymbology
-
extensionPropertyType
(type: QgsMapLayer.PropertyType) → str¶ Returns the extension of a Property.
- Return type
str
- Returns
The extension
New in version 3.0.
- Parameters
type (QgsMapLayer.PropertyType) –
-
extent
(self) → QgsRectangle¶ Returns the extent of the layer.
- Return type
-
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.
- Return type
-
flagsChanged
¶ Emitted when layer’s flags have been modified.
See also
See also
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.
- Parameters
name (str) –
- Return type
str
-
generateId
(layerName: str) → str¶ Generates an unique identifier for this layer, the generate ID is prefixed by
layerName
New in version 3.8.
- Parameters
layerName (str) –
- Return type
str
-
hasAutoRefreshEnabled
(self) → bool¶ Returns
True
if auto refresh is enabled for the layer.See also
See also
New in version 3.0.
- Return type
bool
-
hasDependencyCycle
(self, 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
- 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
See also
See also
See also
-
htmlMetadata
(self) → str¶ Obtain a formatted HTML string containing assorted metadata for this layer.
New 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) → bool¶ Import the metadata of this layer from a QDomDocument
- Parameters
document (QDomDocument) – source QDomDocument
errorMessage (str) – this QString will be initialized on error
- Return type
bool
- 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 (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
- Return type
Tuple[bool, str]
- Returns
True
on success
New in version 2.8.
-
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
. Thescale
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
See also
See also
New in version 2.16.
- Parameters
scale (float) –
-
isRefreshOnNotifyEnabled
(self) → bool¶ Returns
True
if the refresh on provider nofification is enabledNew in version 3.0.
- Return type
bool
-
isSignalConnected
(self, 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.New 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, or layers stored inside a local temporary folder (such as the “/tmp” folder on Linux).
New 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
-
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
-
legend
(self) → QgsMapLayerLegend¶ Can be
None
.New in version 2.6.
- Return type
-
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.
- Return type
str
-
legendUrlFormat
(self) → str¶ Returns the format for a URL based layer legend.
- Return type
str
-
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.- Return type
Tuple[str, bool]
- 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)
- Return type
Tuple[str, bool]
- 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
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 (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.
- Return type
Tuple[str, bool]
- 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.
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 (str) – path to sqlite database
uri (str) – uri for table
qmd (str) – will be set to QMD xml metadata content from database
- Return type
bool
- 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 (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 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 (Union[QgsMapLayer.StyleCategories) – the style categories to be loaded.
- Return type
Tuple[str, bool]
- 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
also()
-
loadNamedStyleFromDatabase
(self, db: str, uri: str) → Tuple[bool, str]¶ Retrieve a named style for this layer from a sqlite database.
- Parameters
db (str) – path to sqlite database
uri (str) – uri for table
- Return type
Tuple[bool, str]
- Returns
True
if style was successfully loadedqml: will be set to QML style content from database
-
loadSldStyle
(self, uri: str) → Tuple[str, bool]¶ Attempts to style the layer using the formatting from an SLD type file.
- Parameters
uri (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
- Return type
Tuple[str, bool]
- Returns
a string with any status or error messages
See also
-
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 toTrue
.See also
See also
See also
See also
- Return type
float
-
metadata
(self) → QgsLayerMetadata¶ Returns a reference to the layer’s metadata store.
See also
See also
New in version 3.0.
- Return type
-
metadataChanged
¶ Emitted when the layer’s metadata is changed.
See also
See also
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)
- Return type
str
- 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.
- Return type
str
- Returns
the layer metadata URL
See also
-
metadataUrlFormat
(self) → str¶ Returns the metadata format of the layer used by QGIS Server in GetCapabilities request. MetadataUrlType indicates how the metadata is structured.
- Return type
str
- Returns
the layer metadata format
See also
-
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.
- Return type
str
- Returns
the layer metadata type
See also
-
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 toTrue
.See also
See also
See also
See also
- Return type
float
-
nameChanged
¶ Emitted when the name has been changed
New in version 2.16: [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
New in version 3.6.
- Return type
str
-
providerType
(self) → str¶ Returns the provider type (provider key) for this layer
- Return type
str
-
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
- Return type
str
-
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.
- Parameters
layerElement (QDomElement) –
context (QgsReadWriteContext) –
categories (Union[QgsMapLayer.StyleCategories) –
-
readCustomProperties
(self, layerNode: QDomNode, keyStartsWith: str = '')¶ Read custom properties from project file.
- Parameters
layerNode (QDomNode) – note to read from
keyStartsWith (str = '') – reads only properties starting with the specified string (or all if the string is empty)*
-
readLayerXml
(self, layerElement: QDomElement, context: QgsReadWriteContext, flags: Union[QgsMapLayer.ReadFlags, QgsMapLayer.ReadFlag] = QgsMapLayer.ReadFlags()) → 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.
note
The DOM node corresponds to a DOM document project file XML element read by
QgsProject
.This, in turn, calls
readXml()
(and thenreadSymbology()
), 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) → bool¶ - Parameters
node (QDomNode) –
errorMessage (str) –
- Return type
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 (QDomNode) – node that will contain the style definition for this layer.
errorMessage (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
.New 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, 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 (QDomNode) – node that will contain the symbology definition for this layer.
errorMessage (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
layer_node (QDomNode) –
context (QgsReadWriteContext) –
- Return type
bool
-
recalculateExtents
¶ This is used to send a request that any mapcanvas using this layer update its extents [signal]
-
receivers
(self, PYQT_SIGNAL) → int¶
-
refreshOnNotifyMessage
(self) → str¶ Returns the message that should be notified by the provider to triggerRepaint
New in version 3.0.
- Return type
str
-
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.
See also
- Parameters
key (str) –
-
renderer3D
(self) → QgsAbstract3DRenderer¶ Returns 3D renderer associated with the layer. May be
None
.New in version 3.0.
- Return type
-
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
isTrue
then the layer will only be repainted when the canvas is next re-rendered, and will not trigger any canvas redraws itself. [signal]- Parameters
deferredUpdate (bool = False) –
-
resolveReferences
(self, project: QgsProject)¶ Resolve references to other layers (kept as layer IDs after reading XML) into layer objects.
New in version 3.0.
- Parameters
project (QgsProject) –
-
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)
- Return type
Tuple[str, bool]
- 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.
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)
- Return type
Tuple[str, bool]
- 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
-
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 (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.
- Return type
Tuple[str, bool]
- 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 (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.
- Return type
Tuple[str, bool]
- 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
-
saveSldStyle
(self, uri: str) → Tuple[str, bool]¶ Saves the properties of this layer to an SLD format file.
- Parameters
uri (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
- Return type
Tuple[str, bool]
- Returns
a string with any status or error messages
See also
-
sender
(self) → QObject¶
-
senderSignalIndex
(self) → int¶
-
setAbstract
(self, abstract: str)¶ Sets the abstract of the layer used by QGIS Server in GetCapabilities request.
- Returns
the layer abstract
See also
- Parameters
abstract (str) –
-
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
- Parameters
attrib (str) –
-
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
- Parameters
attribUrl (str) –
-
setAutoRefreshEnabled
(self, enabled: bool)¶ Sets whether auto refresh is enabled for the layer.
See also
See also
New in version 3.0.
- 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
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.
See also
See also
New in version 3.0.
- Parameters
interval (int) –
-
setBlendMode
(self, blendMode: QPainter.CompositionMode)¶ Set the blending mode used for rendering a layer.
- Parameters
blendMode (QPainter.CompositionMode) – new blending mode
See also
-
setCrs
(self, srs: QgsCoordinateReferenceSystem, emitSignal: bool = True)¶ Sets layer’s spatial reference system
- Parameters
srs (QgsCoordinateReferenceSystem) –
emitSignal (bool = True) –
-
setCustomProperties
(self, properties: QgsObjectCustomProperties)¶ Set custom properties for layer. Current properties are dropped.
New in version 3.0.
- Parameters
properties (QgsObjectCustomProperties) –
-
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
See also
- Parameters
key (str) –
value (Any) –
-
setDataSource
(self, dataSource: str, baseName: str, provider: str, options: QgsDataProvider.ProviderOptions, loadDefaultStyleFlag: bool = False)¶ Updates the data source of the layer. 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.
Subclasses should override this method: default implementation does nothing.
- Parameters
dataSource (str) – new layer data source
baseName (str) – base name of the layer
provider (str) – provider string
options (QgsDataProvider.ProviderOptions) – provider options
loadDefaultStyleFlag (bool = False) – set to
True
to reset the layer’s style to the default for the data source
See also
New in version 3.6.
-
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
- Parameters
dataUrl (str) –
-
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
- Parameters
dataUrlFormat (str) –
-
setDependencies
(self, layers: Iterable[QgsMapLayerDependency]) → bool¶ Sets the list of dependencies.
See also
- 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
New in version 3.0.
-
setExtent
(self, rect: QgsRectangle)¶ Sets the extent
- Parameters
rect (QgsRectangle) –
-
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.
- Parameters
flags (Union[QgsMapLayer.LayerFlags) –
-
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
- Parameters
keywords (str) –
-
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).
- Parameters
layers (Iterable[str]) –
-
setLegend
(self, legend: QgsMapLayerLegend)¶ Assign a legend controller to the map layer. The object will be responsible for providing legend items.
- Parameters
legend (QgsMapLayerLegend) – Takes ownership of the object. Can be
None
.
New in version 2.6.
-
setLegendUrl
(self, legendUrl: str)¶ Sets the URL for the layer’s legend.
- Parameters
legendUrl (str) –
-
setLegendUrlFormat
(self, legendUrlFormat: str)¶ Sets the format for a URL based layer legend.
- Parameters
legendUrlFormat (str) –
-
setMaximumScale
(self, scale: float)¶ Sets the maximum map
scale
(i.e. most “zoomed in” scale) at which the layer will be visible. Thescale
value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. Ascale
of 0 indicates no maximum scale visibility.Note
Scale based visibility is only used if
setScaleBasedVisibility()
is set toTrue
.See also
See also
See also
- Parameters
scale (float) –
-
setMetadata
(self, metadata: QgsLayerMetadata)¶ Sets the layer’s
metadata
store.See also
See also
New in version 3.0.
- Parameters
metadata (QgsLayerMetadata) –
-
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
- Parameters
metaUrl (str) –
-
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
See also
- Parameters
metaUrlFormat (str) –
-
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
See also
- Parameters
metaUrlType (str) –
-
setMinimumScale
(self, scale: float)¶ Sets the minimum map
scale
(i.e. most “zoomed out” scale) at which the layer will be visible. Thescale
value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. Ascale
of 0 indicates no minimum scale visibility.Note
Scale based visibility is only used if
setScaleBasedVisibility()
is set toTrue
.See also
See also
See also
- Parameters
scale (float) –
-
setName
(self, name: str)¶ Set the display
name
of the layer.See also
New in version 2.16.
- Parameters
name (str) –
-
setOriginalXmlProperties
(self, originalXmlProperties: str)¶ Sets the original XML properties for the layer to
originalXmlProperties
The storage format for the XML is qlr
New in version 3.6.
- Parameters
originalXmlProperties (str) –
-
setProviderType
(self, providerType: str)¶ Sets the
providerType
(provider key)- Parameters
providerType (str) –
-
setRefreshOnNofifyMessage
(self, message: str)¶ 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:
New in version 3.0.
- Parameters
message (str) –
-
setRefreshOnNotifyEnabled
(self, enabled: bool)¶ Set whether provider notification is connected to triggerRepaint
New in version 3.0.
- Parameters
enabled (bool) –
-
setRenderer3D
(self, renderer: QgsAbstract3DRenderer)¶ Sets 3D renderer for the layer. Takes ownership of the renderer.
New in version 3.0.
- Parameters
renderer (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
See also
See also
See also
-
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
- Parameters
shortName (str) –
-
setSubLayerVisibility
(self, name: str, visible: bool)¶ Set the visibility of the given sublayer name.
- Parameters
name (str) – sublayer name
visible (bool) – sublayer visibility
-
setTitle
(self, title: str)¶ Sets the title of the layer used by QGIS Server in GetCapabilities request.
See also
- Parameters
title (str) –
-
setTransformContext
(self, transformContext: QgsCoordinateTransformContext)¶ Sets the coordinate transform context to
transformContext
New in version 3.8.
- Parameters
transformContext (QgsCoordinateTransformContext) –
-
setValid
(self, valid: bool)¶ Sets whether layer is valid or not - should be used in constructor.
- Parameters
valid (bool) –
-
shortName
(self) → str¶ Returns the short name of the layer used by QGIS Server to identify the layer.
See also
- Return type
str
-
source
(self) → str¶ Returns the source for the layer. This source may contain usernames, passwords and other sensitive information.
See also
- Return type
str
-
statusChanged
¶ Emit a signal with status (e.g. to be caught by
QgisApp
and display a msg on status bar) [signal]- Parameters
status (str) –
-
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.
See also
New in version 2.16: [signal]
-
styleLoaded
¶ Emitted when a style has been loaded
- Parameters
categories (Union[QgsMapLayer.StyleCategories) – style categories
New in version 3.12: [signal]
-
styleManager
(self) → QgsMapLayerStyleManager¶ Gets access to the layer’s style manager. Style manager allows switching between multiple styles.
New in version 2.8.
- Return type
-
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
also()
-
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]
-
temporalProperties
(self) → QgsMapLayerTemporalProperties¶ Returns the layer’s temporal properties. This may be
None
, depending on the layer type.New in version 3.14.
- Return type
-
timerEvent
(self, QTimerEvent)¶
-
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
-
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.
New in version 3.8.
- Return type
-
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. IfdeferredUpdate
isTrue
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) → QgsMapLayerType¶ Returns the type of the layer.
- Return type
-
undoStack
(self) → QUndoStack¶ Returns pointer to layer’s undo stack
- Return type
QUndoStack
-
undoStackStyles
(self) → QUndoStack¶ Returns pointer to layer’s style undo stack
New in version 2.16.
- Return type
QUndoStack
-
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.
- Parameters
layerElement (QDomElement) –
document (QDomDocument) –
context (QgsReadWriteContext) –
categories (Union[QgsMapLayer.StyleCategories) –
-
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, context: QgsReadWriteContext, categories: Union[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 (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.
New 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, context: QgsReadWriteContext, categories: Union[QgsMapLayer.StyleCategories, QgsMapLayer.StyleCategory] = QgsMapLayer.AllStyleCategories) → bool¶ Write the style for the layer into the docment 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 (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
layer_node (QDomNode) –
document (QDomDocument) –
context (QgsReadWriteContext) –
- Return type
bool