Click or drag to resize

DistanceGetHaversineDistance Method (CoordinateReferenceSystem, Double, Double, Double, Double)

Extension method that calculates the haversine distance between to points using a specific coordinate reference system.

Namespace:  Ptv.Components.Projections
Assembly:  Ptv.Components.Projections (in Ptv.Components.Projections.dll) Version: 1.7.10.0
Syntax
public static double GetHaversineDistance(
	this CoordinateReferenceSystem crs,
	double x0,
	double y0,
	double x1,
	double y1
)

Parameters

crs
Type: Ptv.Components.ProjectionsCoordinateReferenceSystem
Coordinate reference system
x0
Type: SystemDouble
X-coordinate of first point
y0
Type: SystemDouble
Y-coordinate of first point
x1
Type: SystemDouble
X-coordinate of second point
y1
Type: SystemDouble
Y-coordinate of second point

Return Value

Type: Double
Haversine distance in [km].

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type CoordinateReferenceSystem. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Remarks
This extension has been provided for convenience reasons only. It is good enough for single coordinates but should be used in batch processing scenarios where performance is an issue. On each call this extension method gets a coordinate transformation for transforming from the specified CRS to EPSG:4326, transforms the specified coordinates to EPSG:4326 and finally uses the transformed coordinates with the default, lon/lat based haversine distance calculation. When it comes to mass-calculations it is recommended to cache and re-use any coordinate transformation necessary by the client thus avoid per coordinate transformation lookups.
Examples
double d_Frankfurt_Berlin = CoordinateReferenceSystem.XServer.PTV_MERCATOR.GetHaversineDistance(965820, 6458402, 1489888, 6883432);
See Also