Class: QgsVectorTileUtils

Utility functions for working with vector tiles.

Added in version 3.14.

Static Methods

checkXYZUrlTemplate

Checks whether the URL template string is correct (contains {x}, {y} / {-y}, {z} placeholders)

formatXYZUrlTemplate

Returns formatted tile URL string replacing {x}, {y}, {z} placeholders (or {-y} instead of {y} for TMS convention)

loadSprites

Downloads the sprite image and sets it to the conversion context

makeQgisFields

Returns QgsFields instance based on the set of field names

makeVectorLayerForTile

Returns a temporary vector layer for given sub-layer of tile in vector tile layer

scaleToZoom

Finds zoom level given map scale denominator.

scaleToZoomLevel

Finds the best fitting zoom level given a map scale denominator and allowed zoom level range.

sortTilesByDistanceFromCenter

Orders tile requests according to the distance from view center (given in tile matrix coords)

tilePolygon

Returns polygon (made by four corners of the tile) in screen coordinates

updateUriSources

Parses the style URL to update the source URLs in the uri.

class qgis.core.QgsVectorTileUtils[source]

Bases: object

static checkXYZUrlTemplate(url: str | None) bool[source]

Checks whether the URL template string is correct (contains {x}, {y} / {-y}, {z} placeholders)

Parameters:

url (Optional[str])

Return type:

bool

static formatXYZUrlTemplate(url: str | None, tile: QgsTileXYZ, tileMatrix: QgsTileMatrix) str[source]

Returns formatted tile URL string replacing {x}, {y}, {z} placeholders (or {-y} instead of {y} for TMS convention)

Parameters:
Return type:

str

static loadSprites(styleDefinition: Dict[str, Any], context: QgsMapBoxGlStyleConversionContext, styleUrl: str | None = '')[source]

Downloads the sprite image and sets it to the conversion context

Parameters:
  • styleDefinition (Dict[str, Any]) – the style definition map

  • context (QgsMapBoxGlStyleConversionContext) – the style conversion context

  • styleUrl (Optional[str] = '') – optional the style url

static makeQgisFields(flds: Iterable[str | None]) QgsFields[source]

Returns QgsFields instance based on the set of field names

Parameters:

flds (Iterable[Optional[str]])

Return type:

QgsFields

static makeVectorLayerForTile(mvt: QgsVectorTileLayer | None, tileID: QgsTileXYZ, layerName: str | None) QgsVectorLayer | None[source]

Returns a temporary vector layer for given sub-layer of tile in vector tile layer

Parameters:
Return type:

Optional[QgsVectorLayer]

static scaleToZoom(mapScale: float, z0Scale: float = 5.59082e+08) float[source]

Finds zoom level given map scale denominator.

The z0Scale argument gives the scale denominator at zoom level 0, where the default value corresponds to GoogleCRS84Quad tile matrix set

Added in version 3.16.

Parameters:
  • mapScale (float)

  • z0Scale (float = 5.59082e+08)

Return type:

float

static scaleToZoomLevel(mapScale: float, sourceMinZoom: int, sourceMaxZoom: int, z0Scale: float = 5.59082e+08) int[source]

Finds the best fitting zoom level given a map scale denominator and allowed zoom level range.

The z0Scale argument gives the scale denominator at zoom level 0, where the default value corresponds to GoogleCRS84Quad tile matrix set.

Parameters:
  • mapScale (float)

  • sourceMinZoom (int)

  • sourceMaxZoom (int)

  • z0Scale (float = 5.59082e+08)

Return type:

int

static sortTilesByDistanceFromCenter(tiles: Iterable[QgsTileXYZ], center: QPointF | QPoint)[source]

Orders tile requests according to the distance from view center (given in tile matrix coords)

Parameters:
  • tiles (Iterable[QgsTileXYZ])

  • center (Union[QPointF, QPoint])

static tilePolygon(id: QgsTileXYZ, ct: QgsCoordinateTransform, tm: QgsTileMatrix, mtp: QgsMapToPixel) QPolygon[source]

Returns polygon (made by four corners of the tile) in screen coordinates

Raises:

QgsCsException

Parameters:
Return type:

QPolygon

static updateUriSources(uri: str | None, forceUpdate: bool = False) str[source]

Parses the style URL to update the source URLs in the uri. If forceUpdate is True, any existing source will be updated.

Added in version 3.40.

Parameters:
  • uri (Optional[str])

  • forceUpdate (bool = False)

Return type:

str