locationtech / jts

The JTS Topology Suite is a Java library for creating and manipulating vector geometry.
Other
1.95k stars 440 forks source link

Enable ring-endpoint-handling for LineString with isRing() == true #1033

Closed FObermaier closed 8 months ago

FObermaier commented 8 months ago

With the current state of TopologyPreservingSimplifier and related classes, the LINEARRING (220 180, 261 175, 380 220, 300 40, 140 30, 30 220, 176 176, 220 180) simplifies to LINEARRING (30 220, 380 220, 300 40, 140 30, 30 220) using a tolerance value of 40. (see here)

Performing the same operation on LINESTRING (220 180, 261 175, 380 220, 300 40, 140 30, 30 220, 176 176, 220 180) gives LINESTRING (220 180, 380 220, 300 40, 140 30, 30 220, 220 180).

dr-jts commented 8 months ago

It's not clear from the description what this PR does?

Are you suggesting changing the TopologyPreservingSimplifier behaviour so that it simplifies the endpoint of closed LineStrings? If so, I disagree - the contract is to preserve the endpoints of LineStrings.

FObermaier commented 8 months ago

Are you suggesting changing the TopologyPreservingSimplifier behaviour so that it simplifies the endpoint of closed LineStrings?

Yes.

If so, I disagree - the contract is to preserve the endpoints of LineStrings.

Take a look at the following snipplet:

Geometry ls = read("LINESTRING (220 180, 261 175, 380 220, 300 40, 140 30, 30 220, 176 176, 220 180)");
Geometry lr = read("LINEARRING (220 180, 261 175, 380 220, 300 40, 140 30, 30 220, 176 176, 220 180)");
assertTrue(ls.equals(lr));
assertTrue(ls.equalsExact(lr));

If this is true, then any operation on either of these geometries should give the same result.

dr-jts commented 8 months ago

If this is true, then any operation on either of these geometries should give the same result.

Not necessarily. The OGC topological model is somewhat limited in terms of real-world requirements, IMHO. That's why the concept of BoundaryNodeRule was introduced - to give more control over how endpoints are treated.

For an example, consider simplifying a road network that contains "loops" - e.g. turn-arounds modelled as closed LineStrings. In order to preserve network integrity, the endpoints of all lines must be preserved, including those of closed LineStrings.

What could be done is allow the simplify behaviour to be controlled by an option flag. This takes effort and complicates the API, so is there a clear practical use case for this?

FObermaier commented 8 months ago

You have a point regarding LineStrings in network models.