MCPcopy Create free account
hub / github.com/shapely/shapely / contains

Function contains

shapely/predicates.py:552–608  ·  view source on GitHub ↗

Return 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 i

(a, b, **kwargs)

Source from the content-addressed store, hash-verified

550
551@multithreading_enabled
552def contains(a, b, **kwargs):
553 """Return True if geometry B is completely inside geometry A.
554
555 A contains B if no points of B lie in the exterior of A and at least one
556 point of the interior of B lies in the interior of A.
557
558 Note: following this definition, a geometry does not contain its boundary,
559 but it does contain itself. See ``contains_properly`` for a version where
560 a geometry does not contain itself.
561
562 Parameters
563 ----------
564 a, b : Geometry or array_like
565 Geometry or geometries to check.
566 **kwargs
567 See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
568
569 See Also
570 --------
571 within : ``contains(A, B) == within(B, A)``
572 contains_properly : contains with no common boundary points
573 prepare : improve performance by preparing ``a`` (the first argument)
574 contains_xy : variant for checking against a Point with x, y coordinates
575
576 Examples
577 --------
578 >>> import shapely
579 >>> from shapely import LineString, Point, Polygon
580 >>> line = LineString([(0, 0), (1, 1)])
581 >>> shapely.contains(line, Point(0, 0))
582 False
583 >>> shapely.contains(line, Point(0.5, 0.5))
584 True
585 >>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
586 >>> shapely.contains(area, Point(0, 0))
587 False
588 >>> shapely.contains(area, line)
589 True
590 >>> shapely.contains(area, LineString([(0, 0), (2, 2)]))
591 False
592 >>> polygon_with_hole = Polygon(
593 ... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
594 ... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
595 ... )
596 >>> shapely.contains(polygon_with_hole, Point(1, 1))
597 True
598 >>> shapely.contains(polygon_with_hole, Point(2, 2))
599 False
600 >>> shapely.contains(polygon_with_hole, LineString([(1, 1), (5, 5)]))
601 False
602 >>> shapely.contains(area, area)
603 True
604 >>> shapely.contains(area, None)
605 False
606
607 """
608 return lib.contains(a, b, **kwargs)
609

Callers

nothing calls this directly

Calls 1

containsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…