FIX: Work out the area of polygons with holes and of split intersections - #152
Merged
Merged
Conversation
…/areas/Calculations.java Co-authored-by: Eugene Dorfman <eugene.dorfman@gmail.com>
justadreamer
approved these changes
Sep 17, 2026
justadreamer
approved these changes
Sep 18, 2026
This was referenced Sep 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why:
CompareOnPremTestfails on the current Enterprise data file with: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
transformGeometrytookgeometry.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 meantintersect.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:testPolygonWithHolefailed with the same exception as CI.testPolygonSplitByGridCellis 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.
CompareOnPremTestitself needs the Enterprise data file and is skipped locally, so CI is the check for it.Notes