ST_AsMVT — Aggregate function returning a Mapbox Vector Tile representation of a set of rows.
bytea ST_AsMVT(anyelement set row
bytea ST_AsMVT(anyelement row, text name
bytea ST_AsMVT(anyelement row, text name, integer extent
bytea ST_AsMVT(anyelement row, text name, integer extent, text geom_name
bytea ST_AsMVT(anyelement row, text name, integer extent, text geom_name, text feature_id_name
An aggregate function which returns a binary Mapbox Vector Tile representation of a set of rows corresponding to a tile layer. The rows should contain a geometry column which will be encoded as a feature geometry. The geometry should be in tile coordinate space and valid as per the MVT specification. ST_AsMVTGeom can be used to transform geometry into tile coordinate space. Other row columns are encoded as feature attributes.
The Mapbox Vector Tile format can store features with varying sets of attributes. To use this capability supply a JSONB column in the row data containing Json objects one level deep. The keys and values in the JSONB values will be encoded as feature attributes.
Tiles with multiple layers
can be created by concatenating multiple calls to this function using
Do not call with a
row row data with at least a geometry column.
name is the name of the layer. Default is the string "default".
extent is the tile extent in screen space as defined by the specification. Default is 4096.
geom_name is the name of the geometry column in the row data. Default is the first geometry column.
feature_id_name is the name of the Feature ID column in the row data. If NULL or negative the Feature ID is not set. The first column matching name and valid type (smallint, integer, bigint) will be used as Feature ID, and any subsequent column will be added as a property. JSON properties are not supported.
Enhanced: 3.0 - added support for Feature ID.
Enhanced: 2.5.0 - added support parallel query.
SELECT ST_AsMVT(q, 'test', 4096, 'geom') FROM (SELECT 1 AS c1, ST_AsMVTGeom( ST_GeomFromText('POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10), (20 30, 35 35, 30 20, 20 30))'), ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)), 4096, 0, false) AS geom) AS q; st_asmvt -------------------------------------------------------------------- \x1a320a0474657374121d1202000018032215095aa63f1a134631130a270f09280a121d0a14140f1a026331220228012880207802