Difference Method (GeometryEngine)
Parameters
- geometry1
- the Geometry instance on the left hand side of the subtraction.
- geometry2
- the Geometry on the right hand side being subtracted.
Return Value
Returns the result of subtraction. The result has the dimension of If either of the input geometries are empty, then is returned unchanged.
Difference between two Polygons
List<MapPoint> polyPts = new List<MapPoint>();
polyPts.Add(MapPointBuilderEx.CreateMapPoint(3.0, 2.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(3.0, 6.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(6.0, 6.0));
polyPts.Add(MapPointBuilderEx.CreateMapPoint(6.0, 2.0));
Polygon poly1 = PolygonBuilderEx.CreatePolygon(polyPts);
Envelope env = EnvelopeBuilderEx.CreateEnvelope(MapPointBuilderEx.CreateMapPoint(1.0, 1.0), MapPointBuilderEx.CreateMapPoint(4, 4));
Polygon poly2 = PolygonBuilderEx.CreatePolygon(env);
Geometry result = GeometryEngine.Instance.Difference(poly1, poly2);
Polygon polyResult = result as Polygon;
// polyResult.Area = 10.0
result = GeometryEngine.Instance.Difference(poly2, poly1);
polyResult = result as Polygon;
// polyResult.Area = 7.0
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.