[postgis-tickets] [PostGIS] #5382: ST_AsMVTGeom output is snapped to grid incorrectly
PostGIS
trac at osgeo.org
Tue May 16 08:13:28 PDT 2023
#5382: ST_AsMVTGeom output is snapped to grid incorrectly
---------------------+---------------------------
Reporter: mknycha | Owner: pramsey
Type: defect | Status: new
Priority: medium | Milestone: PostGIS 3.3.3
Component: postgis | Version: 3.3.x
Keywords: |
---------------------+---------------------------
Steps to replicate:
- Run:
{{{#!sql
SELECT ST_AsText(ST_AsMVTGeom(
ST_GeomFromText('POLYGON((0 0, 4 0, 6 6, -1 5, 0 0))'),
ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
20, 0, true));
}}}
Actual output:
{{{
POLYGON((12 8,8 20,0 20,0 9,12 8))
}}}
Expected output:
{{{
POLYGON((12 8,8 20,0 20,0 10,12 8))
}}}
Explanation:
They way I understand ST_AsMVTGeom works, is that after the transformation
and clipping, it snaps the output to the grid of integer points. The
problem is, that is does not round the integer coordinates correctly.
For example, the output for:
{{{
SELECT ST_AsText(ST_AsMVTGeom(
ST_GeomFromText('POLYGON((0 0, 4 0, 6 6, -3 5, 0 0))'),
ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
20, 0, false));
st_astext
--------------------------------------
POLYGON((12 8,8 20,0 20,-6 10,12 8))
(1 row)
}}}
Comparing to the clipped output:
{{{
SELECT ST_AsText(ST_AsMVTGeom(
ST_GeomFromText('POLYGON((0 0, 4 0, 6 6, -3 5, 0 0))'),
ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
20, 0, true));
st_astext
------------------------------------
POLYGON((12 8,8 20,0 20,0 9,12 8))
(1 row)
}}}
makes sense, because looking at the bottom edge of the unclipped output,
after clipping by the bounding box the bottom left corner should be closer
to (0 9) than (0 10).
Outputs comparison (orange unclipped, red clipped):
[[Image(https://i.ibb.co/Gk5Qccn/Screenshot-2023-05-16-at-16-53-39.png)]]
But consider what happens for another output:
{{{
SELECT ST_AsText(ST_AsMVTGeom(
ST_GeomFromText('POLYGON((0 0, 4 0, 6 6, -1 5, 0 0))'),
ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
20, 0, false));
st_astext
--------------------------------------
POLYGON((12 8,8 20,0 20,-2 10,12 8))
(1 row)
}}}
Comparing to the clipped one:
{{{
SELECT ST_AsText(ST_AsMVTGeom(
ST_GeomFromText('POLYGON((0 0, 4 0, 6 6, -1 5, 0 0))'),
ST_MakeBox2D(ST_Point(0, 0), ST_Point(10, 10)),
20, 0, true));
st_astext
------------------------------------
POLYGON((12 8,8 20,0 20,0 9,12 8))
(1 row)
}}}
Now, after clipping and before snap to grid, the left bottom corner should
be closer to (0 10). That's why I think the output polygon should contain
(0 10), instead of (0 9).
Image with outputs comparison (orange unclipped, red clipped):
[[Image(https://i.ibb.co/xs2dWH8/Screenshot-2023-05-16-at-17-07-02.png)]]
Hopefully I got that right, thanks for your open source project
--
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5382>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.
More information about the postgis-tickets
mailing list