# dist2Line

0th

Percentile

##### Distance between points and lines or (the border of) polygons.

The shortest distance between points and polylines or polygons.

Keywords
spatial
##### Usage
dist2Line(p, line, distfun=distHaversine)
##### Arguments
p
longitude/latitude of point(s). Can be a vector of two numbers, a matrix of 2 columns (first one is longitude, second is latitude) or a SpatialPoints* object
line
longitude/latitude of line as a matrix of 2 columns (first one is longitude, second is latitude) or a SpatialLines* or SpatialPolygons* object
distfun
A distance function, such as distHaversine
##### Value

• Distance and lon/lat of the nearest point on the line. Distance is in the same unit as r in the distfun(default is meters)

• dist2Line
##### Examples
line <- rbind(c(-180,-20), c(-150,-10), c(-140,55), c(10, 0), c(-140,-60))
pnts <- rbind(c(-170,0), c(-75,0), c(-70,-10), c(-80,20), c(-100,-50), c(-100,-60), c(-100,-40), c(-100,-20), c(-100,-10), c(-100,0))
d = dist2Line(pnts, line)
plot( makeLine(line), type='l')
points(line)
points(pnts, col='blue', pch=20)
points(d[,2], d[,3], col='red', pch='x')
for (i in 1:nrow(d)) lines(gcIntermediate(pnts[i,], d[i,2:3], 10), lwd=2)
Documentation reproduced from package geosphere, version 1.2-15, License: GPL

### Community examples

Looks like there are no examples yet.