Parameters
- geometry1
- The base geometry.
- geometry2
- The comparison geometry.
Return Value
True if the geometry1 contains geometry2.
Exception | Description |
---|---|
System.ArgumentNullException | Either geometry1 or geometry2 or both are null or empty. |
System.NotImplementedException | The method is not implemented for GeometryBag. |
System.InvalidOperationException | Incompatible spatial references between the input geometries. |
If the 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.
// build a polygon List<MapPoint> pts = new List<MapPoint>(); pts.Add(MapPointBuilder.CreateMapPoint(1.0, 1.0)); pts.Add(MapPointBuilder.CreateMapPoint(1.0, 2.0)); pts.Add(MapPointBuilder.CreateMapPoint(2.0, 2.0)); pts.Add(MapPointBuilder.CreateMapPoint(2.0, 1.0)); Polygon poly = PolygonBuilder.CreatePolygon(pts); // test if an inner point is contained MapPoint innerPt = MapPointBuilder.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 = MapPointBuilder.CreateMapPoint(1.25, 1.75); List<MapPoint> innerLinePts = new List<MapPoint>(); innerLinePts.Add(innerPt); innerLinePts.Add(innerPt2); // test an inner polyline Polyline polyline = PolylineBuilder.CreatePolyline(innerLinePts); contains = GeometryEngine.Instance.Contains(poly, polyline); // contains = true // test a line that crosses the boundary MapPoint outerPt = MapPointBuilder.CreateMapPoint(3, 1.5); List<MapPoint> crossingLinePts = new List<MapPoint>(); crossingLinePts.Add(innerPt); crossingLinePts.Add(outerPt); polyline = PolylineBuilder.CreatePolyline(crossingLinePts); contains = GeometryEngine.Instance.Contains(poly, polyline); // contains = false // test a polygon in polygon Envelope env = EnvelopeBuilder.CreateEnvelope(innerPt, innerPt2); contains = GeometryEngine.Instance.Contains(poly, env); // contains = true
Target Platforms: Windows 10, Windows 8.1