Opened 4 years ago

Closed 3 years ago

#4713 closed defect (fixed)

Degenerated polygons from ST_Difference

Reported by: José de Paula Rodrigues Neto Assis Owned by: pramsey
Priority: medium Milestone: PostGIS GEOS
Component: postgis Version: 3.0.x
Keywords: Cc: José de Paula Rodrigues Neto Assis

Description

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).

Attachments (4)

dump_teste_diff.backup (449.2 KB ) - added by José de Paula Rodrigues Neto Assis 4 years ago.
PostgreSQL 12.0 database dump of the bug data
polygon_table_a.png (126.2 KB ) - added by José de Paula Rodrigues Neto Assis 4 years ago.
Preview of Table A geometry
polygon_table_b.png (77.4 KB ) - added by José de Paula Rodrigues Neto Assis 4 years ago.
Preview of Table B geometry
result_st_difference_a_b.png (25.4 KB ) - added by José de Paula Rodrigues Neto Assis 4 years ago.
Preview of ST_Difference - this is the bug

Download all attachments as: .zip

Change History (7)

by José de Paula Rodrigues Neto Assis, 4 years ago

Attachment: dump_teste_diff.backup added

PostgreSQL 12.0 database dump of the bug data

by José de Paula Rodrigues Neto Assis, 4 years ago

Attachment: polygon_table_a.png added

Preview of Table A geometry

by José de Paula Rodrigues Neto Assis, 4 years ago

Attachment: polygon_table_b.png added

Preview of Table B geometry

by José de Paula Rodrigues Neto Assis, 4 years ago

Preview of ST_Difference - this is the bug

comment:1 by José de Paula Rodrigues Neto Assis, 4 years ago

Cc: José de Paula Rodrigues Neto Assis added

comment:2 by Algunenano, 4 years ago

Milestone: PostGIS 3.1.0PostGIS GEOS

comment:3 by pramsey, 3 years ago

Resolution: fixed
Status: newclosed

As of GEOS 3.9, the output is a valid polygon.

Note: See TracTickets for help on using tickets.