source: subversion/applications/routing/pyroute-dev/routeAsGpx.py @ 34690

Last change on this file since 34690 was 18455, checked in by buerste, 10 years ago

-remove BOM
-fix version strings

  • Property svn:keywords set to Rev
File size: 2.3 KB
Line 
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3
4"""routeAsOsm - routes within an OSM file, and generates a
5GPX file containing the result
6
7Usage:
8        routeAsGpx.py [input OSM file] [start node] [end node] [transport] [description]
9"""
10
11__version__ = "$Rev: 18455 $"[1:-2]
12__license__ = """This program is free software: you can redistribute it and/or modify
13it under the terms of the GNU General Public License as published by
14the Free Software Foundation, either version 3 of the License, or
15(at your option) any later version.
16
17This program is distributed in the hope that it will be useful,
18but WITHOUT ANY WARRANTY; without even the implied warranty of
19MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20GNU General Public License for more details.
21
22You should have received a copy of the GNU General Public License
23along with this program. If not, see <http://www.gnu.org/licenses/>."""
24_debug = 0
25
26
27from route import *
28
29def routeToGpx(nodeList, osmData, description=""):
30        """Format a route (as list of nodes) into a GPX file"""
31
32        output = ''
33        output = output + "<?xml version='1.0'?>\n";
34
35        output = output + "<gpx version='1.1' creator='pyroute' xmlns='http://www.topografix.com/GPX/1/1' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'>\n"
36
37        output = output + " <rte>\n"
38        output = output + "  <name>%s</name>\n" % description
39
40        count = 0;
41        for i in nodeList:
42                output = output + "   <rtept lat='%f' lon='%f'>\n" % ( \
43                        osmData.nodes[i][0],
44                        osmData.nodes[i][1])
45                output = output + "    <name>%d</name>\n" % count
46                output = output + "   </rtept>\n"
47                count = count + 1
48        output = output + " </rte>\n</gpx>\n"
49
50        return(output)
51
52if __name__ == "__main__":
53        try:
54                # Load data
55                data = LoadOsm(sys.argv[1])
56
57                # Do routing
58                router = Router(data)
59                result, route = router.doRoute(int(sys.argv[2]), int(sys.argv[3]), sys.argv[4])
60
61                # Display result
62                if result == 'success':
63                        print routeToGpx(route, data, sys.argv[5])
64                else:
65                        sys.stderr.write("Failed (%s)" % result)
66
67        except IndexError:
68                # Not enough argv[]s
69                sys.stderr.write("Usage: routeAsGpx.py [OSM file] [from node] [to node] [transport method] [description]\n")
Note: See TracBrowser for help on using the repository browser.