Skip to content

Instantly share code, notes, and snippets.

@agenteo
Last active August 7, 2023 08:20
Show Gist options
  • Save agenteo/6493f50b21e5c0f3b377786a78be668e to your computer and use it in GitHub Desktop.
Save agenteo/6493f50b21e5c0f3b377786a78be668e to your computer and use it in GitHub Desktop.
GaiaGPS GPX distance is wrong.py
# Created this script to verify that GaiaGPS GPX distance calculation is wrong. Using geopy and Harvestine formula I can match GPS Track Editor and Strava's distance.
import xml.etree.ElementTree as ET
# Read the GPX file
def read_gpx(file_path):
tree = ET.parse(file_path)
root = tree.getroot()
coordinates = []
for trkpt in root.findall(".//{http://www.topografix.com/GPX/1/1}trkpt"):
lat = float(trkpt.get("lat"))
lon = float(trkpt.get("lon"))
coordinates.append((lat, lon))
return coordinates
# Calculate distance using Geopy
def calculate_distance(coordinates):
total_distance = 0.0
for i in range(len(coordinates) - 1):
coord1 = coordinates[i]
coord2 = coordinates[i + 1]
distance = geodesic(coord1, coord2).kilometers
total_distance += distance
return total_distance
coordinates = read_gpx(gpx_file_path)
total_distance = calculate_distance(coordinates)
print(f"Total distance: {total_distance:.2f} kilometers")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment