def test_offset_curve_kwargs(): # check that kwargs are passed through result1 = shapely.offset_curve( line_string, -2.0, quadsegs=2, join_style="mitre", mitre_limit=2.0 ) result2 = shapely.offset_curve(line_string, -2.0) assert result1 != result2
def parallel_offset( self, distance, side="right", resolution=16, join_style=JOIN_STYLE.round, mitre_limit=5.0, ): """Returns a LineString or MultiLineString geometry at a distance from the object on its right or its left side. The side parameter may be 'left' or 'right' (default is 'right'). The resolution of the buffer around each vertex of the object increases by increasing the resolution keyword parameter or third positional parameter. Vertices of right hand offset lines will be ordered in reverse. The join style is for outside corners between line segments. Accepted values are JOIN_STYLE.round (1), JOIN_STYLE.mitre (2), and JOIN_STYLE.bevel (3). The mitre ratio limit is used for very sharp corners. It is the ratio of the distance from the corner to the end of the mitred offset corner. When two line segments meet at a sharp angle, a miter join will extend far beyond the original geometry. To prevent unreasonable geometry, the mitre limit allows controlling the maximum length of the join corner. Corners with a ratio which exceed the limit will be beveled. """ if mitre_limit == 0.0: raise ValueError("Cannot compute offset from zero-length line segment") if side == "right": distance *= -1 return shapely.offset_curve(self, distance, resolution, join_style, mitre_limit)
def test_offset_curve_non_scalar_kwargs(): msg = "only accepts scalar values" with pytest.raises(TypeError, match=msg): shapely.offset_curve([line_string, line_string], 1, quadsegs=np.array([8, 9])) with pytest.raises(TypeError, match=msg): shapely.offset_curve( [line_string, line_string], 1, join_style=["round", "bevel"] ) with pytest.raises(TypeError, match=msg): shapely.offset_curve([line_string, line_string], 1, mitre_limit=[5.0, 6.0])
def test_offset_curve_join_style_invalid(): with pytest.raises(ValueError, match="'invalid' is not a valid option"): shapely.offset_curve(line_string, 1.0, join_style="invalid")
def test_offset_curve_distance_array(): # check that kwargs are passed through result = shapely.offset_curve([line_string, line_string], [-2.0, -3.0]) assert result[0] == shapely.offset_curve(line_string, -2.0) assert result[1] == shapely.offset_curve(line_string, -3.0)
def test_offset_curve_empty(): with ignore_invalid(): # Empty geometries emit an "invalid" warning # (see https://github.com/libgeos/geos/issues/515) actual = shapely.offset_curve(empty_line_string, 2.0) assert shapely.is_empty(actual)