pysal.explore.spaghetti.snap_points_on_segments

pysal.explore.spaghetti.snap_points_on_segments(points, segments)[source]

Place points onto closet segment in a set of segments

Parameters:
points : dict

Point id as key and (x,y) coordinate as value

segments : list

Elements are of type pysal.lib.cg.shapes.Chain ** Note ** each element is a segment represented as a chain with one head and one tail node in other words one link only.

Returns:
p2s : dict

key [point id (see points in arguments)]; value [a 2-tuple ((head, tail), point) where (head, tail) is the target segment, and point is the snapped location on the segment.

Examples

>>> import pysal.explore.spaghetti as spgh
>>> from pysal.lib.cg.shapes import Point, Chain
>>> points = {0: Point((1,1))}
>>> segments = [Chain([Point((0,0)), Point((2,0))])]
>>> spgh.util.snap_points_on_segments(points, segments)
{0: ([(0.0, 0.0), (2.0, 0.0)], array([1., 0.]))}