Class: QgsVectorTileLayer

class qgis.core.QgsVectorTileLayer

Bases: QgsMapLayer

Implements a map layer that is dedicated to rendering of vector tiles. Vector tiles compared to “ordinary” vector layers are pre-processed data optimized for fast rendering. A dataset is provided with a series of zoom levels for different map scales. Each zoom level has a matrix of tiles that contain actual data. A single vector tile may be a a file stored on a local drive, requested over HTTP request or retrieved from a database.

Content of a vector tile is divided into one or more named sub-layers. Each such sub-layer may contain many features which consist of geometry and attributes. Contrary to traditional vector layers, these sub-layers do not need to have a rigid schema where geometry type and attributes are the same for all features. A single sub-layer may have multiple geometry types in a single tile or have some attributes defined only at particular zoom levels.

Vector tile layer currently does not use the concept of data providers that other layer types use. The process of rendering of vector tiles looks like this:

+——–+ +——+ +———+ | DATA | | RAW | | DECODED | | | –> LOADER –> | | –> DECODER –> | | –> RENDERER | SOURCE | | TILE | | TILE | +——–+ +——+ +———+

Data source is a place from where tiles are fetched from (URL for HTTP access, local files, MBTiles file, GeoPackage file or others. Loader (QgsVectorTileLoader) class takes care of loading data from the data source. The “raw tile” data is just a blob (QByteArray) that is encoded in some way. There are multiple ways how vector tiles are encoded just like there are different formats how to store images. For example, tiles can be encoded using Mapbox Vector Tiles (MVT) format or in GeoJSON. Decoder (QgsVectorTileDecoder) takes care of decoding raw tile data into QgsFeature objects. A decoded tile is essentially an array of vector features for each sub-layer found in the tile - this is what vector tile renderer (QgsVectorTileRenderer) expects and does the map rendering.

To construct a vector tile layer, it is best to use QgsDataSourceUri class and set the following parameters to get a valid encoded URI:

  • “type” - what kind of data source will be used

  • “url” - URL or path of the data source (specific to each data source type, see below)

Currently supported data source types:

  • “xyz” - the “url” should be a template like http://example.com/{z}/{x}/{y}.pbf where {x},{y},{z} will be replaced by tile coordinates

  • “mbtiles” - tiles read from a MBTiles file (a SQLite database)

Currently supported decoders:

  • MVT - following Mapbox Vector Tiles specification

Added in version 3.14.

QgsVectorTileLayer(path: Optional[str] = ‘’, baseName: Optional[str] = ‘’, options: QgsVectorTileLayer.LayerOptions = QgsVectorTileLayer.LayerOptions()) Constructs a new vector tile layer

Methods

appendError

Add error message

childEvent

clone

rtype:

Optional[QgsVectorTileLayer]

connectNotify

createMapRenderer

param rendererContext:

customEvent

dataProvider

rtype:

Optional[QgsDataProvider]

decodedSource

param source:

disconnectNotify

encodedSource

param source:

hasDependencyCycle

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.

htmlMetadata

rtype:

str

invalidateWgs84Extent

Invalidates the WGS84 extent.

isSignalConnected

isTileBorderRenderingEnabled

Returns whether to render also borders of tiles (useful for debugging)

labeling

Returns currently assigned labeling

labelsEnabled

Returns whether the layer contains labels which are enabled and should be drawn.

loadDefaultMetadata

loadDefaultStyle

loadDefaultStyleAndSubLayers

Loads the default style for the layer, and returns True if the style was successfully loaded.

properties

rtype:

Qgis.MapLayerProperties

readCommonStyle

Read style data common to all layer types

readCustomProperties

Read custom properties from project file.

readStyleManager

Read style manager's configuration (if any).

readSymbology

param node:

readXml

param layerNode:

receivers

removeSelection

Clear selection

renderer

Returns currently assigned renderer

selectByGeometry

Selects features found within the search geometry (in layer's coordinates).

selectedFeatureCount

Returns the number of features that are selected in this layer.

selectedFeatures

Returns the list of features currently selected in the layer.

sender

senderSignalIndex

setError

Sets error message

setExtent

Sets the extent

setExtent3D

Sets the extent

setLabeling

Sets labeling for the map layer.

setLabelsEnabled

Sets whether labels should be enabled for the layer.

setProviderType

Sets the providerType (provider key)

setRenderer

Sets renderer for the map layer.

setTileBorderRenderingEnabled

Sets whether to render also borders of tiles (useful for debugging)

setTransformContext

param transformContext:

setValid

Sets whether layer is valid or not

sourceMaxZoom

Returns maximum zoom level at which source has any valid tiles (negative = unconstrained)

sourceMinZoom

Returns minimum zoom level at which source has any valid tiles (negative = unconstrained)

sourcePath

Returns URL/path of the data source (syntax different to each data source type)

sourceType

Returns type of the data source

tileMatrixSet

Returns the vector tile matrix set.

timerEvent

writeCommonStyle

Write style data common to all layer types

writeCustomProperties

Write custom properties to project file.

writeStyleManager

Write style manager's configuration (if exists).

writeSymbology

param node:

writeXml

param layerNode:

Signals

selectionChanged

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

class LayerOptions(transformContext: QgsCoordinateTransformContext = QgsCoordinateTransformContext())

Bases: sip.wrapper

Constructor for LayerOptions with optional transformContext.

QgsVectorTileLayer.LayerOptions(a0: QgsVectorTileLayer.LayerOptions)

transformContext
appendError(self, error: QgsErrorMessage)

Add error message

childEvent(self, a0: QChildEvent | None)
clone(self) QgsVectorTileLayer | None
Return type:

Optional[QgsVectorTileLayer]

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

rendererContext (QgsRenderContext)

Return type:

Optional[QgsMapLayerRenderer]

customEvent(self, a0: QEvent | None)
dataProvider(self) QgsDataProvider | None
Return type:

Optional[QgsDataProvider]

decodedSource(self, source: str | None, provider: str | None, context: QgsReadWriteContext) str
Parameters:
Return type:

str

disconnectNotify(self, signal: QMetaMethod)
encodedSource(self, source: str | None, context: QgsReadWriteContext) str
Parameters:
Return type:

str

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

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

Deprecated since version QGIS: 3.10

htmlMetadata(self) str
Return type:

str

invalidateWgs84Extent(self)

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

Added in version 3.20.

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

Returns whether to render also borders of tiles (useful for debugging)

Return type:

bool

labeling(self) QgsVectorTileLabeling | None

Returns currently assigned labeling

Return type:

Optional[QgsVectorTileLabeling]

labelsEnabled(self) bool

Returns whether the layer contains labels which are enabled and should be drawn.

Return type:

bool

Returns:

True if layer contains enabled labels

Added in version 3.34.

loadDefaultMetadata(self)
loadDefaultStyle(self)
loadDefaultStyleAndSubLayers(self, error: str | None, warnings: Iterable[str | None])

Loads the default style for the layer, and returns True if the style was successfully loaded. Also loads any sub layers (such as raster terrain layers) associated with the layer’s default style.

The error string will be filled with a translated error message if an error occurs during the style load. The warnings list will be populated with any warning messages generated during the style load (e.g. default style properties which could not be converted).

Ownership of the subLayers is transferrred to the caller.

Added in version 3.28.

Parameters:
  • error (Optional[str])

  • warnings (Iterable[Optional[str]]) -> (bool)

properties(self) Qgis.MapLayerProperties
Return type:

Qgis.MapLayerProperties

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

Read style data common to all layer types

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

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)

readStyleManager(self, layerNode: QDomNode)

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

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

bool

readXml(self, layerNode: QDomNode, context: QgsReadWriteContext) bool
Parameters:
Return type:

bool

receivers(self, signal: PYQT_SIGNAL) int
removeSelection(self)

Clear selection

Added in version 3.28.

renderer(self) QgsVectorTileRenderer | None

Returns currently assigned renderer

Return type:

Optional[QgsVectorTileRenderer]

selectByGeometry(self, geometry: QgsGeometry, context: QgsSelectionContext, behavior: Qgis.SelectBehavior = Qgis.SelectBehavior.SetSelection, relationship: Qgis.SelectGeometryRelationship = Qgis.SelectGeometryRelationship.Intersect, flags: Qgis.SelectionFlags | Qgis.SelectionFlag = Qgis.SelectionFlags(), renderContext: QgsRenderContext | None = None)

Selects features found within the search geometry (in layer’s coordinates).

A render context can optionally be specified in order to avoid selecting features which are not currently rendered.

Added in version 3.28.

Parameters:
selectedFeatureCount(self) int

Returns the number of features that are selected in this layer.

Added in version 3.28.

Return type:

int

selectedFeatures(self) List[QgsFeature]

Returns the list of features currently selected in the layer.

Added in version 3.28.

Return type:

List[QgsFeature]

selectionChanged

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

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

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

sender(self) QObject | None
senderSignalIndex(self) int
setError(self, error: QgsError)

Sets error message

setExtent(self, rect: QgsRectangle)

Sets the extent

setExtent3D(self, box: QgsBox3D)

Sets the extent

Added in version 3.36.

setLabeling(self, labeling: QgsVectorTileLabeling | None)

Sets labeling for the map layer.

Note

Takes ownership of the passed labeling

Parameters:

labeling (Optional[QgsVectorTileLabeling])

setLabelsEnabled(self, enabled: bool)

Sets whether labels should be enabled for the layer.

Note

Labels will only be rendered if labelsEnabled() is True and a labeling object is returned by labeling().

See also

labelsEnabled()

See also

labeling()

Added in version 3.34.

Parameters:

enabled (bool)

setProviderType(self, providerType: str | None)

Sets the providerType (provider key)

setRenderer(self, r: QgsVectorTileRenderer | None)

Sets renderer for the map layer.

Note

Takes ownership of the passed renderer

Parameters:

r (Optional[QgsVectorTileRenderer])

setTileBorderRenderingEnabled(self, enabled: bool)

Sets whether to render also borders of tiles (useful for debugging)

Parameters:

enabled (bool)

setTransformContext(self, transformContext: QgsCoordinateTransformContext)
Parameters:

transformContext (QgsCoordinateTransformContext)

setValid(self, valid: bool)

Sets whether layer is valid or not

sourceMaxZoom(self) int

Returns maximum zoom level at which source has any valid tiles (negative = unconstrained)

Return type:

int

sourceMinZoom(self) int

Returns minimum zoom level at which source has any valid tiles (negative = unconstrained)

Return type:

int

sourcePath(self) str

Returns URL/path of the data source (syntax different to each data source type)

Return type:

str

sourceType(self) str

Returns type of the data source

Return type:

str

tileMatrixSet(self) QgsVectorTileMatrixSet

Returns the vector tile matrix set.

Added in version 3.22.6.

Return type:

QgsVectorTileMatrixSet

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

Write style data common to all layer types

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

Write custom properties to project file.

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 | None, context: QgsReadWriteContext, categories: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories) bool
Parameters:
Return type:

bool

writeXml(self, layerNode: QDomNode, doc: QDomDocument, context: QgsReadWriteContext) bool
Parameters:
Return type:

bool