Skip to content
Prev 15428 / 29559 Next

Closest point in R

In spatstat, for a polygon window P and a point pattern X you can do 

    L <- as.psp(P)
    Z <- project2segment(X, L)
    Y <- Z$Xproj

Then Y[i] is the nearest point to X[i] on the boundary of P.
Other components of Z give you the distance from X[i] to Y[i], etc.

Adrian Baddeley
On 22/06/12 06:15, Ted Rosenbaum wrote: