[postgis-tickets] [PostGIS] #4713: Degenerated polygons from ST_Difference

PostGIS trac at osgeo.org
Thu Jul 2 21:03:35 PDT 2020


#4713: Degenerated polygons from ST_Difference
-----------------------+---------------------------
 Reporter:  espinafre  |      Owner:  pramsey
     Type:  defect     |     Status:  new
 Priority:  medium     |  Milestone:  PostGIS 3.1.0
Component:  postgis    |    Version:  3.0.x
 Keywords:             |
-----------------------+---------------------------
 When trying to do a ST_Difference between two fairly complex
 MultiPolygons, the result is a MultiPolygon composed of rectangles and
 triangles, looking like overly simplified shapes.

 * Database version: PostgreSQL 12.3
 * OS/Architecture: Gentoo Linux, AMD64 (also reproduced with CentOS 8/PGDG
 repo)
 * PostGIS version: 3.0.1
 * GEOS version: 3.8.1
 * GDAL version: 3.1.0
 * PROJ version: 7.0.1
 The table definitions are as follows:

 {{{
 CREATE TABLE tb_test_a
 (
     id integer PRIMARY KEY,
     geom geometry(MultiPolygon,4674)
 );
 CREATE TABLE tb_test_b
 (
     id integer PRIMARY KEY,
     geom geometry(MultiPolygon,4674)
 );
 }}}

 They have a single record each, with a different geometry in each case,
 which I'm attaching to this report; they are both ST_Valid()
 MultiPolygons.

 This is what generates the degenerated polygons:
 {{{
 SELECT
         ST_Difference(a.geom, b.geom) geom
 FROM
         tb_test_a a,
         tb_test_b b
 }}}

 If I wrap both geometries with ST_MakeValid(ST_SnapToGrid()), I get the
 expected results:

 {{{
 SELECT
         ST_Difference(
                 ST_MakeValid(ST_SnapToGrid(a.geom, 0.0000000001)),
                 ST_MakeValid(ST_SnapToGrid(b.geom, 0.0000000001)) ) geom
 FROM
         tb_test_a a,
         tb_test_b b
 }}}

 I have to make ST_MakeValid after snapping because of self-intersection
 errors.

 I've also seen cases of ST_Intersection failing the same way (generating
 too simplified results) with similarly complex source MultiPolygons (but
 not with the attached data).

-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/4713>
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