def nearest_points(g1, g2): """Returns the calculated nearest points in the input geometries The points are returned in the same order as the input geometries. """ seq = shapely.shortest_line(g1, g2) if seq is None: if g1.is_empty: raise ValueError("The first input geometry is empty") else: raise ValueError("The second input geometry is empty") p1 = shapely.get_point(seq, 0) p2 = shapely.get_point(seq, 1) return (p1, p2)
def test_shortest_line_empty(prepare): g1 = _prepare_input(line_string, prepare) assert shapely.shortest_line(g1, empty_line_string) is None g1_empty = _prepare_input(empty_line_string, prepare) assert shapely.shortest_line(g1_empty, line_string) is None assert shapely.shortest_line(g1_empty, empty_line_string) is None
def test_shortest_line_none(prepare): assert shapely.shortest_line(_prepare_input(line_string, prepare), None) is None assert shapely.shortest_line(None, line_string) is None assert shapely.shortest_line(None, None) is None
def test_shortest_line(prepare): g1 = shapely.linestrings([(0, 0), (1, 0), (1, 1)]) g2 = shapely.linestrings([(0, 3), (3, 0)]) actual = shapely.shortest_line(_prepare_input(g1, prepare), g2) expected = shapely.linestrings([(1, 1), (1.5, 1.5)]) assert shapely.equals(actual, expected)