Returns the distance between two geometries which have the same CoordinateSystem.

Namespace:  ESRI.ArcGISExplorer.Geometry

Assembly:  ESRI.ArcGISExplorer (in ESRI.ArcGISExplorer.dll) Version: 2.0.0.1500 (2.0.0.1500)

Syntax

C#
public static double DistanceBetween(
	Geometry geometryA,
	Geometry geometryB
)
Visual Basic (Declaration)
Public Shared Function DistanceBetween ( _
	geometryA As Geometry, _
	geometryB As Geometry _
) As Double

Parameters

geometryA
Type: ESRI.ArcGISExplorer.Geometry..::.Geometry

A geometry to measure distance from.
geometryB
Type: ESRI.ArcGISExplorer.Geometry..::.Geometry

A geometry to measure distance to.

Return Value

The distance between geometryA and geometryB, in the Units of the CoordinateSystem.

Remarks

This method returns the distance between any two geometries that have the same CoordinateSystem.

If the input geometries have a geographic CoordinateSystem, then the distance returned will be in the angular units of the Geometry - therefore note the following.

If a Geometry has a geographic coordinate system (which has angular units), measurements based on this Geometry, for example length, area, and distances, are not coherent values; 1 degree of latitude varies slightly, and 1 degree of longitude varies greatly between the equator and the poles. For example, if you were to compare the Length of two polylines representing two roads in different locations on the earth to find out which was the shorter distance to drive, you would need to get distance in linear units in order to get a comparable measurement and find out which one is really the shortest; a distance in angular units could be misleading.

This method does not account for the curvature of the earths surface; see the GeodesicUtilities.DistanceBetween method for an alternative which does account for this.

Examples

The code below demonstrates how to find the distance between two different types of geometry using the GeometryOperations class, by creating a Multipoint representing New Zealand's largest cities, and a Polyline representing the line of 180 degrees longitude, both using the New Zealand Map Grid coordinate system. The code also you have a using statement for the Geometry namespace.
CopyC#
// Create a Multipoint containing New Zealands largest cities, using the New Zealand map grid coordinate system
CoordinateSystem nzng = CoordinateSystem.ProjectedCoordinateSystems.NationalGrids.NewZealand.NewZealandMapGrid;
Multipoint mp = new ESRI.ArcGISExplorer.Geometry.Multipoint(new ESRI.ArcGISExplorer.Geometry.Point[] {
  new ESRI.ArcGISExplorer.Geometry.Point(2670907, 6477145), // Aukland
  new ESRI.ArcGISExplorer.Geometry.Point(2689846, 5997385), // Wellington
  new ESRI.ArcGISExplorer.Geometry.Point(2484448, 5739788), // Christchurch
  new ESRI.ArcGISExplorer.Geometry.Point(2315727, 5480117) }, // Dunedin
    nzng);

// Create a Polyline of the line at 180 degrees west near to New Zealand, using the New Zealand map grid coordinate system
Polyline pl = new Polyline(new ESRI.ArcGISExplorer.Geometry.Point[] {
  new ESRI.ArcGISExplorer.Geometry.Point(3013619, 4998369), new ESRI.ArcGISExplorer.Geometry.Point(3062490, 5555068), 
  new ESRI.ArcGISExplorer.Geometry.Point(3107286, 6110532), new ESRI.ArcGISExplorer.Geometry.Point(3149965, 6664308), 
  new ESRI.ArcGISExplorer.Geometry.Point(3191364, 7223210)}, nzng);

// Get the distance between the geometries
double dist = GeometryOperations.DistanceBetween(pl, mp);

// Report the distance and units.
string distBetween = string.Format("Distance between New Zealand major cities and 180 degrees west is {0} {1}", String.Format("{0:0}", dist),
    pl.CoordinateSystem.Unit.GetPluralName(UnitNameOptions.Simple));
CopyVB.NET
' Create a Multipoint containing New Zealands largest cities, using the New Zealand map grid coordinate system
Dim nzng As CoordinateSystem = CoordinateSystem.ProjectedCoordinateSystems.NationalGrids.NewZealand.NewZealandMapGrid
Dim mp As Multipoint = New ESRI.ArcGISExplorer.Geometry.Multipoint(New ESRI.ArcGISExplorer.Geometry.Point() { _
  New ESRI.ArcGISExplorer.Geometry.Point(2670907, 6477145), _
  New ESRI.ArcGISExplorer.Geometry.Point(2689846, 5997385), _
  New ESRI.ArcGISExplorer.Geometry.Point(2484448, 5739788), _
  New ESRI.ArcGISExplorer.Geometry.Point(2315727, 5480117)}, nzng)

' Create a Polyline of the line at 180 degrees west near to New Zealand, using the New Zealand map grid coordinate system
Dim pl As Polyline = New Polyline(New ESRI.ArcGISExplorer.Geometry.Point() { _
  New ESRI.ArcGISExplorer.Geometry.Point(3013619, 4998369), New ESRI.ArcGISExplorer.Geometry.Point(3062490, 5555068), _
  New ESRI.ArcGISExplorer.Geometry.Point(3107286, 6110532), New ESRI.ArcGISExplorer.Geometry.Point(3149965, 6664308), _
  New ESRI.ArcGISExplorer.Geometry.Point(3191364, 7223210)}, nzng)

' Get the distance between the geometries
Dim dist As Double = GeometryOperations.DistanceBetween(pl, mp)

' Report the distance and units.
Dim distBetween As String = String.Format("Distance between New Zealand major cities and 180 degrees west is {0} {1}", _
                     String.Format("{0:0}", dist), pl.CoordinateSystem.Unit.GetPluralName(UnitNameOptions.Simple))

Exceptions

ExceptionCondition
System..::.ArgumentExceptionBoth geometries must have the same CoordinateSystem.

See Also