Great Circle Distance Perl script

A Perl script to calculate the Great Circle Distances between a matrix of points


Great Circle Menu
Map & Calculator
Alternate Map sizes
Formula
Java API
Spreadsheet
Perl script
What is a
Great Circle?
Help Us
Sponsorship Info
Statistics



 

Here is a perl script that takes a text file containing a number of location co-ordinates and outputs a matrix of the distances between every point.

Perl (www.perl.org) is a popular scripting language, if you have access to a Unix system then it's likely to already have a Perl interpreter, and you can likely run this script on that system without further ado. Perl is free, available for most systems, and if you don't have it you can download it here

The script was written using perl 5.004 (MS Windows download), though it should work with other versions. It still needs some work doing to it, but even so I hope it will prove useful to somebody. You can open it in any text editor, by-the-way.

Using the Script

The format of the text file is such that each line in the file contains a single point thus
[ Commas and spaces marked ^SP are significant ]
   location,locationid,deg min [N/S], deg min [E/W]
^SP ^SP ^SP ^SP
location is a string which will be used when outputting the matrix
locationid is a arbitrary number, not currently used
deg  are the degrees of latitude or longitude
deg  are the minutes of latitude or longitude

N/S Indicates whether the latitude is North or South of the equator.
E/W Indicates whether the latitude is East or West of the Greenwich meridian.
Note these two fields are case sensitive. In fact any values other than "S" or "W" will be silently taken as North and East respectively.

Format errors will cause the script to exit immediately, with the offending line number indicated. There is no range checking performed.  Values can be floating point ( aka "decimals" ).

All distances are in Kilometres, because that's what the rest of the world uses - sorry Yanks.

Example: An input file containing
Armenia,9,40 00 N, 45 00 E
Poland,152,52 00 N, 20 00 E
Sweden,179,62 00 N, 15 00 E
Turkey,189,39 00 N, 35 00 E

Will yield a CSV producing a matrix thus;

Armenia Poland Sweden Turkey
Armenia 0 2328.3 3166.6 864.7
Poland 2328.3 0 1151.6 1851.5
Sweden 3166.6 1151.6 0 2895.3
Turkey 864.7 1851.5 2895.3 0

Download the script .

Download the sample input file

Great Circle visitor counter
total hits on all pages in section
(since 01/01/04)



Home Thai Guide   Great Circle Calculator WorldClock AMS Services Contact us