Module edist
[hide private]
[frames] | no frames]

Module edist

edist - Simple command line coordinate processing.

edist operates on one, or more, locations specified in the following format [+-]DD.DD;[+-]DDD.DD. For example, a location string of 52.015;-0.221 would be interpreted as 52.015 degrees North by 0.221 degrees West. Positive values can be specified with a + prefix, but it isn't required.

For example:

$ ./edist.py --sunrise --sunset --ascii '52.015;-0.221'
$ ./edist.py --destination 20@45 -- '-52.015;0.221'

In the second example the locations are separated by '--', which stops processing options and allows you to specify locations beginning with a hyphen(such as anywhere in the Southern hemisphere).


Note: In most shells the locations must be quoted because of the special nature of the semicolon.

Version: 0.11.0

Author: James Rowe

Copyright: Copyright (C) 2007-2008 James Rowe

Status: WIP

License: GNU General Public License Version 3

Classes [hide private]
  LocationsError
Error object for data parsing error
  NumberedPoint
Class for representing locations from command line
  NumberedPoints
Class for representing a group of NumberedPoint objects
Functions [hide private]
tuple of list, dict and list
process_command_line()
Main command line interface
dict
read_locations(filename)
Pull locations from a user's config file
tuple of dict and list
read_csv(filename)
Pull locations from a user's CSV file
int
main()
Main script handler
Variables [hide private]
  USAGE = '%prog operates on one, or more, locations specified i...
Function Details [hide private]

process_command_line()

 

Main command line interface

>>> saved_args = sys.argv[1:]
>>> sys.argv[1:] = ["-p", "52.015;-0.221"]
>>> modes, opts, args = process_command_line()
>>> modes, args
(['display'], ['52.015;-0.221'])
>>> sys.argv[1:] = ["-d", "-b", "52.015;-0.221", "52.168;0.040"]
>>> modes, opts, args = process_command_line()
>>> modes, args
(['distance', 'bearing'], ['52.015;-0.221', '52.168;0.040'])
>>> sys.argv[1:] = saved_args
Returns: tuple of list, dict and list
Modes, options, list of locations as str objects

read_locations(filename)

 
Pull locations from a user's config file
Parameters:
  • filename (str) - Config file to parse
Returns: dict
List of locations from config file

read_csv(filename)

 

Pull locations from a user's CSV file

Read gpsbabel's CSV output format

>>> locations, names = read_csv(open("gpsbabel"))
>>> sorted(locations.items())
[('01:My place', ('52.01500', '-0.22100')),
 ('02:Microsoft Research Cambridge', ('52.16700', '00.39000'))]
>>> names
['01:My place', '02:Microsoft Research Cambridge']
Parameters:
  • filename (str) - CSV file to parse (STDIN if '-')
Returns: tuple of dict and list
list of locations as str objects

main()

 

Main script handler

>>> saved_args = sys.argv[1:]
>>> sys.argv[1:] = ["-p", "52.015;-0.221"]
>>> main()
Location 1 is 52°00′54″N, 000°13′15″W
>>> sys.argv[1:] = ["-s", "22@40", "52.015;-0.221"]
>>> main()
Destination from location 1 is 52°09′59″N, 000°00′48″W
>>> sys.argv[1:] = saved_args
Returns: int
0 for success, >1 error code

Variables Details [hide private]

USAGE

Value:
'''%prog operates on one, or more, locations specified in the followin\
g format
``[+-]DD.DD;[+-]DDD.DD``.  For example, a location string of ``52.015;\
-0.221``
would be interpreted as 52.015 degrees North by 0.221 degrees West.  P\
ositive
values can be specified with a ``+`` prefix, but it isn\'t required.''\
'