def import_locations(self, gpx_file):
        """Import GPX data files.

        ``import_locations()`` returns a series of lists representing track
        segments with :class:`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="upoints/0.12.2"
            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 the :mod:`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")], ]

        Args:
            gpx_file (iter): GPX data to read

        Returns:
            list: Locations with optional comments

        .. _GPX 1.1 Schema Documentation: http://www.topografix.com/GPX/1/1/
        """
        self._gpx_file = gpx_file
        data = utils.prepare_xml_read(gpx_file, objectify=True)

        try:
            self.metadata.import_metadata(data.metadata)
        except AttributeError:
            pass

        for segment in data.trk.trkseg:
            points = point.TimedPoints()
            for trackpoint in segment.trkpt:
                latitude = trackpoint.get('lat')
                longitude = trackpoint.get('lon')
                try:
                    name = trackpoint.name.text
                except AttributeError:
                    name = None
                try:
                    description = trackpoint.desc.text
                except AttributeError:
                    description = None
                try:
                    elevation = float(trackpoint.ele.text)
                except AttributeError:
                    elevation = None
                try:
                    time = utils.Timestamp.parse_isoformat(trackpoint.time.text)
                except AttributeError:
                    time = None
                points.append(Trackpoint(latitude, longitude, name,
                                         description, elevation, time))
            self.append(points)
def import_locations ( self , gpx_file ) : self . _gpx_file = gpx_file data = utils . prepare_xml_read ( gpx_file , objectify = True ) try : self . metadata . import_metadata ( data . metadata ) except AttributeError : pass for segment in data . trk . trkseg : points = point . TimedPoints ( ) for trackpoint in segment . trkpt : latitude = trackpoint . get ( 'lat' ) longitude = trackpoint . get ( 'lon' ) try : name = trackpoint . name . text except AttributeError : name = None try : description = trackpoint . desc . text except AttributeError : description = None try : elevation = float ( trackpoint . ele . text ) except AttributeError : elevation = None try : time = utils . Timestamp . parse_isoformat ( trackpoint . time . text ) except AttributeError : time = None points . append ( Trackpoint ( latitude , longitude , name , description , elevation , time ) ) self . append ( points )
Import GPX data files.

        ``import_locations()`` returns a series of lists representing track
        segments with :class:`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="upoints/0.12.2"
            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 the :mod:`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")], ]

        Args:
            gpx_file (iter): GPX data to read

        Returns:
            list: Locations with optional comments

        .. _GPX 1.1 Schema Documentation: http://www.topografix.com/GPX/1/1/