Opened 12 months ago

Closed 7 months ago

Last modified 4 months ago

#5390 closed defect (fixed)

TopologyException: side location conflict on ST_IsValid-geometry

Reported by: tjay Owned by: pramsey
Priority: medium Milestone: PostGIS GEOS
Component: postgis Version: 3.1.x
Keywords: Cc:

Description

Hi,

is there a safe way to perform ST_Intersects on the OGC-Valid-geometry in the following example, without raising the GEOSIntersects/TopologyException or altering the geometry?

DO $$
  DECLARE geom_a geometry := 'POLYGON((335645.7810000004 5677846.65,335648.6579999998 5677845.801999999,335650.8630842535 5677845.143617179,335650.77673334075 5677844.7250704905,335642.90299999993 5677847.498,335645.7810000004 5677846.65))'::geometry;
  DECLARE geom_b geometry := 'POLYGON((335642.903 5677847.498,335642.894 5677847.459,335645.92 5677846.69,335647.378 5677852.523,335644.403 5677853.285,335644.374 5677853.293,335642.903 5677847.498))'::geometry;
BEGIN
  IF NOT ST_IsValid(geom_a) OR NOT ST_IsValid(geom_b) THEN
    RAISE EXCEPTION 'geom_a / geom_b are not valid';
  END IF;
  PERFORM ST_Intersects(geom_a,geom_b);
END $$;

FEHLER:  GEOSIntersects: TopologyException: side location conflict at 335642.90299999999 5677847.4979999997. This can occur if the input geometry is invalid.
KONTEXT:  SQL-Anweisung »SELECT st_intersects(geom_a,geom_b)«
PL/pgSQL-Funktion inline_code_block Zeile 8 bei PERFORM

SELECT postgis_full_version();
                                                                        postgis_full_version
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="3.1.8 c5ebc1f" [EXTENSION] PGSQL="120" GEOS="3.11.2-CAPI-1.17.2" PROJ="9.2.0" LIBXML="2.9.7" LIBJSON="0.13.1" LIBPROTOBUF="1.3.0" WAGYU="0.5.0 (Internal)"
(1 row)

Change History (5)

comment:1 by mdavis, 12 months ago

GEOS 3.12 (the next release) contains a fix for this problem.

A party-effective workaround for this is to compute the intersects on the boundary (ST_Boundary) of each geometry instead. This works as long as one geometry is not wholly contained in the other. To handle that case (if needed) you could also test for intersection of one point of each geometry against the other.

SELECT ST_Intersects(
  ST_Boundary('POLYGON ((335645.7810000004 5677846.65, 335648.6579999998 5677845.801999999, 335650.8630842535 5677845.143617179, 335650.77673334075 5677844.7250704905, 335642.90299999993 5677847.498, 335645.7810000004 5677846.65))'),
  ST_Boundary('POLYGON ((335642.903 5677847.498, 335642.894 5677847.459, 335645.92 5677846.69, 335647.378 5677852.523, 335644.403 5677853.285, 335644.374 5677853.293, 335642.903 5677847.498))')
);

comment:2 by tjay, 12 months ago

Nice to hear that this will be fixed with GEOS 3.12. A Link at this place to the relevant GEOS issue/commit may help for future investigation. This issue can be closed with this.

comment:3 by tjay, 12 months ago

i can confirm with GEOS="3.12.0beta1-CAPI-1.18.0" the TopologyException is gone.

comment:4 by mdavis, 7 months ago

Resolution: fixed
Status: newclosed

comment:5 by tjay, 4 months ago

The issue still exists when using ST_Touches https://github.com/libgeos/geos/issues/1026

Note: See TracTickets for help on using tickets.