How to use the gpxpy.gpx.GPXRoute function in gpxpy

To help you get started, we’ve selected a few gpxpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github GeotrekCE / Geotrek-admin / geotrek / mapentity / serializers.py View on Github external
Raise ValueError if it is not a Point, LineString or a collection of those

        Point -> add as a Way Point
        LineString -> add all Points in a Route
        Collection (of LineString or Point) -> add as a route, concatening all points
        """
        if isinstance(geom, GeometryCollection):
            for i, g in enumerate(geom):
                self.geomToGPX(g, u"%s (%s)" % (name, i), description)
        elif isinstance(geom, Point):
            wp = self._point_to_GPX(geom)
            wp.name = name
            wp.description = description
            self.gpx.waypoints.append(wp)
        elif isinstance(geom, LineString):
            gpx_route = gpxpy.gpx.GPXRoute(name=name, description=description)
            gpx_route.points = [self._point_to_GPX(point, klass=gpxpy.gpx.GPXRoutePoint) for point in geom]
            self.gpx.routes.append(gpx_route)
        else:
            raise ValueError("Unsupported geometry %s" % geom)
github tkrajina / gpxpy / gpxpy / gpx.py View on Github external
class GPX:
    gpx_10_fields = [
            mod_gpxfield.GPXField('version', attribute=True),
            mod_gpxfield.GPXField('creator', attribute=True),
            mod_gpxfield.GPXField('name'),
            mod_gpxfield.GPXField('description', 'desc'),
            mod_gpxfield.GPXField('author_name', 'author'),
            mod_gpxfield.GPXField('author_email', 'email'),
            mod_gpxfield.GPXField('link', 'url'),
            mod_gpxfield.GPXField('link_text', 'urlname'),
            mod_gpxfield.GPXField('time', type=mod_gpxfield.TIME_TYPE),
            mod_gpxfield.GPXField('keywords'),
            mod_gpxfield.GPXComplexField('bounds', classs=GPXBounds),
            mod_gpxfield.GPXComplexField('waypoints', classs=GPXWaypoint, tag='wpt', is_list=True),
            mod_gpxfield.GPXComplexField('routes', classs=GPXRoute, tag='rte', is_list=True),
            mod_gpxfield.GPXComplexField('tracks', classs=GPXTrack, tag='trk', is_list=True),
    ]
    # Text fields serialize as empty container tags, dependents are
    # are listed after as 'tag:dep1:dep2:dep3'. If no dependents are
    # listed, it will always serialize. The container is closed with
    # '/tag'. Required dependents are preceded by an @. If a required
    # dependent is empty, nothing in the container will serialize. The
    # format is 'tag:@dep2'. No optional dependents need to be listed.
    # Extensions not yet supported
    gpx_11_fields = [
            mod_gpxfield.GPXField('version', attribute=True),
            mod_gpxfield.GPXField('creator', attribute=True),
            'metadata:name:description:author_name:author_email:author_link:copyright_author:copyright_year:copyright_license:link:time:keywords:bounds',
                mod_gpxfield.GPXField('name', 'name'),
                mod_gpxfield.GPXField('description', 'desc'),
                'author:author_name:author_email:author_link',
github makinacorpus / django-mapentity / mapentity / serializers.py View on Github external
Raise ValueError if it is not a Point, LineString or a collection of those

        Point -> add as a Way Point
        LineString -> add all Points in a Route
        Collection (of LineString or Point) -> add as a route, concatening all points
        """
        if isinstance(geom, GeometryCollection):
            for i, g in enumerate(geom):
                self.geomToGPX(g, u"%s (%s)" % (name, i), description)
        elif isinstance(geom, Point):
            wp = self._point_to_GPX(geom)
            wp.name = name
            wp.description = description
            self.gpx.waypoints.append(wp)
        elif isinstance(geom, LineString):
            gpx_route = gpxpy.gpx.GPXRoute(name=name, description=description)
            gpx_route.points = [self._point_to_GPX(point, klass=gpxpy.gpx.GPXRoutePoint) for point in geom]
            self.gpx.routes.append(gpx_route)
        else:
            raise ValueError("Unsupported geometry %s" % geom)