MiscJunk logo
Page banner

Track Distance

Introduction

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

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.

Usage

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
-85.4014688223,42.6569480118
-85.3969800965,42.6594780209
-85.3817184286,42.6613551245
-85.3644980440,42.6504189560
-85.3864519941,42.6398092404

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

> trkdis test.xyz
-85.4014688223,42.6569480118,0.000000,3.564736
-85.3969800965,42.6594780209,0.287364,3.277372
-85.3817184286,42.6613551245,1.073581,2.491154
-85.3644980440,42.6504189560,2.229712,1.335024
-85.3864519941,42.6398092404,3.564736,0.000000

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.

Notes

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

Last updated: 1 December 2008