Gpx Class
Reads and writes GPX, the GPS Exchange Format: the waypoints, routes and tracks of a GPS device or of a sports application.
public static class GpxRemarks
The reader reads GPX 1.1 and GPX 1.0, and returns one feature per wpt, rte and trk element, in the order of the document. A waypoint is a GeoPoint, a route is a GeoLineString of its rtept, and a track is a GeoMultiLineString with one line per trkseg, even when it has a single segment, so the type of the geometry tells a track from a route. The ele of a point becomes its GeoPosition.Altitude, and its time its GeoPosition.Time (UTC when the text has no offset). The name of the metadata (or of the gpx element in GPX 1.0) becomes GeoFeatureCollection.Name.
The properties of a feature are the Gpx.TypePropertyName property, wpt, rte or trk, and the elements name, cmt, desc, src and type as a String, the sym of a waypoint as a String, the number of a route or a track as a Double, and the time of a waypoint as a DateTimeOffset, also kept as the time of its position. The other elements are ignored: link (url in GPX 1.0), extensions (such as the heart rate or the cadence of a Garmin device), the other data of a waypoint (magvar, fix, hdop…), the metadata other than its name, and every element of the points of the routes and tracks except ele and time. The features have no GeoFeature.Id.
The writer writes GPX 1.1. A GeoPoint is a wpt, a GeoMultiPoint is one wpt per point, a GeoLineString is a rte, and a GeoMultiLineString is a trk with one trkseg per line, as the reader returns them and as GDAL writes them. When the Gpx.TypePropertyName property is trk, a GeoLineString is a track of one segment; when it is rte, a GeoMultiLineString is one route per line. As GPX requires, the waypoints come first, then the routes, then the tracks. The altitude and the time of each position are its ele and time, the time in UTC. The writer writes the properties named after the elements the reader reads, as their text; the time property of a waypoint whose position has no time is written in UTC when it is a DateTimeOffset, a DateTime or a text that is a date, and the number when it is a non-negative integer. The measures are not written. The other properties and the identifiers are not written, as GPX has no element for them.
Methods
| Name | Description |
|---|---|
| Format(GeoFeatureCollection, GpxWriterOptions?) | Writes features as a GPX 1.1 document. |
| Parse(string) | Reads the waypoints, routes and tracks of a GPX document. |
| Read(Stream) | Reads the waypoints, routes and tracks of a GPX document. |
| Write(GeoFeatureCollection, Stream, GpxWriterOptions?) | Writes features as a GPX 1.1 document, encoded in UTF-8. |
Format(GeoFeatureCollection, GpxWriterOptions?)
Gpx.csWrites features as a GPX 1.1 document.
public static string Format(GeoFeatureCollection features, GpxWriterOptions? options = null)Parameters
featuresGeoFeatureCollection- The features: points and lines.
optionsGpxWriterOptions?- The options, or
nullfor the defaults.
Returns
string The GPX text.
Exceptions
ArgumentException- A feature has no geometry, or a polygon or a geometry collection, or a position is not finite.
Parse(string)
Gpx.csReads the waypoints, routes and tracks of a GPX document.
public static GeoFeatureCollection Parse(string gpx)Parameters
gpxstring- The GPX text.
Returns
GeoFeatureCollection One feature per waypoint, route and track, in the order of the document.
Exceptions
FormatException- The text is not valid XML or not GPX.
Read(Stream)
Gpx.csReads the waypoints, routes and tracks of a GPX document.
public static GeoFeatureCollection Read(Stream stream)Parameters
streamStream- The GPX document. Its encoding is read from the XML declaration, UTF-8 by default. It is left open.
Returns
GeoFeatureCollection One feature per waypoint, route and track, in the order of the document.
Exceptions
FormatException- The document is not valid XML or not GPX.
Write(GeoFeatureCollection, Stream, GpxWriterOptions?)
Gpx.csWrites features as a GPX 1.1 document, encoded in UTF-8.
public static void Write(GeoFeatureCollection features, Stream stream, GpxWriterOptions? options = null)Parameters
featuresGeoFeatureCollection- The features: points and lines.
streamStream- The stream to write to. It is left open.
optionsGpxWriterOptions?- The options, or
nullfor the defaults.
Exceptions
ArgumentException- A feature has no geometry, or a polygon or a geometry collection, or a position is not finite.
Constants
| Name | Description |
|---|---|
| TypePropertyName | The name of the property that holds the GPX element of a feature: wpt, rte or trk. |
TypePropertyName
The name of the property that holds the GPX element of a feature: wpt, rte or trk.
public const string TypePropertyName = "gpxType"