Skip to content

Fix BoundaryChainNoder to split chains at self-touch nodes#1134

Merged
dr-jts merged 1 commit intolocationtech:masterfrom
dr-jts:fix-boundarychainnoder-selftouch
May 30, 2025
Merged

Fix BoundaryChainNoder to split chains at self-touch nodes#1134
dr-jts merged 1 commit intolocationtech:masterfrom
dr-jts:fix-boundarychainnoder-selftouch

Conversation

@dr-jts
Copy link
Contributor

@dr-jts dr-jts commented May 30, 2025

Fixes the BoundaryChainNoder to split chains at self-touch nodes. This is required by CoverageUnion to produce correct OGC topology for inverted polygons and exverted holes.

For example, the coverage:

GEOMETRYCOLLECTION (POLYGON ((1 9, 9 9, 9 6, 5 7, 2 6, 1 9)), POLYGON ((1 1, 1 9, 2 6, 4 3, 5 7, 7 3, 9 6, 9 1, 1 1)))

produces a polygon with two holes:

POLYGON ((9 9, 9 6, 9 1, 1 1, 1 9, 9 9), (5 7, 7 3, 9 6, 5 7), (2 6, 4 3, 5 7, 2 6))
image

Before this fix, the output was an inverted polygon with a single self-touching ring.

@dr-jts dr-jts merged commit 8c5ba92 into locationtech:master May 30, 2025
2 checks passed
@dr-jts dr-jts deleted the fix-boundarychainnoder-selftouch branch May 30, 2025 21:50
@pramsey
Copy link

pramsey commented Jul 8, 2025

Porting to GEOS, this pre-existing test now throws a TopologyException:

auto input = GEOSWKTReader_read(m_reader,
        "GEOMETRYCOLLECTION(POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0)), POLYGON ((1 0, 0.9 1, 2 1, 2 0, 1 0)))");

auto result = GEOSCoverageUnion(input);

What does JTS do? @dr-jts

@pramsey
Copy link

pramsey commented Jul 8, 2025

Answering my own question, it does the same thing as GEOS:

image

pramsey added a commit to Snowflake-Labs/geos that referenced this pull request Jul 8, 2025
@dr-jts
Copy link
Contributor Author

dr-jts commented Jul 8, 2025

it does the same thing as GEOS:

The TopologyException is expected behaviour, since the input is an invalid coverage (the polygons overlap). Are you seeing something that needs fixing in JTS?

@pramsey
Copy link

pramsey commented Jul 8, 2025 via email

@dr-jts
Copy link
Contributor Author

dr-jts commented Jul 8, 2025

It’s a change in behaviour. Previously the behavior was that invalid coverages were just returned unchanged when fed through coversge union

Actually it's always been possible that TopoloigyExceptions are thrown for invalid coverages. See the Javadoc on OverlayNG.CoverageUnion here. But the doc on the coverage.CoverageUnion class should make this explicit.

pramsey added a commit to libgeos/geos that referenced this pull request Jul 8, 2025
Port of locationtech/jts#1134, to handle case where holes in a coverage touch at a point when generating a coverage union.
@dr-jts
Copy link
Contributor Author

dr-jts commented Jul 8, 2025

Added doc about CoverageUnion exceptions in 0e5ac9a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants