How to use ST_AsMVT to serve MVT to web clients?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to use ST_AsMVT to serve MVT to web clients?

zimmicz
This post was updated on .
Hi,
I'm experimenting with the new 2.4.0 and ST_AsMVT, but I can't get my head around the way to send it to the web client (e. g. a leafet map). I have a

CREATE TABLE cadastre_area (
    code integer,
    name text,
    geom geometry(MULTIPOLYGON, 5514)
);

I'm running
SELECT ST_AsMVT('test', 4096, 'geom', q) FROM (SELECT code, name, geom FROM cadastre_area) q;
for testing purposes and getting
\x1aa5dbd0070a047465737412e216120400000101180322d7160987913f8db38e01aa59160e2a010412012a0624060e001410420a1a00203b0a3914190e15085912010a0f0c0f06370804080a0e0e0234090e0
as a result. What's the proper way to pass it down to the browser?

I use [apiary](http://private-43de6-postgismvt.apiary-mock.com/mvt) for testing, but I guess I'm missing the important step between ST_AsMVT and HTTP request :)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to use ST_AsMVT to serve MVT to web clients?

zimmicz
Moved a bit forward and got stuck with [ST_AsMVTGeom](https://postgis.net/docs/manual-dev/ST_AsMVTGeom.html).

All the tile queries sent to PostGIS looks like

SELECT
    name,
    ST_AsText(ST_AsMVTGeom(
        geom,
        ST_MakeBox2D(ST_Point(0, 0), ST_Point(4096, 4096)),
        4096,
        0,
        false
    )) geom
FROM cadastre_area
WHERE ST_Intersects(geom, (SELECT ST_Transform(ST_SetSRID(ST_MakeEnvelope(17.55615234375, 48.980216985374994, 17.578125, 48.99463598353408), 4326), 3857)))

I'm not really sure what the second argument stands for. The docs say "bounds is the geometric bounds of the tile contents without buffer." So are these the abstract coordinates of the tile space, or geographic ones (defined in 3857?).

The queries now pass just fine, but return the data shifted to the south of the map.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to use ST_AsMVT to serve MVT to web clients?

zimmicz
Loading...