nearestPointOnLine: Get the nearest point on a line to a given point

Description Usage Arguments Value Author(s) See Also Examples

View source: R/point_line_distance.R

Description

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

Usage

1
nearestPointOnLine(coordsLine, coordsPoint)

Arguments

coordsLine

Matrix with coordinates of line vertices. Each row represents a vertex.

coordsPoint

A vector representing the X and Y coordinates of the point.

Value

Vector with the X and Y coordinates of the nearest point on a line to the given point.

Author(s)

German Carrillo

See Also

nearestPointOnSegment, snapPointsToLines

Examples

1
2
3
coordsLine = cbind(c(1,2,3),c(3,2,2))
coordsPoint = c(1.2,1.5)
nearestPointOnLine(coordsLine, coordsPoint)

Example output

Loading required package: sp
Checking rgeos availability: FALSE
 	Note: when rgeos is not available, polygon geometry 	computations in maptools depend on gpclib,
 	which has a restricted licence. It is disabled by default;
 	to enable gpclib, type gpclibPermit()
   X    Y 
1.85 2.15 

maptools documentation built on Sept. 7, 2021, 5:09 p.m.