Class: QgsVectorTileWriter¶
- class qgis.core.QgsVectorTileWriter¶
Bases:
sip.wrapper
Takes care of writing vector tiles. The intended use is to set up the class by setting the destination URI, extent, zoom level range and input vector layers. Then with a call to
writeTiles()
the data gets written. In case of a failure,errorMessage()
returns the cause of the problem during writing.The syntax of destination URIs is the same like the data source string used by vector tile layers: parameters are encoded as a HTTP query string, where “type” key determines the type of the destination container, the “url” key is normally the path. Currently supported types:
“xyz” - tile data written as local files, using a template where {x},{y},{z} are replaced by the actual tile column, row and zoom level numbers, e.g.: file:///home/qgis/tiles/{z}/{x}/{y}.pbf
“mbtiles” - tile data written to a new MBTiles file, the “url” key should be ordinary file system path, e.g.: /home/qgis/output.mbtiles
Currently the writer only support MVT encoding of data.
Metadata support: it is possible to pass a QVariantMap with metadata. This is backend dependent. Currently only “mbtiles” source type supports writing of metadata. The key-value pairs will be written to the “metadata” table in the MBTiles file. Some useful metadata keys listed here, but see MBTiles spec for more details:
“name” - human-readable name of the tileset
“bounds” - extent in WGS 84: “minlon,minlat,maxlon,maxlat”
“center” - default view of the map: “longitude,latitude,zoomlevel”
“minzoom” - lowest zoom level
“maxzoom” - highest zoom level
“attribution” - string that explains the sources of data
“description” - descriptions of the content
“type” - whether this is an overlay or a basemap
“version” - version of the tileset
Vector tile writer always writes “format” and “json” metadata. If not specified in metadata by the client, tile writer also writes “name”, “bounds”, “minzoom” and “maxzoom”.
New in version 3.14:
Methods
Returns error message related to the previous call to
writeTiles()
.Returns calculated extent that combines extent of all input layers
Sets where and how the vector tiles will be written.
Sets extent of vector tile output.
Sets vector layers and their configuration for output of vector tiles
Sets the maximum zoom level of tiles.
Sets that will be written to the output dataset.
Sets the minimum zoom level of tiles.
Sets coordinate transform context for transforms between layers and tile matrix CRS
Writes vector tiles according to the configuration.
- class Layer(layer: QgsVectorLayer)¶
Bases:
sip.wrapper
Constructs an entry for a vector layer
QgsVectorTileWriter.Layer(QgsVectorTileWriter.Layer)
Configuration of a single input vector layer to be included in the output
New in version 3.14.
- filterExpression(self) str ¶
Returns filter expression. If not empty, only features matching the expression will be used
- Return type
str
- layer(self) QgsVectorLayer ¶
Returns vector layer of this entry
- Return type
- layerName(self) str ¶
Returns layer name in the output. If not set,
layer()
->:py:func:~Layer.name will be used.- Return type
str
- maxZoom(self) int ¶
Returns maximum zoom level at which this layer will be used. Negative value means no max. zoom level
- Return type
int
- minZoom(self) int ¶
Returns minimum zoom level at which this layer will be used. Negative value means no min. zoom level
- Return type
int
- setFilterExpression(self, expr: str)¶
Sets filter expression. If not empty, only features matching the expression will be used
- Parameters
expr (str) –
- setLayerName(self, name: str)¶
Sets layer name in the output. If not set,
layer()
->:py:func:~Layer.name will be used.- Parameters
name (str) –
- setMaxZoom(self, maxzoom: int)¶
Sets maximum zoom level at which this layer will be used. Negative value means no max. zoom level
- Parameters
maxzoom (int) –
- setMinZoom(self, minzoom: int)¶
Sets minimum zoom level at which this layer will be used. Negative value means no min. zoom level
- Parameters
minzoom (int) –
- errorMessage(self) str ¶
Returns error message related to the previous call to
writeTiles()
. Will return an empty string if writing was successful.- Return type
str
- fullExtent(self) QgsRectangle ¶
Returns calculated extent that combines extent of all input layers
- Return type
- setDestinationUri(self, uri: str)¶
Sets where and how the vector tiles will be written. See the class description about the syntax of destination URIs.
- Parameters
uri (str) –
- setExtent(self, extent: QgsRectangle)¶
Sets extent of vector tile output. Currently always in EPSG:3857. If unset, it will use the full extent of all input layers combined
- Parameters
extent (QgsRectangle) –
- setLayers(self, layers: Iterable[QgsVectorTileWriter.Layer])¶
Sets vector layers and their configuration for output of vector tiles
- Parameters
layers (Iterable[QgsVectorTileWriter.Layer]) –
- setMaxZoom(self, maxZoom: int)¶
Sets the maximum zoom level of tiles. Allowed values are in interval [0,24]
- Parameters
maxZoom (int) –
- setMetadata(self, metadata: Dict[str, Any])¶
Sets that will be written to the output dataset. See class description for more on metadata support
- Parameters
metadata (Dict[str) –
- setMinZoom(self, minZoom: int)¶
Sets the minimum zoom level of tiles. Allowed values are in interval [0,24]
- Parameters
minZoom (int) –
- setTransformContext(self, transformContext: QgsCoordinateTransformContext)¶
Sets coordinate transform context for transforms between layers and tile matrix CRS
- Parameters
transformContext (QgsCoordinateTransformContext) –
- writeTiles(self, feedback: QgsFeedback = None) bool ¶
Writes vector tiles according to the configuration. Returns
True
on success (upon failure one can get error cause usingerrorMessage()
)If a pointer to a feedback object is provided, it can be used to track progress or provide cancellation functionality.
- Parameters
feedback (
QgsFeedback
= None) –- Return type
bool