Skip to content

Commit

Permalink
Merge pull request #975 from jmarshallnz/fix_st_difference
Browse files Browse the repository at this point in the history
Fix st_difference on a single sfc so it works on entirely contained geometries correctly.
  • Loading branch information
edzer committed Feb 18, 2019
2 parents f14b755 + 864fcc9 commit 43836ba
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
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

0 comments on commit 43836ba

Please sign in to comment.