shapely.buffer

Contents

shapely.buffer#

buffer(geometry, distance, quad_segs=8, cap_style='round', join_style='round', mitre_limit=5.0, single_sided=False, **kwargs)#

Computes the buffer of a geometry for positive and negative buffer distance.

The buffer of a geometry is defined as the Minkowski sum (or difference, for negative distance) of the geometry with a circle with radius equal to the absolute value of the buffer distance.

The buffer operation always returns a polygonal result. The negative or zero-distance buffer of lines and points is always empty.

Parameters:
geometryGeometry or array_like
distancefloat or array_like

Specifies the circle radius in the Minkowski sum (or difference).

quad_segsint, default 8

Specifies the number of linear segments in a quarter circle in the approximation of circular arcs.

cap_styleshapely.BufferCapStyle or {‘round’, ‘square’, ‘flat’}, default ‘round’

Specifies the shape of buffered line endings. BufferCapStyle.round (‘round’) results in circular line endings (see quad_segs). Both BufferCapStyle.square (‘square’) and BufferCapStyle.flat (‘flat’) result in rectangular line endings, only BufferCapStyle.flat (‘flat’) will end at the original vertex, while BufferCapStyle.square (‘square’) involves adding the buffer width.

join_styleshapely.BufferJoinStyle or {‘round’, ‘mitre’, ‘bevel’}, default ‘round’

Specifies the shape of buffered line midpoints. BufferJoinStyle.round (‘round’) results in rounded shapes. BufferJoinStyle.bevel (‘bevel’) results in a beveled edge that touches the original vertex. BufferJoinStyle.mitre (‘mitre’) results in a single vertex that is beveled depending on the mitre_limit parameter.

mitre_limitfloat, default 5.0

Crops of ‘mitre’-style joins if the point is displaced from the buffered vertex by more than this limit.

single_sidedbool, default False

Only buffer at one side of the geometry.

**kwargs

See NumPy ufunc docs for other keyword arguments.

Examples

>>> from shapely import LineString, Point, Polygon, BufferCapStyle, BufferJoinStyle
>>> buffer(Point(10, 10), 2, quad_segs=1)
<POLYGON ((12 10, 10 8, 8 10, 10 12, 12 10))>
>>> buffer(Point(10, 10), 2, quad_segs=2)
<POLYGON ((12 10, 11.414 8.586, 10 8, 8.586 8.586, 8 10, 8.5...>
>>> buffer(Point(10, 10), -2, quad_segs=1)
<POLYGON EMPTY>
>>> line = LineString([(10, 10), (20, 10)])
>>> buffer(line, 2, cap_style="square")
<POLYGON ((20 12, 22 12, 22 8, 10 8, 8 8, 8 12, 20 12))>
>>> buffer(line, 2, cap_style="flat")
<POLYGON ((20 12, 20 8, 10 8, 10 12, 20 12))>
>>> buffer(line, 2, single_sided=True, cap_style="flat")
<POLYGON ((20 10, 10 10, 10 12, 20 12, 20 10))>
>>> line2 = LineString([(10, 10), (20, 10), (20, 20)])
>>> buffer(line2, 2, cap_style="flat", join_style="bevel")
<POLYGON ((18 12, 18 20, 22 20, 22 10, 20 8, 10 8, 10 12, 18 12))>
>>> buffer(line2, 2, cap_style="flat", join_style="mitre")
<POLYGON ((18 12, 18 20, 22 20, 22 8, 10 8, 10 12, 18 12))>
>>> buffer(line2, 2, cap_style="flat", join_style="mitre", mitre_limit=1)
<POLYGON ((18 12, 18 20, 22 20, 22 9.172, 20.828 8, 10 8, 10 12, 18 12))>
>>> square = Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)])
>>> buffer(square, 2, join_style="mitre")
<POLYGON ((-2 -2, -2 12, 12 12, 12 -2, -2 -2))>
>>> buffer(square, -2, join_style="mitre")
<POLYGON ((2 2, 2 8, 8 8, 8 2, 2 2))>
>>> buffer(square, -5, join_style="mitre")
<POLYGON EMPTY>
>>> buffer(line, float("nan")) is None
True