activereader.gpx module

.gpx file reader architecture.

See also

GPX schema

Official documentation for GPX elements and file structure.

Garmin’s GPX trackpoint extension schema

XML file describing the schema for Garmin’s additional GPX trackpoint elements.

activereader.gpx.Gpx(lxml_elem)

Represents an entire .gpx file object.

activereader.gpx.Track(lxml_elem)

An ordered list of trackpoints describing a path.

activereader.gpx.Segment(lxml_elem)

Holds a list of trackpoints which are logically connected in order.

activereader.gpx.Trackpoint(lxml_elem)

Represents a single data sample corresponding to a point in time.

class activereader.gpx.Gpx(lxml_elem)

Bases: ActivityElement

Represents an entire .gpx file object.

TAG = 'gpx'

XML tag name of the element.

If an instance of the class is initialized from a lxml.etree._Element with any other tag name, a TypeError will be raised.

classmethod from_file(file_obj)

Initialize a Gpx element from a file-like object.

Parameters

file_obj (str, bytes, io.StringIO, io.BytesIO) – File-like object. If str, either filename or a string representation of XML object. If str or StringIO, the encoding should not be declared within the string.

Returns

An instance initialized with the _Element that was read in.

Return type

Gpx

property start_time

Timestamp at start of recording.

See also

Timestamps

Type

datetime.datetime

property tracks

All element descendents with tag name “trk”.

Type

list of Track

property segments

All element descendents with tag name “trkseg”.

Type

list of Segment

property trackpoints

All element descendents with tag name “trkpt”.

Type

list of Trackpoint

property routepoints

All element descendents with tag name “rtept”.

Type

list of Routepoint

class activereader.gpx.Track(lxml_elem)

Bases: ActivityElement

An ordered list of trackpoints describing a path.

TAG = 'trk'

XML tag name of the element.

If an instance of the class is initialized from a lxml.etree._Element with any other tag name, a TypeError will be raised.

property segments

All element descendents with tag name “trkseg”.

Type

list of Segment

property trackpoints

All element descendents with tag name “trkpt”.

Type

list of Trackpoint

class activereader.gpx.Segment(lxml_elem)

Bases: ActivityElement

Holds a list of trackpoints 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.

TAG = 'trkseg'

XML tag name of the element.

If an instance of the class is initialized from a lxml.etree._Element with any other tag name, a TypeError will be raised.

property trackpoints

All element descendents with tag name “trkpt”.

Type

list of Trackpoint

class activereader.gpx.Trackpoint(lxml_elem)

Bases: ActivityElement

Represents a single data sample corresponding to a point in time.

The most granular of data contained in the file.

TAG = 'trkpt'

XML tag name of the element.

If an instance of the class is initialized from a lxml.etree._Element with any other tag name, a TypeError will be raised.

property time

Timestamp when trackpoint was recorded.

See also

Timestamps

Type

datetime.datetime

property altitude_m

Elevation of ground surface in meters above sea level.

Type

float

property hr

Heart rate.

Type

int

property cadence_rpm

Cadence in RPM.

See also

Cadence

Type

int

property lat

Latitude in degrees N (-90 to 90).

Type

float

property lon

Longitude in degrees E (-180 to 180).

Type

float