source: subversion/applications/routing/pyroute/lib_gpx.py @ 5830

Last change on this file since 5830 was 5830, checked in by ojw, 12 years ago

Load and display GPX tracklogs

File size: 1.8 KB
Line 
1#!/usr/bin/python
2#-----------------------------------------------------------------------------
3# Library for handling GPX files
4#
5# Usage:
6#
7#-----------------------------------------------------------------------------
8# Copyright 2007, Oliver White
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program.  If not, see <http://www.gnu.org/licenses/>.
22#-----------------------------------------------------------------------------
23import os
24import cairo
25
26class lib_gpx:
27  """  """
28  def __init__(self):
29    self.lines = []
30
31  def draw(self,cr,proj):
32    cr.set_line_cap(cairo.LINE_CAP_ROUND)
33    cr.set_source_rgb(0.7,0.7,0)
34    cr.set_line_width(5)
35
36    for l in self.lines:
37      first = 1
38      for p in l:
39        x,y = proj.ll2xy(p[0], p[1])
40        if(first):
41          cr.move_to(x,y)
42          first = 0
43        else:
44              cr.line_to(x,y)
45      cr.stroke()
46     
47  def saveAs(self,filename):
48                file = open(filename,"w")
49                file.write("<?xml version=\"1.0\"?>\n")
50                file.write('<gpx>\n')
51                file.write('<trk>\n')
52                file.write('<name>Sketch</name>\n')
53                for l in self.lines:
54                        file.write('<trkseg>\n')
55                        for p in l:
56                                file.write('<trkpt lat="%f" lon="%f"/>\n'%(p[0], p[1]))
57                        file.write('</trkseg>\n')
58                file.write('</trk>\n')
59                file.write('</gpx>\n')
60
61                file.close()
62   
Note: See TracBrowser for help on using the repository browser.