QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
QgsVectorTileWriter Class Reference

Takes care of writing vector tiles. More...

#include <qgsvectortilewriter.h>

Classes

class  Layer
 Configuration of a single input vector layer to be included in the output. More...
 

Public Member Functions

 QgsVectorTileWriter ()
 
QString errorMessage () const
 Returns error message related to the previous call to writeTiles().
 
QgsRectangle fullExtent () const
 Returns calculated extent that combines extent of all input layers.
 
void setDestinationUri (const QString &uri)
 Sets where and how the vector tiles will be written.
 
void setExtent (const QgsRectangle &extent)
 Sets extent of vector tile output.
 
void setLayers (const QList< QgsVectorTileWriter::Layer > &layers)
 Sets vector layers and their configuration for output of vector tiles.
 
void setMaxZoom (int maxZoom)
 Sets the maximum zoom level of tiles. Allowed values are in interval [0,24].
 
void setMetadata (const QVariantMap &metadata)
 Sets that will be written to the output dataset. See class description for more on metadata support.
 
void setMinZoom (int minZoom)
 Sets the minimum zoom level of tiles. Allowed values are in interval [0,24].
 
bool setRootTileMatrix (const QgsTileMatrix &tileMatrix)
 Sets zoom level 0 tile matrix.
 
void setTransformContext (const QgsCoordinateTransformContext &transformContext)
 Sets coordinate transform context for transforms between layers and tile matrix CRS.
 
QByteArray writeSingleTile (QgsTileXYZ tileID, QgsFeedback *feedback=nullptr, int buffer=256, int resolution=4096) const
 Encodes single MVT tile.
 
bool writeTiles (QgsFeedback *feedback=nullptr)
 Writes vector tiles according to the configuration.
 

Detailed Description

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:

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:

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".

Since
QGIS 3.14

Definition at line 76 of file qgsvectortilewriter.h.

Constructor & Destructor Documentation

◆ QgsVectorTileWriter()

QgsVectorTileWriter::QgsVectorTileWriter ( )

Definition at line 37 of file qgsvectortilewriter.cpp.

Member Function Documentation

◆ errorMessage()

QString QgsVectorTileWriter::errorMessage ( ) const
inline

Returns error message related to the previous call to writeTiles().

Will return an empty string if writing was successful.

Definition at line 172 of file qgsvectortilewriter.h.

◆ fullExtent()

QgsRectangle QgsVectorTileWriter::fullExtent ( ) const

Returns calculated extent that combines extent of all input layers.

Definition at line 232 of file qgsvectortilewriter.cpp.

◆ setDestinationUri()

void QgsVectorTileWriter::setDestinationUri ( const QString &  uri)
inline

Sets where and how the vector tiles will be written.

See the class description about the syntax of destination URIs.

Definition at line 132 of file qgsvectortilewriter.h.

◆ setExtent()

void QgsVectorTileWriter::setExtent ( const QgsRectangle extent)
inline

Sets extent of vector tile output.

If unset, it will use the full extent of all input layers combined

Definition at line 138 of file qgsvectortilewriter.h.

◆ setLayers()

void QgsVectorTileWriter::setLayers ( const QList< QgsVectorTileWriter::Layer > &  layers)
inline

Sets vector layers and their configuration for output of vector tiles.

Definition at line 146 of file qgsvectortilewriter.h.

◆ setMaxZoom()

void QgsVectorTileWriter::setMaxZoom ( int  maxZoom)
inline

Sets the maximum zoom level of tiles. Allowed values are in interval [0,24].

Definition at line 143 of file qgsvectortilewriter.h.

◆ setMetadata()

void QgsVectorTileWriter::setMetadata ( const QVariantMap &  metadata)
inline

Sets that will be written to the output dataset. See class description for more on metadata support.

Definition at line 149 of file qgsvectortilewriter.h.

◆ setMinZoom()

void QgsVectorTileWriter::setMinZoom ( int  minZoom)
inline

Sets the minimum zoom level of tiles. Allowed values are in interval [0,24].

Definition at line 141 of file qgsvectortilewriter.h.

◆ setRootTileMatrix()

bool QgsVectorTileWriter::setRootTileMatrix ( const QgsTileMatrix tileMatrix)

Sets zoom level 0 tile matrix.

Definition at line 43 of file qgsvectortilewriter.cpp.

◆ setTransformContext()

void QgsVectorTileWriter::setTransformContext ( const QgsCoordinateTransformContext transformContext)
inline

Sets coordinate transform context for transforms between layers and tile matrix CRS.

Definition at line 152 of file qgsvectortilewriter.h.

◆ writeSingleTile()

QByteArray QgsVectorTileWriter::writeSingleTile ( QgsTileXYZ  tileID,
QgsFeedback feedback = nullptr,
int  buffer = 256,
int  resolution = 4096 
) const

Encodes single MVT tile.

Parameters
tileIDTile identifier
feedbackoptional, provide cancellation functionality
resolutionthe resolution of coordinates of geometries within the tile. The default is 4096
buffersize of the buffer zone around tile edges in integer tile coordinates. The default is 256 (~6%)

Returns a QByteArray with the encoded data

Since
QGIS 3.22

Definition at line 317 of file qgsvectortilewriter.cpp.

◆ writeTiles()

bool QgsVectorTileWriter::writeTiles ( QgsFeedback feedback = nullptr)

Writes vector tiles according to the configuration.

Returns true on success (upon failure one can get error cause using errorMessage())

If a pointer to a feedback object is provided, it can be used to track progress or provide cancellation functionality.

Definition at line 54 of file qgsvectortilewriter.cpp.


The documentation for this class was generated from the following files: