upoints.gpx.Trackpoints

Package upoints :: Module gpx :: Class Trackpoints |
[hide private]
[frames] | no frames]

# Class Trackpoints

    object --+
             |
          list --+
                 |
                Trackpoints

Class for representing a group of Trackpoint objects

Since: 0.10.0

Instance Methods | [hide private]
new list |
__init__(self, gpx_file=None) Initialise a new Trackpoints object |
`list` |
import_locations(self, gpx_file, gpx_version=None) Import GPX data files |
`ET.ElementTree` |
export_gpx_file(self, gpx_version=`'``1.1``'`, human_namespace=False) Generate GPX element tree from Trackpoints |
Inherited from `list`: `__add__`, `__contains__`, `__delitem__`, `__delslice__`, `__eq__`, `__ge__`, `__getattribute__`, `__getitem__`, `__getslice__`, `__gt__`, `__hash__`, `__iadd__`, `__imul__`, `__iter__`, `__le__`, `__len__`, `__lt__`, `__mul__`, `__ne__`, `__new__`, `__repr__`, `__reversed__`, `__rmul__`, `__setitem__`, `__setslice__`, `append`, `count`, `extend`, `index`, `insert`, `pop`, `remove`, `reverse`, `sort` Inherited from `object`: `__delattr__`, `__reduce__`, `__reduce_ex__`, `__setattr__`, `__str__`

Properties | [hide private]
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, gpx_file=None) (Constructor) |
Initialise a new Trackpoints object Returns: new list Overrides: object.__init__

### import_locations(self, gpx_file, gpx_version=None) |
Import GPX data files import_locations() returns a series of lists representing track segments with Trackpoint objects as contents. It expects data files in GPX format, as specified in GPX 1.1 Schema Documentation, which is XML such as:
    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <gpx version="1.1" creator="PocketGPSWorld.com"
    xmlns="http://www.topografix.com/GPX/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">
      <trk>
        <trkseg>
          <trkpt lat="52.015" lon="-0.221">
            <name>Home</name>
            <desc>My place</desc>
          </trkpt>
          <trkpt lat="52.167" lon="0.390">
            <name>MSR</name>
            <desc>Microsoft Research, Cambridge</desc>
          </trkpt>
        </trkseg>
      </trk>
    </gpx>
The reader uses Python's ElementTree module, so should be very fast when importing data. The above file processed by import_locations() will return the following `list` object:
    [[Trackpoint(52.015, -0.221, "Home", "My place"),
      Trackpoint(52.167, 0.390, "MSR", "Microsoft Research, Cambridge")], ]
    >>> trackpoints = Trackpoints(open("gpx_tracks"))
    >>> for value in sorted(trackpoints[0],
    ...                     key=lambda x: x.name.lower()):
    ...     print(value)
    Home (52°00'54"N, 000°13'15"W) [My place]
    MSR (52°10'01"N, 000°23'24"E) [Microsoft Research, Cambridge]
Parameters: `gpx_file` (`file`, `list` or `str`) - GPX data to read `gpx_version` (`str`) - Specific GPX version entities to import Returns: `list` Locations with optional comments

### export_gpx_file(self, gpx_version=`'``1.1``'`, human_namespace=False) |
Generate GPX element tree from Trackpoints
    >>> from sys import stdout
    >>> locations = Trackpoints(open("gpx_tracks"))
    >>> xml = locations.export_gpx_file()
    >>> xml.write(stdout)
    <ns0:gpx xmlns:ns0="http://www.topografix.com/GPX/1/1"><ns0:trk><ns0:trkseg><ns0:trkpt lat="52.015" lon="-0.221"><ns0:name>Home</ns0:name><ns0:desc>My place</ns0:desc></ns0:trkpt><ns0:trkpt lat="52.167" lon="0.39"><ns0:name>MSR</ns0:name><ns0:desc>Microsoft Research, Cambridge</ns0:desc></ns0:trkpt></ns0:trkseg></ns0:trk></ns0:gpx>
Parameters: `gpx_version` (`str`) - GPX version to generate `human_namespace` (`bool`) - Whether to generate output using human readable namespace prefixes Returns: `ET.ElementTree` GPX element tree depicting Trackpoint objects