ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Geometry Namespace / GeometryEngine Class / Distance Method
The first geometry.
The second geometry.
Example

In This Topic
    Distance Method (GeometryEngine)
    In This Topic
    Measures the planar distance between two geometries.
    Syntax
    Public Function Distance( _
       ByVal geometry1 As Geometry, _
       ByVal geometry2 As Geometry _
    ) As Double

    Parameters

    geometry1
    The first geometry.
    geometry2
    The second geometry.

    Return Value

    The distance between the two input geometries in the same unit as the spatial reference of the input geometries. If either of the input geometries is empty, then NaN is returned.
    Exceptions
    ExceptionDescription
    Either geometry1 or geometry2 or both are null.
    The method is not implemented for GeometryBag.
    Incompatible spatial references between the input geometries.
    Remarks

    GeometryEngine Distance

    Example
    Determine distance between two Geometries
    MapPoint pt1 = MapPointBuilderEx.CreateMapPoint(1.0, 1.0);
    MapPoint pt2 = MapPointBuilderEx.CreateMapPoint(2.0, 2.0);
    MapPoint pt3 = MapPointBuilderEx.CreateMapPoint(4.0, 2.0);
    
    //
    // pt and pt 
    //
    double d = GeometryEngine.Instance.Distance(pt1, pt2);         // d = Math.Sqrt(2)
    
    //
    // pt and multipoint
    //
    List<MapPoint> multiPts = new List<MapPoint>();
    multiPts.Add(pt2);
    multiPts.Add(pt3);
    Multipoint multiPoint = MultipointBuilderEx.CreateMultipoint(multiPts);
    d = GeometryEngine.Instance.Distance(pt1, multiPoint);         // d = Math.Sqrt(2)
    
    //
    // pt and envelope
    //
    Envelope env = EnvelopeBuilderEx.CreateEnvelope(pt1, pt2);
    d = GeometryEngine.Instance.Distance(pt1, env);                // d = 0
    
    //
    // pt and polyline
    //
    List<MapPoint> polylinePts = new List<MapPoint>();
    polylinePts.Add(MapPointBuilderEx.CreateMapPoint(2.0, 1.0));
    polylinePts.Add(pt2);
    Polyline polyline = PolylineBuilderEx.CreatePolyline(polylinePts);
    
    d = GeometryEngine.Instance.Distance(pt1, polyline);             // d = 1.0
    
    //
    // pt and polygon
    //
    Envelope env2 = EnvelopeBuilderEx.CreateEnvelope(MapPointBuilderEx.CreateMapPoint(3.0, 3.0), MapPointBuilderEx.CreateMapPoint(5.0, 5.0));
    Polygon poly = PolygonBuilderEx.CreatePolygon(env2);
    d = GeometryEngine.Instance.Distance(pt1, poly);                 // d = Math.Sqrt(8)
    
    //
    // envelope and polyline
    //
    d = GeometryEngine.Instance.Distance(env, polyline);             // d = 0
    
    //
    // polyline and polyline
    //
    List<MapPoint> polylineList = new List<MapPoint>();
    polylineList.Add(MapPointBuilderEx.CreateMapPoint(4, 3));
    polylineList.Add(MapPointBuilderEx.CreateMapPoint(4, 4));
    Polyline polyline2 = PolylineBuilderEx.CreatePolyline(polylineList);
    
    d = GeometryEngine.Instance.Distance(polyline, polyline2);           // d = Math.Sqrt(5)
    
    
    //
    // polygon and polygon
    //
    Polygon poly2 = PolygonBuilderEx.CreatePolygon(env);
    d = GeometryEngine.Instance.Distance(poly, poly2);                 // d = Math.Sqrt(2)
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also