Opened 4 days ago

Last modified 45 hours ago

#5758 new defect

Documentation bug in SQL query example for ST_AsMVTGeom

Reported by: azakh Owned by: robe
Priority: medium Milestone: PostGIS 3.4.3
Component: documentation Version: 3.4.x
Keywords: MVT, ST_AsMVTGeom Cc:

Description

Currently:

SELECT ST_AsMVTGeom(
            ST_Transform( geom, 3857 ),
            ST_TileEnvelope(12, 513, 412), extent => 4096, buffer => 64) AS geom
  FROM data
  WHERE geom && ST_TileEnvelope(12, 513, 412, margin => (64.0 / 4096))

Should be:

SELECT ST_AsMVTGeom(
            ST_Transform( geom, 3857 ),
            ST_TileEnvelope(12, 513, 412), extent => 4096, buffer => 64) AS geom
  FROM data
  WHERE ST_Transform(geom, 3857) && ST_TileEnvelope(12, 513, 412, margin => (64.0 / 4096))

Namely, the geom column should be transformed both in SELECT and WHERE clauses.

Related issue: https://trac.osgeo.org/postgis/ticket/5198

Change History (1)

comment:1 by robe, 45 hours ago

I think it's better to transform the ST_TileEnvelope rather than the geom, cause otherwise no index would be used unless there is a functional index on the ST_Transform(geom,3857)

-- this assumes the geom has a 4326 srid
SELECT ST_AsMVTGeom(
            ST_Transform( geom, 3857 ),
            ST_TileEnvelope(12, 513, 412), extent => 4096, buffer => 64) AS geom
  FROM data
  WHERE geom && ST_Transform(ST_TileEnvelope(12, 513, 412, margin => (64.0 / 4096)),4326)

@pramsey @mdavis - you agree?

Note: See TracTickets for help on using tickets.