MiscJunk logo
Page banner

Track Distance


When creating maps for others to use it is sometimes helpful to provide descriptions such as "After 5.4 miles you will see the trail head on the right." Determining the distance along a long, non-linear track can be difficult if your favorite GIS tools don't have that functionality. The Track Distance (TrkDis) utility calculates a running distance total from each end and appends the values to each point within the track.


Download the TrkDis utility and place the executable file in any convenient location. Putting the executable in a directory that is within your system PATH will allow the utility to be executed from any directory.


The utility takes a CSV file (longitude,latitude) of a track as input and calculates the running distance total from each end. These values are appended to the original point values and output in CSV format to STDOUT. Here is a sample input file:

> type test.xyz

Running the utility with the input file produces the following output:

> trkdis test.xyz

The utility defaults to calculating distances in miles. Options are provided to specify the unit of distance to be feet, kilometers or meters - run the utility with no parameters to display the full program usage.


The calculation used (Haversine formula) assumes a perfect (spherical) earth but seems accurate enough for this purpose.

Last updated: 1 December 2008