hypertidy / anglr

Mesh creation and topology for spatial data (and not just geographic)
https://hypertidy.github.io/anglr/
83 stars 10 forks source link

winding overlay issue #39

Closed mdsumner closed 7 years ago

mdsumner commented 7 years ago

Why doesn't $t[7, ] get filtered out by over?

library(sf)
library(dplyr)
library(rangl)
vpal <- function(n) {
  if (!is.null(dim(n))) {
    n <- nrow(n)
  }
  viridis::viridis(n)
}
p_self <- st_sfc(st_polygon(list(cbind(c(0, 0, 1, -0.1, -0.1, 1.5, 0), c(0, 1, 1, 0.2, 1.2, 1.2, 0)))))
ri <- rangl(as(p_self, "Spatial"))

p <- do.call(cbind, structure(list(x = c(-0.205701357466063, -0.0357229982293921, 
                                         -0.0697186700767263, 0.312732638205784, 0.4855439700964, 0.343895337399174, 
                                         0.471379106826677, 1.62156600432815), y = c(0.424072398190045, 
                                                                                     0.160605941373205, 0.336250245917765, 1.09831988982884, 0.54022427700177, 
                                                                                     0.732866417469998, -0.0801967342120795, 1.71024198308086)), .Names = c("x", 
                                                                                                                                                            "y")))
library(sp)
inp <- over(SpatialPoints(p), as(p_self, "Spatial"))
ploti <- function(x, col = NULL) {
  xx <- x %>% inner_join(pi$tXv) %>% inner_join(pi$v) %>% select(x_, y_) 
  #print(xx)
  polypath(xx, col = col)
  #$print(apply(as.matrix(xx), 2, mean))
  text(matrix(apply(as.matrix(xx), 2, mean), ncol = 2), lab = i)
}
plot(p)
plot(p_self, add = TRUE)
text(p, lab = sprintf("pt%i", seq_len(nrow(p))))
for (i in seq_len(nrow(pi$t))) ploti(pi$t[i, ], col =  scales::alpha("red", i/10))
data.frame(pt = seq_len(nrow(p)), pip = over(SpatialPoints(p), as(p_self, "Spatial")))

    pt pip
1  1  NA
2  2  NA
3  3   1
4  4   1
5  5   1
6  6  NA
7  7  NA
8  8  NA    

image

mdsumner commented 7 years ago

Because rangl cleverly optimize the lookup and only filters out known holes.

That's probably a good thing, since the simple features should be fixed independently.

See here for a fix https://github.com/r-gris/toposhop/issues/2