How to calculate the great circle distance between two points on Earth with the Haversine formula in Spotfire

How to calculate the great circle distance between two points on Earth with the Haversine formula in Spotfire

book

Article ID: KB0070531

calendar_today

Updated On:

Products Versions
Spotfire Analyst All

Description

The haversine formula is an equation important in navigation, giving great-circle distances between two points on a sphere from their longitudes and latitudes. This can be calculated in Spotfire with the use of custom expressions when given the latitude and longitude of two points on Earth.

Resolution

Custom Expression of Haversine formula:
2 * 6371 * ASin(Sqrt((
Sin(([lat2 (radians)] - [lat1 (radians)]) / 2) * Sin(([lat2 (radians)] - [lat1 (radians)]) / 2)) + (Cos([lat1 (radians)]) * Cos([lat2 (radians)]) * Sin(([long2 (radians)] - [long1 (radians)]) / 2) * Sin(([long2 (radians)] - [long1 (radians)]) / 2))))

 

Required Input Columns:

  • lat1 (radians) - latitutide of point 1
  • long1 (radians) - longitude of point 1
  • lat2 (radians) - latitutide of point 2
  • long2 (radians) - longitude of point 2

 

Example:

See attached (Filename: Great Circle Distance between 2 points on earth with the Haversine Formula.dxp).


For TIBCO Spotfire versions 7.0 and higher:
The GreatCircleDistance() distance function was introduced in version 7.0 which greatly simplifies the calculation of the great circle distance between 2 points. See:

Issue/Introduction

How to calculate the great circle distance between two points on Earth with the Haversine Formula in Spotfire

Additional Information

URL: http://en.wikipedia.org/wiki/Haversine_formula

Formula:

d  = 2 r \arcsin\left(\sqrt{\sin^2\left(\frac{\phi_2 - \phi_1}{2}\right) + \cos(\phi_1) \cos(\phi_2)\sin^2\left(\frac{\lambda_2 - \lambda_1}{2}\right)}\right)

Details:

  • d is the distance between the two points (along a great circle of the sphere; see spherical distance),
  • r is the radius of the earth = 6367.46km (Note: not perfect sphere therefore cannot be guaranteed correct to better than 0.5%).
  • \phi_1, \phi_2: latitude of point 1 and latitude of point 2.
  • \lambda_1, \lambda_2: longitude of point 1 and longitude of point 2.
  • Longtitude and Latitude are measured in in radians (note that ? and ? can be converted from degrees to radians by multiplying by ?/180 as usual).

Attachments

How to calculate the great circle distance between two points on Earth with the Haversine formula in Spotfire get_app