Fix st_difference on a single sfc so it works on entirely contained geometries correctly. #975
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.
In playing around with
sf
and some very simple geometries, I noticed thatst_difference
when run on a singlesfc
returned unexpected results in the case where earlier geometries are entirely contained in later geometries. e.g. in the existing test forst_difference
with fully contained geometries, if we change the order ofpl1
andpl2
(pl2
is entirely contained withinpl1
) thenreturns
pl1
in it's second geometry, where we'd expectpl1
with a hole wherepl2
is, as the usualst_difference
gives the correct geometry with a hole:This is primarily due to
GEOSOverlaps_r
being called before we callGEOSDifference_r
inCPL_nary_difference
. Overlaps returns false in the case that one of the geometries are entirely contained (and in my understanding is symmetric, so that Overlaps(a,b) == Overlaps(b,a)).The patch changes this to use
GEOSIntersects_r
which I'm guessing might be equivalent toOverlaps || Contains
.First commit adds to the existing test for entirely contained geometries, second fixes it :)