2

I have been following a post here to create vector tiles direct from my database. My data is in WebMercator.

I am using the query:

SELECT ST_AsMVT(tile) FROM 
    (SELECT dh_id, 
        ST_AsMVTGeom(geom_go_mer, 
           ST_MakeEnvelope(%(xmin)s,%(ymin)s,%(xmax)s,%(ymax)s, 3857), 4036, 256, true) 
                AS geom FROM temp.buildings_google_mercator
                WHERE geom_go_mer && (SELECT ST_MakeEnvelope(%(xmin)s,%(ymin)s,%(xmax)s,%(ymax)s, 3857))
                ) AS tile

in Postgis 2.4.4 and parametising it with the webmercator coordinates calculated from the z,y,z tileschema (see here).

I get results, but as I zoom in, there are visibly more boundary disjoints. I looked at the resulting tiles, and it seems that the tiles are not calculated as I would expect.

Resulting Tiles

In this diagram, the pink is the original geometry, the purple and green are two different adjacent tiles. Not only is the resulting tile geometry different from the original, but adjacent tiles do not overlap at all - the line within the green polygon should overlap the line within the purple polygon below.

I am confused whether

  1. this is expected bahaviour for MVT
  2. a bug / feature in Postgis MVT, or
  3. something wrong with my interpretation of it.

I haven't seen bahaviour like this for other MVT maps, so I am not sure it's no. 1.

  • How do you plot you vector tiles? ST_AsMVTGeom postgis.net/docs/manual-dev/ST_AsMVTGeom.html is using by default a distance buffer of 256 units when if clips geometries. Clipped geometries go that 256 units beyond the xyz tile boundaries. MVT viewer should take care of that and overlap the clipped geometries by right amount but in your image it seems like the upper tile should be slided downwards to suit with the lower tile. – user30184 Nov 20 '18 at 19:28
  • this is from qgis, but ultimately I want to view them in openlayers. The same thing currently happens in openlayers too. – Stev_k Nov 20 '18 at 19:33
  • 1
    I am just guessing but it may be that ST_AsMVTGeom is now clipping data with 4096 units + 256 unit sized buffer but ST_AsMVT is compressing that data into 4096x4096 space. – user30184 Nov 20 '18 at 19:47
  • don't think its that as ST_AsMVTGeom(geom_go_mer, ST_MakeEnvelope(%(xmin)s,%(ymin)s,%(xmax)s,%(ymax)s, 3857), 4036, 0, false) has the same result – Stev_k Nov 20 '18 at 21:00
3

Whoops, sharp-eyed amongst you may have noticed that the size parameter above was 4036 not 4096 as it should be. That was causing the slight distortion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.