Repository navigation
Keep polygons when union_ loses area in combine_polygons_below - #985
Open
geoneutrino wants to merge 1 commit into
Open
geoneutrino wants to merge 1 commit into
geoneutrino wants to merge 1 commit into
Conversation
Boost.Geometry's union_ can drop one of two valid polygons that share an edge along nearly collinear vertices, or return nothing, depending on the argument order (boostorg/geometry#1506; seen with 1.83, 1.87, 1.89, 1.92 and develop). union_near() now checks the area of the result: if it is smaller than both inputs together minus their overlap, it retries with the arguments swapped and otherwise keeps the polygons uncombined. The overlap is only computed when the union is smaller than the sum of the inputs, so the check is almost free. On OpenStreetMap test data with a profile that combines landuse and landcover below z14, two landuse features lost most of their area (one -94 %); they are now complete, all other geometry is unchanged. On Overture land cover cleaned into a coverage with many shared edges, whole forest polygons disappeared from a z8 tile (5.5 % of the tile uncovered, 0.4 % without combining); with this change 0.6 %. Runtime with one thread +0.9 % user time, wall clock unchanged.
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.
Boost.Geometry's
union_can drop one of two valid, non-overlapping polygons that share an edge along nearly collinear vertices, or return nothing, depending on the argument order: boostorg/geometry#1506. It happens with Boost 1.83 (the version in current Debian/Ubuntu) and still with 1.92 anddevelopin one of the two argument orders. The old rescaling, which avoided it, was removed in 1.87.combine_polygons_belowruns every polygon of a tile throughunion_near(), so a failingunion_removes whole polygons from the tile.Change:
union_near()checks the area of the union. If it is smaller than both inputs together minus their overlap, it retries with the arguments swapped, and if that fails too it keeps the polygons uncombined (exact when they don't overlap, which is the usual case for adjacent polygons). The overlap is only computed when the union is smaller than the sum of the inputs, so the normal path costs two area computations.Measured (own profile, landuse/landcover combined below z14,
--threads 1, geometry compared feature by feature):New unit test
test_union_manywith the polygons from the Boost issue; it fails without the change.