Show / Hide Table of Contents

Method Distance

Distance(Geometry, Geometry)

Measures the simple Euclidean distance between two geometries. This is a planar measurement using 2D Cartesian mathematics to calculate the distance in the same coordinate space as the inputs. Use DistanceGeodetic(MapPoint, MapPoint, LinearUnit?, AngularUnit?, GeodeticCurveType) for geodetic measurement.

Declaration
public static double Distance(this Geometry geometry1, Geometry geometry2)
Parameters
Type Name Description
Geometry geometry1

The first geometry.

Geometry geometry2

The second geometry.

Returns
Type Description
double

The distance between the two geometries in the same units as the geometry's spatial reference. If one or both of the geometries is empty, returns NaN.

Remarks

Planar measurements of distance and area can be extremely inaccurate if using an unsuitable spatial reference. Ensure that you understand the potential for error with the geometry's spatial reference. If you need to calculate more accurate results consider using a different spatial reference, or using the geodetic equivalent, DistanceGeodetic(MapPoint, MapPoint, LinearUnit?, AngularUnit?, GeodeticCurveType). See the document Spatial References for more information about spatial references.

This distance calculation is based upon the SpatialReference of the input geometries. Although some projections are better than others for preserving distance, it will always be distorted in some areas of the map. Distortion may be negligible for large scale maps (small areas) that use a suitable map projection.

Exceptions
Type Condition
ArgumentException

Indicates that geometry1 and geometry2 do not have equivalent spatial references.

NotImplementedException

True curve geometries can only be used if the other input geometry is a MapPoint.

Applies to

Platforms and versions
TargetVersions
.NET Standard 2.0100.3 - 200.8
.NET100.13 - 300.0
.NET Windows100.13 - 300.0
.NET Android200.0 - 300.0
.NET iOS200.0 - 300.0
.NET Framework100.0 - 200.8
Xamarin.Android100.0 - 100.15
Xamarin.iOS100.0 - 100.15
UWP100.0 - 200.8
In this article
Provide feedback
Back to top Copyright © 2025 Esri.