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(element=None)#
Bases:
Element
A GPX class for the GPX data format.
GPX documents contain a metadata header, followed by waypoints, routes, and tracks. You can add your own elements to the extensions section of the GPX document.
- Parameters:
element (etree._Element | None) – The GPX XML element. Defaults to None.
- waypoints: list[gpx.waypoint.Waypoint]#
A list of waypoints.
- routes: list[gpx.route.Route]#
A list of routes.
- tracks: list[gpx.track.Track]#
A list of tracks.
- property name: str | None#
The name of the GPX file.
Alias of
gpx.metadata.Metadata.name
.
- property desc: str | None#
A description of the contents of the GPX file.
Alias of
gpx.metadata.Metadata.desc
.
- property author: Person | None#
The person or organization who created the GPX file.
Alias of
gpx.metadata.Metadata.author
.
- property copyright: Copyright | None#
Copyright and license information governing use of the file.
Alias of
gpx.metadata.Metadata.copyright
.
- property links: list[gpx.link.Link] | None#
URLs associated with the location described in the file.
Alias of
gpx.metadata.Metadata.links
.
- property time: datetime | None#
The creation date of the file.
Alias of
gpx.metadata.Metadata.time
.
- property keywords: str | None#
Keywords associated with the file. Search engines or databases can use this information to classify the data.
Alias of
gpx.metadata.Metadata.keywords
.
- property bounds: Bounds | None#
Minimum and maximum coordinates which describe the extent of the coordinates in the file.
Alias of
gpx.metadata.Metadata.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)
- 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)
- to_string()#
Serialize the GPX instance to a string.
- Returns:
The GPX data as a string.
- Return type:
gpx.metadata
Module#
This module provides a Metadata object to contain GPX metadata, containing information about the GPX file, author, and copyright restrictions.
- class gpx.metadata.Metadata(element=None)#
Bases:
Element
A metadata class for the GPX data format.
Information about the GPX file, author, and copyright restrictions goes in the metadata section. Providing rich, meaningful information about your GPX files allows others to search for and use your GPS data.
- Parameters:
element (etree._Element | None) – The metadata XML element. Defaults to None.
- links: list[gpx.link.Link]#
URLs associated with the location described in the file.
gpx.waypoint
Module#
This module provides a Waypoint object to contain GPX waypoints.
- class gpx.waypoint.Waypoint(element=None)#
Bases:
Element
A waypoint class for the GPX data format.
A waypoint represents a waypoint, point of interest, or named feature on a map.
- Parameters:
element (etree._Element | None) – The waypoint XML element. Defaults to None.
- time: datetime | None#
Creation/modification timestamp for element. Date and time in are in Universal Coordinated Time (UTC), not local time! Conforms to ISO 8601 specification for date/time representation. Fractional seconds are allowed for millisecond timing in tracklogs.
- geoidheight: Decimal | 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.
- desc: str | None#
A text description of the element. Holds additional information about the element intended for the user, not 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.
- links: list[gpx.link.Link]#
Link to additional information about the waypoint.
- 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.
- dgpsid: DGPSStation | None#
ID of DGPS station used in differential correction.
- distance_to(other, radius=6378137)#
Returns the distance to the other waypoint (in metres) using a simple spherical earth model (haversine formula).
- 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
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(element=None)#
Bases:
Element
,PointsMutableSequenceMixin
A route class for the GPX data format.
A route represents an ordered list of waypoints representing a series of turn points leading to a destination.
- Parameters:
element (etree._Element | None) – The route XML element. Defaults to None.
- src: str | None#
Source of data. Included to give user some idea of reliability and accuracy of data.
- links: list[gpx.link.Link]#
Links to external information about the route.
- rtepts: list[gpx.waypoint.Waypoint]#
A list of route points.
- points: list[gpx.waypoint.Waypoint]#
Alias of
rtepts
.
- property bounds: tuple[gpx.types.Latitude, gpx.types.Longitude, gpx.types.Latitude, gpx.types.Longitude]#
The bounds of the route.
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(element=None)#
Bases:
Element
A track class for the GPX data format.
A track represents an ordered list of points describing a path.
- Parameters:
element (etree._Element | None) – The track XML element. Defaults to None.
- src: str | None#
Source of data. Included to give user some idea of reliability and accuracy of data.
- links: list[gpx.link.Link]#
Links to external information about track.
- trksegs: list[gpx.track_segment.TrackSegment]#
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.
- property bounds: tuple[gpx.types.Latitude, gpx.types.Longitude, gpx.types.Latitude, gpx.types.Longitude]#
The bounds of the track.
gpx.track_segment
Module#
This module provides a Track object to contain GPX routes - an ordered list of points describing a path.
- class gpx.track_segment.TrackSegment(element=None)#
Bases:
Element
,PointsMutableSequenceMixin
A track segment class for the GPX data format.
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.
- Parameters:
element (etree._Element | None) – The track segment XML element. Defaults to None.
- trkpts: list[gpx.waypoint.Waypoint]#
A Track Point holds the coordinates, elevation, timestamp, and metadata for a single point in a track.
- points: list[gpx.waypoint.Waypoint]#
Alias of
trkpts
.
- property bounds: tuple[gpx.types.Latitude, gpx.types.Longitude, gpx.types.Latitude, gpx.types.Longitude]#
The bounds of the track segment.
gpx.copyright
Module#
This module provides a Copyright object to contain GPX copyright, containing information about the copyright holder and any license governing use of the GPX data.
- class gpx.copyright.Copyright(element=None)#
Bases:
Element
A copyright class for the GPX data format.
Information about the copyright holder and any license governing use of this file. By linking to an appropriate license, you may place your data into the public domain or grant additional usage rights.
- Parameters:
element (etree._Element | None) – The copyright XML element. Defaults to None.
gpx.link
Module#
This module provides a Link object to contain GPX links to external resources (Web page, digital photo, video clip, etc) with additional information.
gpx.email
Module#
This module provides a Email object to contain an email address.
gpx.person
Module#
This module provides a Person object to contain a person or organization.
- class gpx.person.Person(element=None)#
Bases:
Element
,AttributesMutableMappingMixin
A person class for the GPX data format.
A person or organization.
- Parameters:
element (etree._Element | None) – The person XML element. Defaults to None.
gpx.bounds
Module#
This module provides a Bounds object to contain two lat/lon pairs defining the extent of an element.
gpx.element
Module#
This module provides an Element object to serve as a base class for other GPX objects.
- class gpx.element.Element(element=None)#
Bases:
object
Element base class for GPX elements.
- Parameters:
element (etree._Element | None) – The XML element. Defaults to None.
- _parse()#
Parses the XML element.
- Raises:
ParseError – If the XML element is None.
gpx.mixins
Module#
This module provides a Person object to contain a person or organization.
- class gpx.mixins.AttributesMutableMappingMixin#
Bases:
MutableMapping
A mixin class to provide a MutableMapping interface to an object’s defined attributes.
- class gpx.mixins.PointsSequenceMixin#
Bases:
Sequence
A mixin class to provide a Sequence interface to an object’s points.
- class gpx.mixins.PointsMutableSequenceMixin#
Bases:
PointsSequenceMixin
,MutableSequence
A mixin class to provide a MutableSequence interface to an object’s points.
gpx.types
Module#
This module provides simple type objects to contain various GPX data.
- class gpx.types.Latitude(value)#
Bases:
Decimal
A latitude class for the GPX data format.
The latitude of the point. Decimal degrees, WGS84 datum.
- class gpx.types.Longitude(value)#
Bases:
Decimal
A longitude class for the GPX data format.
The longitude of the point. Decimal degrees, WGS84 datum.
- class gpx.types.Degrees(value)#
Bases:
Decimal
A degrees class for the GPX data format.
Used for bearing, heading, course. Units are decimal degrees, true (not magnetic).
gpx.utils
Module#
This module contains various utility functions.
gpx.errors
Module#
This module provices various error types.