Class: QgsMapLayerUtils¶
- class qgis.core.QgsMapLayerUtils¶
Bases:
sip.wrapper
Contains utility functions for working with map layers.
New in version 3.20:
Methods
Returns the combined extent of a list of
layers
.Creates and returns the (possibly
None
) database connection for alayer
.Returns
True
if the source of the specifiedlayer
matches the givenpath
.Sorts a list of map
layers
by their layer type, respecting theorder
of types specified.Updates a
layer
's data source, replacing its data source with a path referring tonewPath
.- combinedExtent(layers: Iterable[QgsMapLayer], crs: QgsCoordinateReferenceSystem, transformContext: QgsCoordinateTransformContext) QgsRectangle ¶
Returns the combined extent of a list of
layers
.The
crs
argument specifies the desired coordinate reference system for the combined extent.- Parameters
layers (Iterable[QgsMapLayer]) –
crs (QgsCoordinateReferenceSystem) –
transformContext (QgsCoordinateTransformContext) –
- Return type
- databaseConnection(layer: QgsMapLayer) QgsAbstractDatabaseProviderConnection ¶
Creates and returns the (possibly
None
) database connection for alayer
. Ownership is transferred to the caller.New in version 3.22.
- Parameters
layer (QgsMapLayer) –
- Return type
- layerSourceMatchesPath(layer: QgsMapLayer, path: str) bool ¶
Returns
True
if the source of the specifiedlayer
matches the givenpath
.This method can be used to test whether a layer is associated with a file path.
New in version 3.22.
- Parameters
layer (QgsMapLayer) –
path (str) –
- Return type
bool
- sortLayersByType(layers: Iterable[QgsMapLayer], order: Iterable[QgsMapLayerType]) List[QgsMapLayer] ¶
Sorts a list of map
layers
by their layer type, respecting theorder
of types specified.Layer types which appear earlier in the
order
list will result in matching layers appearing earlier in the result list.New in version 3.26.
- Parameters
layers (Iterable[QgsMapLayer]) –
order (Iterable[QgsMapLayerType]) –
- Return type
List[QgsMapLayer]
- updateLayerSourcePath(layer: QgsMapLayer, newPath: str) bool ¶
Updates a
layer
’s data source, replacing its data source with a path referring tonewPath
.Returns
True
if the layer was updated, orFalse
if the layer was not updated (e.g. it uses a data provider which does not specify paths in a layer URI.New in version 3.22.
- Parameters
layer (QgsMapLayer) –
newPath (str) –
- Return type
bool