libpysal.cg.get_segment_point_dist

libpysal.cg.get_segment_point_dist(seg, pt)[source]

Returns (1) the distance between a line segment and point and (2) the distance along the segment to the closest location on the segment from the point as a ratio of the length of the segment.

Parameters:
seglibpysal.cg.LineSegment

A line segment to compute distance from.

ptlibpysal.cg.Point

A point to compute distance from.

Returns:
distfloat

The distance between seg and pt.

ratiofloat

The distance along seg to the closest location on seg from pt as a ratio of the length of seg.

Examples

>>> seg = LineSegment(Point((0, 0)), Point((10, 0)))
>>> pt = Point((5, 5))
>>> get_segment_point_dist(seg, pt)
(5.0, 0.5)
>>> pt2 = Point((0, 0))
>>> get_segment_point_dist(seg, pt2)
(0.0, 0.0)