Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix st_difference on a single sfc so it works on entirely contained geometries correctly. #975

Merged
merged 2 commits into from Feb 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/geos.cpp
Expand Up @@ -956,8 +956,8 @@ Rcpp::List CPL_nary_difference(Rcpp::List sfc) {
contained = chk_(GEOSContains_r(hGEOSCtxt, out[tree_sel[j]].get(), geom.get()));
if (contained)
break;
// test if the items overlap with geom
if (chk_(GEOSOverlaps_r(hGEOSCtxt, geom.get(), out[tree_sel[j]].get()))) {
// test if the items intersect with geom
if (chk_(GEOSIntersects_r(hGEOSCtxt, geom.get(), out[tree_sel[j]].get()))) {
// if they do then erase overlapping parts from geom
geom = geos_ptr(GEOSDifference_r(hGEOSCtxt, geom.get(), out[tree_sel[j]].get()), hGEOSCtxt);
if (geom == nullptr)
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test_geos.R
Expand Up @@ -240,6 +240,12 @@ test_that("st_difference works with fully contained geometries", {
#expect_equal(out1[[2]][[1]], correct_geom[[2]][[1]])
#expect_equal(out2[[1]][[1]], correct_geom[[1]][[1]])
#expect_equal(out2[[2]][[1]], correct_geom[[2]][[1]])
# check change in order
in3 = st_sfc(list(pl2, pl1))
correct_geom = list(pl2, st_difference(pl1, pl2))
out3 = st_difference(in3)
expect_equal(correct_geom[[1]], out3[[1]])
expect_equal(correct_geom[[2]], out3[[2]])
})

test_that("binary operations work on sf objects with common column names", {
Expand Down