shapely.contains
shapely.contains#
- contains(a, b, **kwargs)#
Returns True if geometry B is completely inside geometry A.
A contains B if no points of B lie in the exterior of A and at least one point of the interior of B lies in the interior of A.
Note: following this definition, a geometry does not contain its boundary, but it does contain itself. See
contains_properly
for a version where a geometry does not contain itself.- Parameters
- a, bGeometry or array_like
- **kwargs
For other keyword-only arguments, see the NumPy ufunc docs.
See also
within
contains(A, B) == within(B, A)
contains_properly
contains with no common boundary points
prepare
improve performance by preparing
a
(the first argument)contains_xy
variant for checking against a Point with x, y coordinates
Examples
>>> from shapely import LineString, Point, Polygon >>> line = LineString([(0, 0), (1, 1)]) >>> contains(line, Point(0, 0)) False >>> contains(line, Point(0.5, 0.5)) True >>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]) >>> contains(area, Point(0, 0)) False >>> contains(area, line) True >>> contains(area, LineString([(0, 0), (2, 2)])) False >>> polygon_with_hole = Polygon( ... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)], ... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]] ... ) >>> contains(polygon_with_hole, Point(1, 1)) True >>> contains(polygon_with_hole, Point(2, 2)) False >>> contains(polygon_with_hole, LineString([(1, 1), (5, 5)])) False >>> contains(area, area) True >>> contains(area, None) False