From b659164a0f36ede2daaba83090a431c1fb8d96db Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 19 May 2011 10:30:17 -0400 Subject: [PATCH] Use argparser in maproute.py. --- posts/geoscript/maproute.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/posts/geoscript/maproute.py b/posts/geoscript/maproute.py index 59422be..67c5c2c 100644 --- a/posts/geoscript/maproute.py +++ b/posts/geoscript/maproute.py @@ -14,7 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -""" +"""Print route distances and plot routes on a 2D map. >>> from StringIO import StringIO >>> stream = StringIO('\\n'.join([ @@ -43,6 +43,10 @@ import numpy as _numpy import pylab as _pylab import pyproj as _pyproj + +__version__ = '0.1' + + def read_latlngs(stream): "Read in data from space-separated lat/lng lines with '#' comments." return _numpy.loadtxt(stream) @@ -75,11 +79,20 @@ def plot_route(latlngs, proj=None): lines = _pylab.plot(xs, ys, '.-') if __name__ == '__main__': - import sys + from argparse import ArgumentParser + + p = ArgumentParser( + description=__doc__.splitlines()[0],) + p.add_argument( + '--version', action='version', version='%(prog)s '+__version__) + p.add_argument('coordfiles', metavar='COORDFILE', type=str, nargs='+', + help='Space-separated lat/lng line file') + + args = p.parse_args() _pylab.hold(True) - for filename in sys.argv[1:]: + for filename in args.coordfiles: latlngs = read_latlngs(filename) dist = route_distance(latlngs) print('%s distance: %g m (%g mi)' % (filename, dist, dist/1.6e3)) -- 2.26.2