API Reference#
gpx.gpx Module#
This module provides a GPX object to contain GPX files, consisting of waypoints, routes and tracks.
- class gpx.gpx.GPX(gpx=None)#
A GPX class for the GPX data format.
- Parameters:
gpx (etree._Element | None) – The GPX XML element. Defaults to None.
- bounds: tuple[float, float, float, float] | None#
Minimum and maximum coordinates which describe the extent of the coordinates in the file.
- creator: str | None#
The name or URL of the software that created your GPX document. Defaults to “PyGPX”.
- classmethod from_file(gpx_file, validate=False)#
Create an GPX instance from a file.
>>> from gpx import GPX >>> gpx = GPX.from_file("path/to/file.gpx") >>> print(gpx.bounds)
- classmethod from_string(gpx_str, validate=False)#
Create an GPX instance from a string.
>>> from gpx import GPX >>> gpx = GPX.from_str("""<?xml version="1.0" encoding="UTF-8" ?> ... <gpx xmlns="http://www.topografix.com/GPX/1/1" creator="PyGPX" version="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"> ... [...] ... </gpx>""") >>> print(gpx.bounds)
- keywords: str | None#
Keywords associated with the file. Search engines or databases can use this information to classify the data.
- routes: list[gpx.route.Route]#
A list of routes.
- to_file(gpx_file)#
Serialize the GPX instance to a file.
- to_string()#
Serialize the GPX instance to a string.
- Returns:
The GPX data as a string.
- Return type:
- tracks: list[gpx.track.Track]#
A list of tracks.
- waypoints: list[gpx.waypoint.Waypoint]#
A list of waypoints.
gpx.waypoint Module#
This module provides a Waypoint object to contain GPX waypoints.
- class gpx.waypoint.Waypoint(wpt=None)#
A waypoint class for the GPX data format.
- Parameters:
wpt (etree._Element | None) – The waypoint XML element. Defaults to None.
- desc: str | None#
A text description of the element. Holds additional information about the element intended for the user, not the GPS.
- distance_to(other, radius=6378137)#
Returns the distance to the other waypoint (in metres) using a simple spherical earth model.
- Parameters:
- Returns:
The distance to the other waypoint (in metres).
- Return type:
Adapted from: https://github.com/chrisveness/geodesy/blob/33d1bf53c069cd7dd83c6bf8531f5f3e0955c16e/latlon-spherical.js#L187-L205
- duration_to(other)#
Returns the duration to the other waypoint (in seconds).
- geoidheight: float | None#
Height (in meters) of geoid (mean sea level) above WGS84 earth ellipsoid. As defined in NMEA GGA message.
- name: str | None#
The GPS name of the waypoint. This field will be transferred to and from the GPS. GPX does not place restrictions on the length of this field or the characters contained in it. It is up to the receiving application to validate the field before sending it to the GPS.
- src: str | None#
Source of data. Included to give user some idea of reliability and accuracy of data. “Garmin eTrex”, “USGS quad Boston North”, e.g.
- sym: str | None#
Text of GPS symbol name. For interchange with other programs, use the exact spelling of the symbol as displayed on the GPS. If the GPS abbreviates words, spell them out.
gpx.route Module#
This module provides a Route object to contain GPX routes - ordered lists of waypoints representing a series of turn points leading to a destination.
- class gpx.route.Route(rte=None)#
A route class for the GPX data format.
- Parameters:
rte (etree._Element | None) – The route XML element. Defaults to None.
- points: list[gpx.waypoint.Waypoint]#
A list of route points.
gpx.track Module#
This module provides a Track object to contain GPX routes - an ordered list of points describing a path.
- class gpx.track.Track(trk=None)#
A track class for the GPX data format.
- Parameters:
trk (etree._Element | None) – The track XML element. Defaults to None.
- segments: list[list[gpx.waypoint.Waypoint]]#
A Track Segment holds a list of Track Points which are logically connected in order. To represent a single GPS track where GPS reception was lost, or the GPS receiver was turned off, start a new Track Segment for each continuous span of track data.
gpx.utils Module#
This module contains various utility functions.
gpx.errors Module#
This module provices various error types.
- exception gpx.errors.InvalidGPXError#
GPX is invalid.