ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Geometry Namespace / GeometryEngine Class / Contains Method
The base geometry.
The comparison geometry.

In This Topic
    Contains Method (GeometryEngine)
    In This Topic
    Returns true if geometry1 contains geometry2.
    public bool Contains( 
       Geometry geometry1,
       Geometry geometry2
    Public Function Contains( _
       ByVal geometry1 As Geometry, _
       ByVal geometry2 As Geometry _
    ) As Boolean


    The base geometry.
    The comparison geometry.

    Return Value

    True if the geometry1 contains geometry2.
    Either geometry1 or geometry2 or both are null.
    The method is not implemented for GeometryBag.
    Incompatible spatial references between the input geometries.
    If both geometry1 and geometry2 are not empty, then geometry1 contains geometry2 if the intersection of their interiors is not empty and geometry2 is a subset of geometry1.

    If geometry1 is empty, then it does not contain geometry2.

    If geometry1 is not empty and geometry2 is empty, then geometry1 contains geometry2.

    Contains is the opposite of Within. That is, geometry1 contains geometry2 if and only if geometry2 is within geometry1.

    GeometryEngine Contains

    Polygon contains MapPoints, Polylines, Polygons
    // build a polygon      
    List<MapPoint> pts = new List<MapPoint>();
    pts.Add(MapPointBuilderEx.CreateMapPoint(1.0, 1.0));
    pts.Add(MapPointBuilderEx.CreateMapPoint(1.0, 2.0));
    pts.Add(MapPointBuilderEx.CreateMapPoint(2.0, 2.0));
    pts.Add(MapPointBuilderEx.CreateMapPoint(2.0, 1.0));
    Polygon poly = PolygonBuilderEx.CreatePolygon(pts);
    // test if an inner point is contained
    MapPoint innerPt = MapPointBuilderEx.CreateMapPoint(1.5, 1.5);
    bool contains = GeometryEngine.Instance.Contains(poly, innerPt);   // contains = true
    // test a point on a boundary
    contains = GeometryEngine.Instance.Contains(poly, poly.Points[0]);     // contains = false
    // test an interior line
    MapPoint innerPt2 = MapPointBuilderEx.CreateMapPoint(1.25, 1.75);
    List<MapPoint> innerLinePts = new List<MapPoint>();
    // test an inner polyline
    Polyline polyline = PolylineBuilderEx.CreatePolyline(innerLinePts);
    contains = GeometryEngine.Instance.Contains(poly, polyline);   // contains = true
    // test a line that crosses the boundary
    MapPoint outerPt = MapPointBuilderEx.CreateMapPoint(3, 1.5);
    List<MapPoint> crossingLinePts = new List<MapPoint>();
    polyline = PolylineBuilderEx.CreatePolyline(crossingLinePts);
    contains = GeometryEngine.Instance.Contains(poly, polyline);     // contains = false
    // test a polygon in polygon
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(innerPt, innerPt2);
    contains = GeometryEngine.Instance.Contains(poly, env);      // contains = true

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also