R/clickjoin.R

Defines functions clickjoin

Documented in clickjoin

#
#  clickjoin.R
#
# interactive addition/deletion of segments between vertices
#

clickjoin <- function(X, ..., add=TRUE, m=NULL, join=TRUE) {
  verifyclass(X, "ppp")
  if(!(is.logical(join) && length(join) == 1))
    stop("join should be a single logical value")
  plot(X, add=add, pch=16)
  if(is.null(m)) {
    m <- matrix(FALSE, npoints(X), npoints(X))
  } else {
    stopifnot(is.matrix(m) && is.logical(m))
    stopifnot(all(dim(m) == npoints(X)))
    from <- as.vector(row(m)[m])
    to   <- as.vector(col(m)[m])
    with(X, segments(x[from], y[from], x[to], y[to]))
  }
  while(TRUE) {
    twoid <- identify(X, plot=FALSE, n=2)
    n <- length(twoid)
    if(n == 0) break
    if(n == 2) {
      m[twoid[1L],twoid[2L]] <- m[twoid[2L],twoid[1L]] <- join
      lines(X$x[twoid], X$y[twoid], ...)
    }
  }
  return(m)
}

Try the spatstat.linnet package in your browser

Any scripts or data that you put into this service are public.

spatstat.linnet documentation built on Nov. 2, 2023, 6:10 p.m.