ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Core.Geometry Namespace / IGeometryEngine Interface / Difference Method
the Geometry instance on the left hand side of the subtraction.
the Geometry on the right hand side being subtracted.
Example

In This Topic
    Difference Method (IGeometryEngine)
    In This Topic
    Performs the topological difference operation on the two geometries.
    Syntax
    Function Difference( _
       ByVal geometry1 As Geometry, _
       ByVal geometry2 As Geometry _
    ) As Geometry

    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 geometry1.
    Exceptions
    ExceptionDescription
    Either geometry1 or geometry2 or both are null or empty.
    The method is not implemented for GeometryBag.
    Incompatible spatial references between the input geometries.
    Remarks

    GeometryEngine Difference

    Example
    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
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also