How to use the gpxpy.gpx.GPX 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 ruipgil / TrackToTrip / scripts / tracktotrip_geolife_dataset.py View on Github external
def save_segments(segments, origina_filepath, folder):
    """ Save segments to gpx
    """
    name = origina_filepath.split('/')[-1]
    for i, segment in enumerate(segments):
        label, points = segment
        filename = label + '.' + str(i) + '.' + str(len(points)) + '.' + name.split('.')[0] + '.gpx'

        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 in points:
            gpx_point = gpxpy.gpx.GPXTrackPoint(
                latitude=point['lat'],
                longitude=point['lon'],
                elevation=point['alt'],
                time=point['time']
            )
            gpx_segment.points.append(gpx_point)
github tkrajina / gpxpy / gpxpy / parser.py View on Github external
def __init__(self, xml_or_file=None):
        """
        Initialize new GPXParser instance.

        Arguments:
            xml_or_file: string or file object containing the gpx
                formatted xml

        """
        self.init(xml_or_file)
        self.gpx = mod_gpx.GPX()
github makinacorpus / django-mapentity / mapentity / serializers.py View on Github external
def serialize(self, queryset, **options):
        self.gpx = gpxpy.gpx.GPX()

        stream = options.pop('stream')
        geom_field = options.pop('geom_field')

        for obj in queryset:
            geom = getattr(obj, geom_field)
            objtype = unicode(obj.__class__._meta.verbose_name)
            name = '[%s] %s' % (objtype, unicode(obj))

            description = ''
            objupdate = getattr(obj, 'date_update')
            if objupdate:
                description = _('Modified') + ': ' + humanize_timesince(objupdate)
            if geom:
                assert geom.srid == settings.SRID, "Invalid srid"
                self.geomToGPX(geom, name, description)
github bwaldvogel / openmoves / gpx_export.py View on Github external
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
github GeotrekCE / Geotrek-admin / geotrek / mapentity / serializers.py View on Github external
def serialize(self, queryset, **options):
        self.gpx = gpxpy.gpx.GPX()

        stream = options.pop('stream')
        geom_field = options.pop('geom_field')

        for obj in queryset:
            geom = getattr(obj, geom_field)
            objtype = unicode(obj.__class__._meta.verbose_name)
            name = '[%s] %s' % (objtype, unicode(obj))

            description = ''
            objupdate = getattr(obj, 'date_update')
            if objupdate:
                description = _('Modified') + ': ' + humanize_timesince(objupdate)
            if geom:
                assert geom.srid == settings.SRID, "Invalid srid"
                self.geomToGPX(geom, name, description)
github mapillary / mapillary_tools / mapillary_tools / gpx_from_exif.py View on Github external
def write_gpx(path, data):
    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 in data:
        gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(
            point[1], point[2], elevation=point[3], time=point[0]))
    with open(path, "w") as f:
        f.write(gpx.to_xml())
github makinacorpus / django-mapentity / mapentity / serializers / gpx.py View on Github external
def serialize(self, queryset, **options):
        self.gpx = gpxpy.gpx.GPX()
        self.options = options

        for obj in queryset:
            self.end_object(obj)

        stream = options.pop('stream')
        stream.write(self.gpx.to_xml())
github wannesm / LeuvenMapMatching / leuvenmapmatching / util.py View on Github external
def path_to_gpx(path, filename=None):
    gpx = gpxpy.gpx.GPX()

    # 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)

    gpx_segment.points = [(gpxpy.gpx.GPXTrackPoint(lat, lon, time=time)) for (lat, lon, time) in path]

    if filename:
        with open(filename, 'w') as gpx_fh:
            gpx_fh.write(gpx.to_xml())

    return gpx
github mapillary / mapillary_tools / mapillary_tools / gpx_from_gopro.py View on Github external
def write_gpx(path, data):
    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 in data:
        if len(point) > 3:
            gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(
                latitude=point[1], longitude=point[2], elevation=point[3], time=point[0]))
        else:
            gpx_segment.points.append(gpxpy.gpx.GPXTrackPoint(
                latitude=point[1], longitude=point[2], time=point[0]))

    with open(path, "w") as f: