Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

nearestsegment

Find Line Segment Nearest to Each Point


Description

Given a point pattern and a line segment pattern, this function finds the nearest line segment for each point.

Usage

nearestsegment(X, Y)

Arguments

X

A point pattern (object of class "ppp").

Y

A line segment pattern (object of class "psp").

Details

The distance between a point x and a straight line segment y is defined to be the shortest Euclidean distance between x and any location on y. This algorithm first calculates the distance from each point of X to each segment of Y. Then it determines, for each point x in X, which segment of Y is closest. The index of this segment is returned.

Value

Integer vector v (of length equal to the number of points in X) identifying the nearest segment to each point. If v[i] = j, then Y[j] is the line segment lying closest to X[i].

Author(s)

and Rolf Turner r.turner@auckland.ac.nz

See Also

project2segment to project each point of X to a point lying on one of the line segments.

Use distmap.psp to identify the nearest line segment for each pixel in a grid.

Examples

X <- runifrect(3)
  Y <- as.psp(matrix(runif(20), 5, 4), window=owin())
  v <- nearestsegment(X,Y)
  plot(Y)
  plot(X, add=TRUE)
  plot(X[1], add=TRUE, col="red")
  plot(Y[v[1]], add=TRUE, lwd=2, col="red")

spatstat.geom

Geometrical Functionality of the 'spatstat' Family

v2.1-0
GPL (>= 2)
Authors
Adrian Baddeley [aut, cre], Rolf Turner [aut], Ege Rubak [aut], Tilman Davies [ctb], Ute Hahn [ctb], Abdollah Jalilian [ctb], Sebastian Meyer [ctb], Suman Rakshit [ctb], Dominic Schuhmacher [ctb], Rasmus Waagepetersen [ctb]
Initial release
2021-04-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.