shapely.contains_properly

shapely.contains_properly#

contains_properly(a, b, **kwargs)#

Return True if geometry B is completely inside geometry A, with no common boundary points.

A contains B properly if B intersects the interior of A but not the boundary (or exterior). This means that a geometry A does not “contain properly” itself, which contrasts with contains(), where common points on the boundary are allowed.

If you need to test multiple geometries against the same geometry A, you can improve performance by preparing A in advance using prepare().

Note: this function will prepare the geometries under the hood if needed. You can prepare the geometries in advance to avoid repeated preparation when calling this function multiple times.

Parameters:
a, bGeometry or array_like

Geometry or geometries to check.

**kwargs

See NumPy ufunc docs for other keyword arguments.

See also

contains

contains which allows common boundary points

prepare

improve performance by preparing a (the first argument)

Examples

>>> import shapely
>>> from shapely import Polygon
>>> area1 = Polygon([(0, 0), (3, 0), (3, 3), (0, 3), (0, 0)])
>>> area2 = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> area3 = Polygon([(1, 1), (2, 1), (2, 2), (1, 2), (1, 1)])

area1 and area2 have a common border:

>>> shapely.contains(area1, area2)
True
>>> shapely.contains_properly(area1, area2)
False

area3 is completely inside area1 with no common border:

>>> shapely.contains(area1, area3)
True
>>> shapely.contains_properly(area1, area3)
True