[GIS] Haversine formula to calculate distance between real coordinates

arcgis-10.0coordinate systemcoordinatesdistancekriging

I need to calculate distance between two stations in a map in order to calculate empirical variogram in ordinary kriging to interpolate temperature data.

Calculating distance in kriging using Euclidean distance formula between two points on XY axes, and I found that not sufficient because I specified Lag_units and Lag_distance in meters when I programmed kriging.

Can I use the haversine formula to calculate distance between real coordinates instead of Euclidean distance?

Best Answer

What you're looking into is measuring a distance on google maps. Unfortunatly, this is not a question to which an easy answer can be given, but you might consider one of these ways :

  1. The least accurate way : the haversin formula ,
  2. Ellipsoidal Earth projected to a plane formula (since Google Maps is based on a Mercator projection and a WGS84 Datum, this formula may yield better results if you succeed in putting it into an algorithm),
  3. The cleanest of ways, which will yield the best results, is to reproject your map into a local coordinate system (CS) and then mesure the distance on it ;

Let me now focus on this last bullet : google maps uses a coordinate system called "Pseudo Mercator" or "Web Mercator" which have the code EPSG:3857, I live in Morocco, so the coordinate system I should use is EPSG:32630, depending on where you live, you should pick a convenient coordinate system for accurate results. Once you pick your coordinate system, your should look for a the mathematical tranformation between EPSG:3857 and EPSG:XXXXX (your local CS) or leave it to a third party library to carry such transformation (depends on which tools you're using).

Edit : just forgot to mention that if you want a third party library that can handle tranformations, look up Proj4 or PROJ4NET for C# programming.