Description Usage Arguments Value Author(s) References See Also Examples

View source: R/point_line_distance.R

This function calculates the coordinates of and the distance to the nearest point on a segment to a given point. This function does not work with geographic coordinates.

1 | ```
nearestPointOnSegment(s, p)
``` |

`s` |
A matrix representing the coordinates of the segment. The matrix has 2x2 dimension where each row represents one of the end points. |

`p` |
A vector representing the X and Y coordinates of the point. |

A vector with three numeric values representing X and Y coordinates of the nearest point on a segment to a given point as well as the distance between both points.

German Carrillo

The function was ported to R based on this code: http://pastebin.com/n9rUuGRh

`nearestPointOnLine`

, `snapPointsToLines`

1 2 3 | ```
segment = cbind(c(1,2),c(1,1.5))
point = c(1.2,1.5)
nearestPointOnSegment(segment, point)
``` |

```
Loading required package: sp
Checking rgeos availability: TRUE
X Y distance
1.3600000 1.1800000 0.3577709
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.