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 intoQgsFeature
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
New in version 3.14.
QgsVectorTileLayer(path: str = ‘’, baseName: str = ‘’, options: QgsVectorTileLayer.LayerOptions = QgsVectorTileLayer.LayerOptions()) Constructs a new vector tile layer
Methods
Add error message
- rtype:
QgsVectorTileLayer
- param rendererContext:
- rtype:
QgsDataProvider
- param source:
- param source:
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.- rtype:
str
Invalidates the WGS84 extent.
Returns whether to render also borders of tiles (useful for debugging)
Returns currently assigned labeling
- rtype:
Tuple[str, bool]
- rtype:
Tuple[str, bool]
Read style data common to all layer types
Read custom properties from project file.
Read style manager's configuration (if any).
- param node:
- param layerNode:
Returns currently assigned renderer
Sets error message
Sets the extent
Sets labeling for the map layer.
Sets the
providerType
(provider key)Sets renderer for the map layer.
Sets whether to render also borders of tiles (useful for debugging)
- param transformContext:
Sets whether layer is valid or not
Returns maximum zoom level at which source has any valid tiles (negative = unconstrained)
Returns minimum zoom level at which source has any valid tiles (negative = unconstrained)
Returns URL/path of the data source (syntax different to each data source type)
Returns type of the data source
Write style data common to all layer types
Write custom properties to project file.
Write style manager's configuration (if exists).
- param node:
- param layerNode:
- class LayerOptions(transformContext: QgsCoordinateTransformContext = QgsCoordinateTransformContext())¶
Bases:
sip.wrapper
Constructor for LayerOptions with optional
transformContext
.QgsVectorTileLayer.LayerOptions(QgsVectorTileLayer.LayerOptions)
- transformContext¶
- appendError(self, error: QgsErrorMessage)¶
Add error message
- childEvent(self, QChildEvent)¶
- clone(self) QgsVectorTileLayer ¶
- Return type:
- connectNotify(self, QMetaMethod)¶
- createMapRenderer(self, rendererContext: QgsRenderContext) QgsMapLayerRenderer ¶
- Parameters:
rendererContext (QgsRenderContext) –
- Return type:
- customEvent(self, QEvent)¶
- dataProvider(self) QgsDataProvider ¶
- Return type:
- decodedSource(self, source: str, provider: str, context: QgsReadWriteContext) str ¶
- Parameters:
source (str) –
provider (str) –
context (QgsReadWriteContext) –
- Return type:
str
- disconnectNotify(self, QMetaMethod)¶
- encodedSource(self, source: str, context: QgsReadWriteContext) str ¶
- Parameters:
source (str) –
context (QgsReadWriteContext) –
- Return type:
str
- 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
- 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.
New in version 3.20.
- isSignalConnected(self, QMetaMethod) bool ¶
- isTileBorderRenderingEnabled(self) bool ¶
Returns whether to render also borders of tiles (useful for debugging)
- Return type:
bool
- labeling(self) QgsVectorTileLabeling ¶
Returns currently assigned labeling
- Return type:
- loadDefaultMetadata(self) Tuple[str, bool] ¶
- Return type:
Tuple[str, bool]
- loadDefaultStyle(self) Tuple[str, bool] ¶
- Return type:
Tuple[str, bool]
- readCommonStyle(self, layerElement: QDomElement, context: QgsReadWriteContext, categories: 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)
- 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: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories) bool ¶
- Parameters:
node (QDomNode) –
errorMessage (str) –
context (QgsReadWriteContext) –
categories (Union[QgsMapLayer.StyleCategories) –
- Return type:
bool
- readXml(self, layerNode: QDomNode, context: QgsReadWriteContext) bool ¶
- Parameters:
layerNode (QDomNode) –
context (QgsReadWriteContext) –
- Return type:
bool
- receivers(self, PYQT_SIGNAL) int ¶
- renderer(self) QgsVectorTileRenderer ¶
Returns currently assigned renderer
- Return type:
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setExtent(self, rect: QgsRectangle)¶
Sets the extent
- setLabeling(self, labeling: QgsVectorTileLabeling)¶
Sets labeling for the map layer.
Note
Takes ownership of the passed labeling
- Parameters:
labeling (QgsVectorTileLabeling) –
- setProviderType(self, providerType: str)¶
Sets the
providerType
(provider key)
- setRenderer(self, r: QgsVectorTileRenderer)¶
Sets renderer for the map layer.
Note
Takes ownership of the passed renderer
- Parameters:
r (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
- timerEvent(self, QTimerEvent)¶
- writeCommonStyle(self, layerElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext, categories: 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.
- 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: QgsMapLayer.StyleCategories | QgsMapLayer.StyleCategory = QgsMapLayer.AllStyleCategories) bool ¶
- Parameters:
node (QDomNode) –
doc (QDomDocument) –
errorMessage (str) –
context (QgsReadWriteContext) –
categories (Union[QgsMapLayer.StyleCategories) –
- Return type:
bool
- writeXml(self, layerNode: QDomNode, doc: QDomDocument, context: QgsReadWriteContext) bool ¶
- Parameters:
layerNode (QDomNode) –
doc (QDomDocument) –
context (QgsReadWriteContext) –
- Return type:
bool