﻿ Distance Method (GeometryEngine)—ArcGIS Pro
ArcGIS Pro 3.3 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 double Distance(
Geometry geometry1,
Geometry geometry2
)```
```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

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>();
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>();
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>();
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.