Skip to content

FIX: Work out the area of polygons with holes and of split intersections - #152

Merged
Automation51D merged 2 commits into
mainfrom
fix/area-of-polygons-with-holes
Sep 18, 2026
Merged

Automation51D merged 2 commits into
mainfrom
fix/area-of-polygons-with-holes

Conversation

@YaroslavVlasenko

Copy link
Copy Markdown
Contributor

Why:

CompareOnPremTest fails on the current Enterprise data file with:

java.lang.IllegalArgumentException: Points of LinearRing do not form a closed linestring

The data is fine. The area in the log is a valid polygon with one outer boundary and five holes, every ring is closed and the text is not cut short. The problem is in Calculations, in two places.

1. Holes

transformGeometry took geometry.getCoordinates(), which is the points of every ring in one list, and built a single ring from them. For a polygon with holes the first point belongs to the outer boundary and the last one to the last hole, so the ring does not close and JTS throws. The outer boundary and each hole are now transformed as separate rings and put back together as a polygon with holes.

2. Intersections made of several pieces

When the intersection of an area with a grid cell has more than one piece, the loop read geo.getGeometryN(i) where it meant intersect.getGeometryN(i). For a polygon that returns the whole area each time, so the whole area was added once per piece. This did not throw, it gave an area that was too large. It now uses the pieces of the intersection.

Tests

Two tests in CalculationsTest, both written first and seen to fail:

  • testPolygonWithHole failed with the same exception as CI.
  • testPolygonSplitByGridCell is a U shape whose arms are two separate pieces in the next grid cell. It returned 8759 where 3438 was expected.

Both pass now, with the other seven. The polygon from the CI log was also run through the fixed code and gives an area with no error.

CompareOnPremTest itself needs the Enterprise data file and is skipped locally, so CI is the check for it.

Notes

  • Nightly was green on 17 September because it still had the previous data file in the asset cache. The cache key includes the date, so later runs download the current file and are expected to fail on this test until this is merged.
  • This code was added in Add examples for parity with ip-intelligence-dotnet-examples #96 for parity with the .NET examples. Whether the .NET version has the same two problems has not been checked.

…/areas/Calculations.java

Co-authored-by: Eugene Dorfman <eugene.dorfman@gmail.com>
@Automation51D
Automation51D merged commit 7a2a7e4 into main Sep 18, 2026
1 check passed
@Automation51D
Automation51D deleted the fix/area-of-polygons-with-holes branch September 18, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants