Introduced in: v26.7.0
Encodes a group of features into a binary Mapbox Vector Tile layer.
This is the aggregate counterpart of the scalar function MVTEncodeGeom. Each input row becomes one feature. The
geometry argument is a Geometry of tile-space coordinates, typically produced by MVTEncodeGeom; the optional
properties argument is a named tuple whose element names become the feature attribute keys and whose element types
determine the vector tile value types. Point, line and polygon geometry are supported.
The properties tuple must have explicit element names. Column aliases inside tuple(...) are not propagated to tuple
element names, so name the elements with a cast, for example tuple(count(), any(id))::Tuple(cluster_count UInt64, id String).
Identical property values are interned into the layer’s shared value pool, so the emitted tile does not duplicate them.
If feature_id_name is given, the named unsigned-integer property element is emitted as the MVT Feature id (a uint64)
and excluded from the tags; a NULL id is omitted for that feature.
The result is the raw bytes of a single-layer tile, which can be returned directly over the HTTP interface with
FORMAT RawBLOB. This function is the analogue of PostGIS ST_AsMVT.
Syntax
MVTEncode(layer_name[, extent[, feature_id_name[, stringify_unsupported]]])(geometry[, properties])Arguments
geometry— Tile-space geometry, e.g. fromMVTEncodeGeom.Geometryproperties— Optional named tuple of feature attributes. Element names become attribute keys.Tuple
Returned value
Returns the binary contents of a single-layer Mapbox Vector Tile. String
Examples
Encode a clustered tile of points
CREATE TABLE points (lon Float64, lat Float64) ENGINE = Memory;
INSERT INTO points VALUES (13.37, 52.52), (13.38, 52.51), (13.37, 52.52);
SELECT hex(MVTEncode('points')(geom, tuple(cluster_count)::Tuple(cluster_count UInt64))) AS tile
FROM
(
SELECT MVTEncodeGeom((lon, lat)::Point, 10, 550, 335) AS geom, count() AS cluster_count
FROM points
GROUP BY geom
)
SETTINGS allow_suspicious_types_in_group_by = 1;1A4278020A06706F696E7473120D180112020000220509E003EE37120D180112020001220509F801F0341A0D636C75737465725F636F756E742202280122022802288020