1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin gpx n 0.9]
[keywords gps]
[keywords gpx]
[copyright {2010, Keith Vetter <kvetter@gmail.com>}]
[moddesc {GPS eXchange Format (GPX)}]
[titledesc {Extracts waypoints, tracks and routes from GPX files}]
[category {File formats}]
[require Tcl 8.5]
[require gpx [opt 0.9]]
[description]
[para]
This module parses and extracts waypoints, tracks, routes and
metadata from a GPX (GPS eXchange) file. Both GPX version 1.0
and 1.1 are supported.
[section {COMMANDS}]
[list_begin definitions]
[call [cmd "::gpx::Create"] [arg gpxFilename] [opt [arg "rawXML"]]]
The [cmd ::gpx::Create] is the first command called to process GPX
data. It takes the GPX data from either the [arg rawXML]
parameter if present or from the contents of [arg gpxFilename],
and parses it using [emph tdom]. It returns a token value that is used
by all the other commands.
[call [cmd "::gpx::Cleanup"] [arg token]]
This procedure cleans up resources associated with [arg token].
It is [emph strongly] recommended that you call this
function after you are done with a given GPX file.
Not doing so will result in memory not being freed, and
if your app calls [cmd ::gpx::Create] enough times, the
memory leak could cause a performance hit...or worse.
[call [cmd ::gpx::GetGPXMetadata] [arg token]]
This procedure returns a dictionary of the metadata
associated with the GPX data identified by [arg token].
The format of the metadata dictionary is described
below, but keys [emph version] and [emph creator]
will always be present.
[call [cmd ::gpx::GetWaypointCount] [arg token]]
This procedure returns the number of waypoints defined in the GPX
data identified by [arg token].
[call [cmd ::gpx::GetAllWaypoints] [arg token]]
This procedure returns the a list of waypoints defined in the GPX
data identified by [arg token]. The format of each waypoint item
is described below.
[call [cmd ::gpx::GetTrackCount] [arg token]]
This procedure returns the number of tracks defined in the GPX
data identified by [arg token].
[call [cmd ::gpx::GetTrackMetadata] [arg token] [arg whichTrack]]
This procedure returns a dictionary of the metadata
associated track number [arg whichTrack] (1 based) in
the GPX data identified by [arg token].
The format of the metadata dictionary is described below.
[call [cmd ::gpx::GetTrackPoints] [arg token] [arg whichTrack]]
The procedure returns a list of track points comprising track
number [arg whichTrack] (1 based) in the GPX data identified by
[arg token]. The format of the metadata dictionary is described below.
[call [cmd ::gpx::GetRouteCount] [arg token]]
This procedure returns the number of routes defined in the GPX
data identified by [arg token].
[call [cmd ::gpx::GetRouteMetadata] [arg token] [arg whichRoute]]
This procedure returns a dictionary of the metadata
associated route number [arg whichRoute] (1 based) in
the GPX data identified by [arg token].
The format of the metadata dictionary is described below.
[call [cmd ::gpx::GetRoutePoints] [arg token] [arg whichRoute]]
The procedure returns a list of route points comprising route
number [arg whichRoute] (1 based) in the GPX data identified by
[arg token]. The format of the metadata dictionary is described below.
[list_end]
[section "DATA STRUCTURES"]
[list_begin definitions]
[def "metadata dictionary"]
The metadata associated with either the GPX document, a
track, a route, a waypoint, a track point or route
point is returned in a dictionary. The keys of that
dictionary will be whatever optional GPX elements are
present. The value for each key depends on the GPX schema
for that element. For example, the value for a version
key will be a string, while for a link key will be
a sub-dictionary with keys [emph href] and optionally
[emph text] and [emph type].
[def "point item"]
Each item in a track or route list of points consists of
a list of three elements: [emph latitude], [emph longitude] and
[emph "metadata dictionary"]. [emph Latitude] and [emph longitude]
are decimal numbers. The [emph "metadata dictionary"] format is
described above. For points in a track, typically there will
always be ele (elevation) and time metadata keys.
[list_end]
[section "EXAMPLE"]
[example {
% set token [::gpx::Create myGpxFile.gpx]
% set version [dict get [::gpx::GetGPXMetadata $token] version]
% set trackCnt [::gpx::GetTrackCount $token]
% set firstPoint [lindex [::gpx::GetTrackPoints $token 1] 0]
% lassign $firstPoint lat lon ptMetadata
% puts "first point in the first track is at $lat, $lon"
% if {[dict exists $ptMetadata ele]} {
puts "at elevation [dict get $ptMetadata ele] meters"
}
% ::gpx::Cleanup $token
}]
[section "REFERENCES"]
[list_begin enumerated]
[enum]
GPX: the GPS Exchange Format
([uri http://www.topografix.com/gpx.asp])
[enum]
GPX 1.1 Schema Documentation ([uri http://www.topografix.com/GPX/1/1/])
[enum]
GPX 1.0 Developer's Manual ([uri http://www.topografix.com/gpx_manual.asp])
[list_end]
[section AUTHOR]
Keith Vetter
[vset CATEGORY gpx]
[include ../doctools2base/include/feedback.inc]
[manpage_end]
|