[PostGIS] #6037: st_union with gridSize produces unexpected result

PostGIS trac at osgeo.org
Fri Jan 16 04:30:34 PST 2026


#6037: st_union with gridSize produces unexpected result
---------------------------+---------------------
 Reporter:  asgerpetersen  |      Owner:  pramsey
     Type:  defect         |     Status:  new
 Priority:  medium         |  Milestone:
Component:  postgis        |    Version:  3.6.x
 Keywords:                 |
---------------------------+---------------------
 `ST_Union(a, b, gridSize)` can return a polygon that is smaller than both
 input polygons, even when one polygon is `st_within` the other, the
 geometries are fully noded and all input coordinates lie on the specified
 grid.

 `ST_Union(a, b)` produces the expected result.

 The documentation does not clearly state what st_union with gridSize is
 supposed to do except snapping result vertices to a grid, but I think this
 result is unexpected and hard to reason about.

 {{{
 -- These polygons are fully noded and have cm precision (0.01). B is
 within A
 with geoms as (
 select ST_GeometryFromText('POLYGON ((450329.74 6273269.32, 450329.79
 6273269.33, 450330.65 6273269.56, 450331.07 6273269.67, 450380.84
 6273282.58, 450390.92 6273278.05, 450398.23 6273274.76, 450558.14
 6273202.85, 449681.36 6273101.1, 449997.83 6273183.21, 449997.84
 6273183.21, 450289.26 6273258.82, 450317.49 6273266.14, 450329.74
 6273269.32))', 25832) as a,
        ST_GeometryFromText('POLYGON ((450329.74 6273269.32, 450317.5
 6273266.14, 450317.49 6273266.14, 450329.74 6273269.32))', 25832) as b
 ),
 unions as (
         select
                 st_union(a,b) as st_union,
                 st_union(a,b, 0.01) as st_union_gridsize
         from geoms
 )
 select
         st_area(a) area_a,
         st_within(b, a), -- B is within A! So st_union(A, B) == A
         st_equals(a, st_union) a_equals_union, -- A == st_union(A,B)
         st_equals(a, st_union_gridsize) a_equals_union_gridsize, -- Not
 equal!
         st_area(st_union_gridsize) area_union_gridsize -- Note that the
 unioned area is smaller than the area of A alone
 from geoms, unions;
 }}}

 Tested on `POSTGIS="3.6.1 0" [EXTENSION] PGSQL="180"
 GEOS="3.13.1-CAPI-1.19.2" PROJ="9.6.0 NETWORK_ENABLED=OFF
 URL_ENDPOINT=https://cdn.proj.org
 USER_WRITABLE_DIRECTORY=/var/lib/postgresql/.local/share/proj
 DATABASE_PATH=/usr/share/proj/proj.db" (compiled against PROJ 9.6.0)
 LIBXML="2.13.9" LIBJSON="0.18" LIBPROTOBUF="1.5.2" WAGYU="0.5.0
 (Internal)"`
-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/6037>
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