GPX walk tracks
Published: Updated:
I exported information about walking tracks from Apple Watch (Apple Health), there is a standard GPX format. There is no way to automate the export as Apple doesn't give a way (privacy blah blah blah). Maybe in the future I will do tracks through some other application where I don't need to unload the whole history with a huge archive every time.
Here is a python script that searches for faraway from current home tracks. (I don't worry about past rental places).
import functools
import shutil
import gpxpy
import tqdm
import gpxpy.gpx
from pathlib import Path
from geopy.distance import geodesic
home_coordinates = 0.0, 0.0 # redacted
@functools.cache
def gpx_meters_from_point(
gpx_path: str,
point: tuple[float, float],
min_meters: float = 100,
) -> float:
with open(gpx_path) as gpx_file:
gpx = gpxpy.parse(gpx_file)
meters = None
for track in gpx.tracks:
for segment in track.segments:
for _point in segment.points:
_meters = geodesic((_point.latitude, _point.longitude), point).meters
meters = _meters if meters is None else min(meters, _meters)
if meters is None:
raise ValueError(f'no points found in gpx file {gpx_path}')
return meters
Copy to a public folder (which is then copied to the server) tracks that are further than 3000 meters:
gpx_dir = Path('/Users/tandav/Desktop/apple_health_export/workout-routes')
gpx_public_dir = Path('/Users/tandav/docs/files-tandav-me/routes/routes/gpx')
gpx_files = list(gpx_dir.glob('*.gpx'))
for p in tqdm.tqdm(gpx_files):
if gpx_meters_from_point(p, home_coordinates) < 3000:
continue
shutil.copy(p, gpx_public_dir / p.name)
There is gpx.studio which has ability to render gpx filex from your server in iframe . But you have to setup CORS headers. Here is headers for Caddy:
files.tandav.me {
root * /srv
@gpxFiles {
path *.gpx
}
header @gpxFiles Access-Control-Allow-Origin "https://gpx.studio"
file_server {
browse
}
}
The list of my walk tracks is at files.tandav.me/walk-tracks/ . A screenshot of some walk track is at the beggining of the post.