shapely.intersection

Contents

shapely.intersection#

intersection(a, b, grid_size=None, **kwargs)#

Return the geometry that is shared between input geometries.

If grid_size is nonzero, input coordinates will be snapped to a precision grid of that size and resulting coordinates will be snapped to that same grid. If 0, this operation will use double precision coordinates. If None, the highest precision of the inputs will be used, which may be previously set using set_precision. Note: returned geometry does not have precision set unless specified previously by set_precision.

Parameters:
a, bGeometry or array_like

Geometry or geometries to intersect with.

grid_sizefloat, optional

Precision grid size; will use the highest precision of the inputs by default.

**kwargs

See NumPy ufunc docs for other keyword arguments.

Notes

Deprecated since version 2.1.0: A deprecation warning is shown if grid_size is specified as a positional argument. This will need to be specified as a keyword argument in a future release.

Examples

>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 0), (2, 2)])
>>> shapely.intersection(line, LineString([(1, 1), (3, 3)]))
<LINESTRING (1 1, 2 2)>
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.intersection(box1, box2).normalize()
<POLYGON ((1 1, 1 2, 2 2, 2 1, 1 1))>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.intersection(box1, box2, grid_size=1)
<POLYGON ((2 2, 2 1, 1 1, 1 2, 2 2))>