Within Method (IGeometryEngine)
Returns true if geometry1 is within geometry2.
Parameters
- geometry1
- The base geometry.
- geometry2
- The comparison geometry.
Return Value
True if geometry1 is within geometry2.
MapPoints, Polylines, Polygons within Polygon
// 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);
// an inner point
MapPoint innerPt = MapPointBuilderEx.CreateMapPoint(1.5, 1.5);
bool within = GeometryEngine.Instance.Within(innerPt, poly); // within = true
// point on a boundary
within = GeometryEngine.Instance.Within(pts[0], poly); // within = false
// an interior line
MapPoint innerPt2 = MapPointBuilderEx.CreateMapPoint(1.25, 1.75);
List<MapPoint> innerLinePts = new List<MapPoint>();
innerLinePts.Add(innerPt);
innerLinePts.Add(innerPt2);
Polyline polyline = PolylineBuilderEx.CreatePolyline(innerLinePts);
within = GeometryEngine.Instance.Within(polyline, poly); // within = true
// a line that crosses the boundary
MapPoint outerPt = MapPointBuilderEx.CreateMapPoint(3, 1.5);
List<MapPoint> crossingLinePts = new List<MapPoint>();
crossingLinePts.Add(innerPt);
crossingLinePts.Add(outerPt);
polyline = PolylineBuilderEx.CreatePolyline(crossingLinePts);
within = GeometryEngine.Instance.Within(polyline, poly); // within = false
// polygon in polygon
Envelope env = EnvelopeBuilderEx.CreateEnvelope(innerPt, innerPt2);
within = GeometryEngine.Instance.Within(env, poly); // within = true
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.