turfrun/gpx.py
Ian Burgess 02845f8a59 yes
2025-05-06 21:10:16 -06:00

31 lines
852 B
Python

import gpxpy
import gpxpy.gpx
import turtle
# Parsing an existing file:
# -------------------------
a=0
gpx_file = open('test.gpx', 'r')
gpx = gpxpy.parse(gpx_file)
for track in gpx.tracks:
for segment in track.segments:
for point in segment.points:
print(f'Point at ({point.latitude},{point.longitude}')
a+=1
print(a)
for waypoint in gpx.waypoints:
print(f'waypoint {waypoint.name} -> ({waypoint.latitude},{waypoint.longitude})')
for route in gpx.routes:
print('Route:')
for point in route.points:
print(f'Point at ({point.latitude},{point.longitude}) -> {point.elevtion}')
# There are many more utility methods and functions:
# You can manipulate/add/remove tracks, segments, points, waypoints and routes and
# get the GPX XML file from the resulting object:
#print('GPX:', gpx.to_xml())