ArcGIS Pro 2.8 API Reference Guide
Distance Method (GeometryEngine)
Example 

ArcGIS.Core.Geometry Namespace > GeometryEngine Class : Distance Method
The first geometry.
The second geometry.
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
MapPoint pt1 = MapPointBuilder.CreateMapPoint(1.0, 1.0);
MapPoint pt2 = MapPointBuilder.CreateMapPoint(2.0, 2.0);
MapPoint pt3 = MapPointBuilder.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 = MultipointBuilder.CreateMultipoint(multiPts);
d = GeometryEngine.Instance.Distance(pt1, multiPoint);         // d = Math.Sqrt(2)

//
// pt and envelope
//
Envelope env = EnvelopeBuilder.CreateEnvelope(pt1, pt2);
d = GeometryEngine.Instance.Distance(pt1, env);                // d = 0

//
// pt and polyline
//
List<MapPoint> polylinePts = new List<MapPoint>();
polylinePts.Add(MapPointBuilder.CreateMapPoint(2.0, 1.0));
polylinePts.Add(pt2);
Polyline polyline = PolylineBuilder.CreatePolyline(polylinePts);

d = GeometryEngine.Instance.Distance(pt1, polyline);             // d = 1.0

//
// pt and polygon
//
Envelope env2 = EnvelopeBuilder.CreateEnvelope(MapPointBuilder.CreateMapPoint(3.0, 3.0), MapPointBuilder.CreateMapPoint(5.0, 5.0));
Polygon poly = PolygonBuilder.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(MapPointBuilder.CreateMapPoint(4, 3));
polylineList.Add(MapPointBuilder.CreateMapPoint(4, 4));
Polyline polyline2 = PolylineBuilder.CreatePolyline(polylineList);

d = GeometryEngine.Instance.Distance(polyline, polyline2);           // d = Math.Sqrt(5)


//
// polygon and polygon
//
Polygon poly2 = PolygonBuilder.CreatePolygon(env);
d = GeometryEngine.Instance.Distance(poly, poly2);                 // d = Math.Sqrt(2)
Requirements

Target Platforms: Windows 10, Windows 8.1

See Also

Reference

GeometryEngine Class
GeometryEngine Members