project2set: Find Nearest Point in a Region

View source: R/exactPdt.R

project2setR Documentation

Find Nearest Point in a Region

Description

For each data point in a point pattern X, find the nearest location in a given spatial region W.

Usage

  project2set(X, W, ..., polygonal=is.polygonal(W))

Arguments

X

Point pattern (object of class "ppp").

W

Window (object of class "owin") or something acceptable to as.owin.

...

Arguments passed to as.mask controlling the pixel resolution, if polygonal=FALSE.

polygonal

Logical value specifying whether W should be treated as a polygonal window (polygonal=TRUE) or a binary mask window (polygonal=FALSE), and converted to the desired kind of window if necessary.

Details

This function alters the point pattern X so that every point lies inside the window W.

  • If polygonal=FALSE the window W is first discretised as a binary mask using as.mask with pixel resolution determined by the arguments .... Then for each data point X[i] in the point pattern X, the algorithm finds the nearest pixel centre inside W, and moves X[i] to this location.

  • If polygonal=TRUE, the window W is first converted to a polygonal window using as.polygonal. Then for each data point X[i] in the point pattern X, the algorithm finds the nearest location along the boundary of W, moves X[i] to that location, and then perturbs X[i] slightly so that it lies a short distance inside the window W.

The result is a point pattern Y containing these nearest points, that is, Y[i] is the nearest point in W to the point X[i].

Value

A point pattern (object of class "ppp") with the same number of points as X in the window W.

Author(s)

\spatstatAuthors

.

See Also

project2segment, nncross

Examples

## discrete case
  He <- heather$fine[owin(c(2.8, 7.4), c(4.0, 7.8))]
  plot(He, main="project2set")
  W <- erosion(complement.owin(He), 0.2)
if(require(spatstat.random)) {
  X <- runifpoint(4, W)
} else {
  X <- ppp(c(6.1, 4.3, 5.7, 4.7), c(5.0, 6.6, 7.5, 4.9), window=W)
}
  points(X, col="red")
  Y <- project2set(X, He)
  points(Y, col="green")
  arrows(X$x, X$y, Y$x, Y$y, angle=15, length=0.2)

## polygonal case
  A <- runifrect(100, Frame(letterR))
  A <- A[!inside.owin(A, , letterR)]
  plot(A, cols="red")
  B <- project2set(A, letterR)
  points(B, col="green")
  arrows(A$x, A$y, B$x, B$y, angle=15, length=0.2)

spatstat.geom documentation built on May 23, 2026, 5:09 p.m.