File: drv_gpx.html

package info (click to toggle)
gdal 1.10.1+dfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 84,320 kB
  • ctags: 74,726
  • sloc: cpp: 677,199; ansic: 162,820; python: 13,816; cs: 11,163; sh: 10,446; java: 5,279; perl: 4,429; php: 2,971; xml: 1,500; yacc: 934; makefile: 494; sql: 112
file content (290 lines) | stat: -rw-r--r-- 12,333 bytes parent folder | download
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<html>
<head>
<title>GPX - GPS Exchange Format</title>
</head>

<body bgcolor="#ffffff">

<h1>GPX - GPS Exchange Format</h1>

(Starting with GDAL 1.5.0)<p>

GPX (the GPS Exchange Format) is a light-weight XML data format for the interchange of GPS data (waypoints, routes, and tracks) between applications and Web services on the Internet.<p>

OGR has support for GPX reading (if GDAL is build with <i>expat</i> library support) and writing.<p>

Version supported are GPX 1.0 and 1.1 for reading, GPX 1.1 for writing.<p>

The OGR driver supports reading and writing of all the GPX feature types :
<ul>
<li><i>waypoints</i> : layer of features of OGR type wkbPoint</li>
<li><i>routes</i> : layer of features of OGR type wkbLineString</li>
<li><i>tracks</i> : layer of features of OGR type wkbMultiLineString</li>
</ul>

It also supports reading of route points and track points in standalone layers (<i>route_points</i> and <i>track_points</i>), so
that their own attributes can be used by OGR.<p>

In addition to its GPX attributes, each route point of a route has a <i>route_fid</i>
(foreign key to the FID of its belonging route)
and a <i>route_point_id</i> which is its sequence number in the route.<br>
The same applies for track points with <i>track_fid</i>, <i>track_seg_id</i> and <i>track_seg_point_id</i>.

All coordinates are relative to the WGS84 datum (EPSG:4326).<p>

If the environment variable GPX_ELE_AS_25D is set to YES, the elevation element will
be used to set the Z coordinates of waypoints, route points and track points.<p>

The OGR/GPX reads and writes the GPX attributes for the waypoints, routes and tracks.<p>

By default, up to 2 <i>&lt;link&gt;</i> elements can be taken into account by feature.
This default number can be changed with the GPX_N_MAX_LINKS environment variable.<p>

<h2>Encoding issues</h2>

Expat library supports reading the following built-in encodings :
<ul>
<li>US-ASCII</li>
<li>UTF-8</li>
<li>UTF-16</li>
<li>ISO-8859-1</li>
</ul>

OGR 1.8.0 adds supports for Windows-1252 encoding (for previous versions, altering the encoding
mentionned in the XML header to ISO-8859-1 might work in some cases).<p>

The content returned by OGR will be encoded in UTF-8, after the conversion from the
encoding mentionned in the file header is.<p>

If your GPX file is not encoded in one of the previous encodings, it will not be parsed by the
GPX driver. You may convert it into one of the supported encoding with the <i>iconv</i> utility
for example and change accordingly the <i>encoding</i> parameter value in the XML header.<br>
<p>

When writing a GPX file, the driver expects UTF-8 content to be passed in.<p>

<h2>Extensions element reading</h2>

If the <i>&lt;extensions&gt;</i> element is detected in a GPX file, OGR will expose the content
of its sub elements as fields. Complex content of sub elements will be exposed as an XML blob.
<p>
The following sequence GPX content :
<pre>
    &lt;extensions&gt;
        &lt;navaid:name&gt;TOTAL RF&lt;/navaid:name&gt;
        &lt;navaid:address&gt;BENSALEM&lt;/navaid:address&gt;
        &lt;navaid:state&gt;PA&lt;/navaid:state&gt;
        &lt;navaid:country&gt;US&lt;/navaid:country&gt;
        &lt;navaid:frequencies&gt;
        &lt;navaid:frequency type="CTAF" frequency="122.900" name="CTAF"/&gt;
        &lt;/navaid:frequencies&gt;
        &lt;navaid:runways&gt;
        &lt;navaid:runway designation="H1" length="80" width="80" surface="ASPH-G"&gt;
        &lt;/navaid:runway&gt;
        &lt;/navaid:runways&gt;
        &lt;navaid:magvar&gt;12&lt;/navaid:magvar&gt;
    &lt;/extensions&gt;
</pre>
will be interpreted in the OGR SF model as :
<pre>
  navaid_name (String) = TOTAL RF
  navaid_address (String) = BENSALEM
  navaid_state (String) = PA
  navaid_country (String) = US
  navaid_frequencies (String) = &lt;navaid:frequency type="CTAF" frequency="122.900" name="CTAF" &gt;&lt;/navaid:frequency&gt;
  navaid_runways (String) = &lt;navaid:runway designation="H1" length="80" width="80" surface="ASPH-G" &gt;&lt;/navaid:runway&gt;
  navaid_magvar (Integer) = 12
</pre>
<p><br>
Note : the GPX driver will output content of the extensions element only if it is found in the first records of the GPX file.
If extensions appear later, you can force an explicit parsing of the whole file with the <b>GPX_USE_EXTENSIONS</b> environment variable.
<p> 

<h2>Creation Issues</h2>

On export all layers are written to a single GPX file. Update of existing
files is not currently supported.<p>
If the output file already exits, the writing will not occur. You have to delete the existing file first.<p>

Supported geometries :
<ul>
<li>Features of type wkbPoint/wkbPoint25D are written in the <i>wpt</i> element.</li>
<li>Features of type wkbLineString/wkbLineString25D are written in the <i>rte</i> element.</li>
<li>Features of type wkbMultiLineString/wkbMultiLineString25D are written in the <i>trk</i> element.</li>
<li>Other type of geometries are not supported.</li>
</ul>
<p>

For route points and tracks points, if there is a Z coordinate, it is used to fill the elevation element
of the corresponding points.<p>

Starting with GDAL/OGR 1.8.0, if a layer is named "track_points" with wkbPoint/wkbPoint25D geometries, the
tracks in the GPX file will be built from the sequence of features in that layer. This is the way of setting GPX attributes
for each track point, in addition to the raw coordinates. Points belonging to the same track are
identified thanks to the same value of the 'track_fid' field (and it will be broken into track segments
according to the value of the 'track_seg_id' field). They must be written in sequence so that track objects
are properly reconstructed. The 'track_name' field can be set on the first track point to fill the &lt;name&gt;
element of the track.
Similarly, if a layer is named "route_points" with wkbPoint/wkbPoint25D geometries, the routes in the GPX file
will be built from the sequence of points with the same value of the 'route_fid' field.  The 'route_name'
field can be set on the first track point to fill the &lt;name&gt; element of the route.<p>

The GPX writer supports the following <i>layer</i> creation options:
<ul>
<li> <b>FORCE_GPX_TRACK</b>:
By default when writting a layer whose features are of type wkbLineString, the GPX driver
chooses to write them as routes.
<br>If FORCE_GPX_TRACK=YES is specified, they will be written
as tracks.</li><p>
<li> <b>FORCE_GPX_ROUTE</b>:
By default when writting a layer whose features are of type wkbMultiLineString, the GPX driver
chooses to write them as tracks.
<br>If FORCE_GPX_ROUTE=YES is specified, they will be written
as routes, provided that the multilines are composed of only one single line.</li><p>
</ul>
<p>

The GPX writer supports the following <i>dataset</i> creation options:
<ul>
<li> <b>GPX_USE_EXTENSIONS</b>:
By default, the GPX driver will discard attribute fields that do not match the GPX XML definition (name, cmt, etc...).<br>
If GPX_USE_EXTENSIONS=YES is specified, extra fields will be written inside the<i>&lt;extensions&gt;</i> tag.</li><p>
<li> <b>GPX_EXTENSIONS_NS</b>:
Only used if GPX_USE_EXTENSIONS=YES and GPX_EXTENSIONS_NS_URL is set.<br>
The namespace value used for extension tags. By default, "ogr".</li><p>
<li> <b>GPX_EXTENSIONS_NS_URL</b>:
Only used if GPX_USE_EXTENSIONS=YES and GPX_EXTENSIONS_NS is set.<br>
The namespace URI. By default, "http://osgeo.org/gdal".</li><p>
<li> <b>LINEFORMAT</b>: (GDAL/OGR >= 1.8.0)
By default files are created with the line
termination conventions of the local platform (CR/LF on win32 or 
LF on all other systems).  This may be overridden through use of the
LINEFORMAT layer creation option which may have a value of <b>CRLF</b>
(DOS format) or <b>LF</b> (Unix format).</li> <p>
</ul>
<p>

Waypoints, routes and tracks must be written into that order to be valid against the XML Schema.

<p>
When translating from a source dataset, it may be necessary to rename the field names from the source dataset to the expected GPX attribute names, such as &lt;name&gt;, &lt;desc&gt;, etc... 
This can be done with a <a href="drv_vrt.html">OGR VRT</a> dataset, or by using the "-sql" option of the ogr2ogr utility.

</li>

<h2>Issues when translating to Shapefile</h2>

<ul>
<li>
When translating the <i>track_points</i> layer to a Shapefile, the field names "track_seg_id" and "track_seg_point_id" are
truncated to 10 characters in the .DBF file, thus leading to duplicate names.<p>
To avoid this, starting with GDAL 1.6.1,
you can define the GPX_SHORT_NAMES configuration option to TRUE to make them be reported respectively as "trksegid" and "trksegptid",
which will allow them to be unique once translated to DBF. The "route_point_id" field of <i>route_points</i> layer will also be renamed to "rteptid".
But note that no particular processing will be done for any extension field names.<p>

To translate the track_points layer of a GPX file to a set of shapefiles :
<pre>
    ogr2ogr --config GPX_SHORT_NAMES YES out input.gpx track_points
</pre>
</li>

<li>
Shapefile does not support fields of type DateTime. It only supports fields of type Date. So by default, you will lose the
hour:minute:second part of the <i>Time</i> elements of a GPX file.<p>
Starting with GDAL 1.6.0, you can use the OGR SQL CAST operator to convert the <i>time</i> field to a string :
<pre>
    ogr2ogr out input.gpx -sql "SELECT ele, CAST(time AS character(32)) FROM waypoints"
</pre>

Starting with GDAL 1.7.0, there is a more convenient way to select all fields and ask for the conversion of the ones of a given type to strings:
<pre>
    ogr2ogr out input.gpx -fieldTypeToString DateTime
</pre>
</li>

</ul>

<h2>VSI Virtual File System API support</h2>

(Some features below might require OGR >= 1.9.0)<p>

The driver supports reading and writing to files managed by VSI Virtual File System API, which include
"regular" files, as well as files in the /vsizip/ (read-write) , /vsigzip/ (read-write) , /vsicurl/ (read-only) domains.<p>

Writing to /dev/stdout or /vsistdout/ is also supported.<p>

<h2>Example</h2>

<li>The ogrinfo utility can be used to dump the content of a GPX datafile :

<pre>
ogrinfo -ro -al input.gpx
</pre>
</li>
<p><br>

<li>The ogr2ogr utility can be used to do GPX to GPX translation :

<pre>
ogr2ogr -f GPX output.gpx input.gpx waypoints routes tracks
</pre>
<br>
Note : in the case of GPX to GPX translation, you need to specify the layer names,
in order to discard the route_points and track_points layers.
</li>
<p><br>


<li>Use of the <i>&lt;extensions&gt;</i> tag for output :
<pre>
ogr2ogr -f GPX  -dsco GPX_USE_EXTENSIONS=YES output.gpx input
</pre>
which will give an output like the following one :
<pre>
    &lt;?xml version="1.0"?&gt;
    &lt;gpx version="1.1" creator="GDAL 1.5dev"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ogr="http://osgeo.org/gdal"
    xmlns="http://www.topografix.com/GPX/1/1"
    xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd"&gt;
    &lt;wpt lat="1" lon="2"&gt;
    &lt;extensions&gt;
        &lt;ogr:Primary_ID&gt;PID5&lt;/ogr:Primary_ID&gt;
        &lt;ogr:Secondary_ID&gt;SID5&lt;/ogr:Secondary_ID&gt;
    &lt;/extensions&gt;
    &lt;/wpt&gt;
    &lt;wpt lat="3" lon="4"&gt;
    &lt;extensions&gt;
        &lt;ogr:Primary_ID&gt;PID4&lt;/ogr:Primary_ID&gt;
        &lt;ogr:Secondary_ID&gt;SID4&lt;/ogr:Secondary_ID&gt;
    &lt;/extensions&gt;
    &lt;/wpt&gt;
    &lt;/gpx&gt;
</pre>
</li>

<li>Use of -sql option to remap field names to the ones allowed by the GPX schema (starting with GDAL 1.6.0):
<pre>
ogr2ogr -f GPX output.gpx input.shp -sql "SELECT field1 AS name, field2 AS desc FROM input"
</pre>
</li>

<h2>FAQ</h2>

<li>How to solve "ERROR 6: Cannot create GPX layer XXXXXX with unknown geometry type" ?<p>
This error happens when the layer to create does not expose a precise geometry type, but just a generic
wkbUnknown type. This is for example the case when using ogr2ogr with a SQL request to a PostgreSQL datasource.
You must then explicitly specify -nlt POINT (or LINESTRING or MULTILINESTRING).
</li>


<h2>See Also</h2>

<ul>
<li> <a href="http://www.topografix.com/gpx.asp">Home page for GPX format</a><p>
<li> <a href="http://www.topografix.com/GPX/1/1/">GPX 1.1 format documentation</a><p>
</ul>

</body>
</html>