Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
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',
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)