Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
def extract_segment_from_gpx_file(content, segment_id):
gpx_content = gpxpy.parse(content)
if len(gpx_content.tracks) == 0:
return None
track_segment = get_gpx_segments(
gpx_content.tracks[0].segments, segment_id
)
gpx = gpxpy.gpx.GPX()
gpx_track = gpxpy.gpx.GPXTrack()
gpx.tracks.append(gpx_track)
gpx_segment = gpxpy.gpx.GPXTrackSegment()
gpx_track.segments.append(gpx_segment)
for point_idx, point in enumerate(track_segment[0].points):
gpx_segment.points.append(
gpxpy.gpx.GPXTrackPoint(
point.latitude, point.longitude, elevation=point.elevation
)
)
return gpx.to_xml()
def gpx_export(move):
gpx = gpxpy.gpx.GPX()
gpx.creator = "OpenMoves - http://www.openmoves.net/"
# Create first track in our GPX:
gpx_track = gpxpy.gpx.GPXTrack()
gpx.tracks.append(gpx_track)
# Create first segment in our GPX track:
gpx_segment = gpxpy.gpx.GPXTrackSegment()
gpx_track.segments.append(gpx_segment)
# Create points:
gps_samples = move.samples.filter(Sample.sample_type.like('gps-%')).order_by(Sample.time.asc())
if gps_samples.count() == 0:
flash("No GPS samples found for GPX export", 'error')
return None
for gps_sample in gps_samples:
gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(latitude=radian_to_degree(gps_sample.latitude),
longitude=radian_to_degree(gps_sample.longitude),
elevation=gps_sample.gps_altitude,
time=move.date_time + gps_sample.time,
position_dilution=gps_sample.gps_hdop))