Distance between points and lines or the border of polygons.
Distance between points and lines or the border of polygons.
The shortest distance between points and polylines or polygons.
1.1
dist2Line(p, line, distfun=distGeo)
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 distGeo
Returns
matrix with 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). If line is a Spatial* object, the ID (index) of (one of) the nearest objects is also returned. Thus if the objects are polygons and the point is inside a polygon the function may return the ID of a neighboring polygon that shares the nearest border. You can use the intersect function in packages terra.