skip to Main Content

I am implementing a Tile Server with the help of PostGIS.

Running this query:

                SELECT ST_AsMVT(tile) FROM (
                  SELECT
                    __FEATURES__,
                    ST_AsMVTGeom(
                      ST_Transform(__GEOM__, __SRID__),
                      ST_Transform(ST_TileEnvelope(?, ?, ?), __SRID__),
                      4096,
                      256,
                      false
                    ) as geom
                  FROM __SCHEMA__.__TABLE__
                    WHERE
                    __GEOM__ && ST_Transform(ST_TileEnvelope(?, ?, ?), __SRID__)
                ) AS tile 

In 3857 projection I get a very good result.

But if I use geometries in 32632 I get the borders of the geometries not perfectly aligned and a zig-zag effect.

Why?

2

Answers


  1. Chosen as BEST ANSWER

    I was able to solve the issue with this query:

                    SELECT ST_AsMVT(tile) FROM (
                      SELECT
                        __FEATURES__,
                        ST_Transform(ST_AsMVTGeom(
                          ST_Transform(__GEOM__, __PROJ__ __SRID__),
                          ST_Transform(ST_TileEnvelope(?, ?, ?), __PROJ__ __SRID__),
                          4096,
                          512,
                          false
                        ), __PROJ__ __SRID__) as geom
                      FROM __SCHEMA__.__TABLE__
                        WHERE
                        -- Bounding box condition
                        ST_Transform(__GEOM__, __PROJ__ __SRID__) && ST_Transform(ST_TileEnvelope(?, ?, ?), __PROJ__ __SRID__)
                    ) AS tile
    

    Where __PROJ__, is +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs


  2. The coordinate precision, grid alignment, or tile settings in EPSG 32632 could be the cause of the misalignment and zigzag effect. Make sure there is enough accuracy, line up the tile grid with the UTM grid, experiment with the tile size and buffer, and confirm the grid origin. For debugging purposes, visualize the tiles and data. Your PostGIS tile server’s alignment should get better after adjusting these factors.

    here is the piece of code in which values shou

    ST_AsMVTGeom(
       ST_Transform(__GEOM__, __SRID__),
       ST_Transform(ST_TileEnvelope(?, ?, ?), __SRID__),
       4096,
       256,
       false
    ) as geomld be changed. 
    

    The 4096 and 256 parameters may require modification according to your particular use case and data distribution.

    Hope it works 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search