<div dir="ltr">As a continuation of my work with ST_AsGeobuf (1) I've started work on St_AsMVT (2), which is a function intended to output a Mapbox Vector Tile (3).<div><br><div>A feature of Mapbox Vector Tiles are that they can contain several layers of data within a tile, typically corresponding to a separate source schema. So I'm thinking about how to specify the parameters to ST_AsMVT to support fetching the data for a tile and this is my initial proposal:</div><div><br></div><div>CREATE FUNCTION ST_AsMVT(query text, extent <span style="color:rgb(46,46,46);font-family:"lucida grande",verdana,geneva,arial,helvetica,sans-serif;font-size:13.3333px">box2d, resolution double, buffer integer, pixelratio integer</span>)</div><div><br></div><div>The query parameter is expected to produce rows with a specific schema like follows:</div><div><br></div><div>CREATE TABLE output</div><div>(</div><div>  layer text,</div><div>  id bigint,</div><div>  geom geometry,</div><div>  attributes json</div><div>)</div><div><br></div><div>The above schema would allow unioning data from multiple tables with differing attributes (represented using the json datatype, alternatively it could be a hstore?). Note that it's up the the query to include geometries to be considered (usually extent + buffer * resolution).</div><div><br></div><div>The extent parameter defines the geographic extent to be visible within the tile (i.e does not include buffer).</div><div><br></div><div>The resolution parameter defines units per pixel used to translate geometric coordinates into tile coordinates.</div><div><br></div><div>The buffer parameter defines how many pixels should be included outside visible tile coordinates until clipping the geometry. This is used to avoid border rendering artifacts.</div><div><br></div><div>The pixelratio parameter optionally multiplies tile coordinate space to support hdpi displays. Default should probably be 1.</div><div><br></div><div>1) <a href="https://git.osgeo.org/gogs/postgis/postgis/pulls/4">https://git.osgeo.org/gogs/postgis/postgis/pulls/4</a></div><div>2) <a href="https://git.osgeo.org/gogs/postgis/postgis/pulls/5">https://git.osgeo.org/gogs/postgis/postgis/pulls/5</a></div><div>3) <a href="https://www.mapbox.com/vector-tiles/specification">https://www.mapbox.com/vector-tiles/specification</a></div><div><br></div><div>/Björn</div></div></div>