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:
Hi, I am looking for a way (preferably in spatstat) to obtain the point in a polygon (window in my spatstat context) that is closest to a given point outside of it (similar to closestpoint in postgis). Approximations (something that is approximately the closest point) are fine in my context Thanks, Ted --------------------------------------------- Ted Rosenbaum Graduate Student Department of Economics Yale University