locationtech / locationtech/jts

Polygonizer.getGeometry() results are non-deterministic when extractOnlyPolygonal=true

Open
#1,063 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

type-bug
Dominant language
Java
Stars
2.2k
Forks
475
Avg merge
14d 10h
Merged PRs (30d)
1

Description

Polygonizer implementation seems to hold some internal state that affects the output of the getGeometry() method when extractOnlyPolygonal=true.

The attached unit test class demonstrates the issue. Because of the nature of this bug, the assertions may fail depending on the initial internal state of the library on the testing machine. But the assertions pass in my test environment.

JTSBugsTest.txt

Doing the following multiple times yields different results:

  • Create a new Polygonizer with extractOnlyPolygonal=true
  • Add the exact same input linework
  • Call getGeometry()

If the input linework intersects along joint edges, and Polygonizer produces an invalid geometry, the result is different every time, even after normalizing the result.
If the input linework intersects only at points, in which case Polygonizer always produces a valid geometry, the result may be different every time, but seems to be deterministic after normalising.
If the input linework does not intersect, Polygonizer seems to produce the same result every time, even without normalising.

Note that something as simple as calling new GeometryFactory().createPolygon().isValid() affects the internal state and changes the result of the next call to Polygonizer.getGeometry(). This probably also indicates the presence of a bug in the Geometry.isValid() method, as you would never expect it to modify the state of anything at all.

JTS version 1.19.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the attached JTSBugsTest.txt unit test and reproduce repeated calls to Polygonizer.getGeometry() with extractOnlyPolygonal=true. Inspect the Polygonizer and Geometry.isValid() entry points to identify the state change; done means repeated identical inputs produce consistent results and the reproducer passes reliably.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.