Fix buffer to use largest enclosed area for invalid rings #655
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.
The buffer algorithm has a long-standing issue where a polygon with a small self-intersecting lobe at the top of the polygon gets reduced to just the small lobe, rather than the small lobe being removed. See for example #629. This issue can also occur in hole rings.
This issue also affects JTS algorithms which use the
buffer(0)
trick to produce valid polygons (such asDouglasPeuckerSimplifier
,VWSimplifier
andDensifier
). For example, #498.The issue occurs because
buffer
has to determine the interior of a ring to know which side to build the buffer offset curve on (which in the case of a zero-width buffer is just the ring linework). Currently buffer uses theOrientation.isCCW
test to do this. For efficiency this algorithm determines ring orientation by checking only the line segments incident on the uppermost vertex of the ring. For a valid ring (where the linework does not cross itself) this works fine. However, in a self-crossing ring (aka a "bow-tie") which lobe is chosen as the interior is not well-defined. The uppermost vertex approach can end up choosing a very small lobe to be the "interior" of the polygon.The fix is to use an orientation test which takes into account the entire ring. This is provided by the Signed-Area Orientation test. This effectively determines the orientation based on the largest area enclosed by the ring. This corresponds much more closely to user expectation based on visual assessment. It also minimizes the change in area and (usually) extent.
