Skip to content

danielfn/gpx-simplify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GPX Simplify

Simplifies GPX files so older devices (GPS watches, navigators) can load them without issues. Routes recorded with modern devices often contain thousands of points that overwhelm older hardware.

Two interfaces are available: a static web page (browser-based) and a terminal script (for automation or batch processing).

Web

Open index.html in any browser. Everything is processed locally — nothing is uploaded to any server.

Run locally

python3 -m http.server

Open http://localhost:8000 in your browser.

Features

  • Drag & drop .gpx files
  • Tolerance slider (0.25 – 20 m, default 2 m)
  • Configurable max points limit
  • Leaflet map showing original (grey) and simplified (red) routes overlaid
  • Stats for original vs simplified points
  • Direct download of the simplified GPX

Terminal script

# Simplify all GPX files in input/ (output goes to output/)
uv run simplify_gpx.py

# Specific file
uv run simplify_gpx.py input/route.gpx

# Custom output
uv run simplify_gpx.py input/route.gpx -o simplified_route.gpx

Options

Flag Default Description
-t, --tolerance 10 Maximum distance in metres. Points closer to the imaginary line between their neighbours are removed.
-m, --max-points unlimited Maximum number of points per segment. If exceeded after simplification, uniform thinning is applied.

Examples:

# More aggressive (25 m tolerance)
uv run simplify_gpx.py -t 25

# Max 200 points
uv run simplify_gpx.py -m 200

# Combined
uv run simplify_gpx.py input/route.gpx -t 15 -m 500 -o output/route.gpx

How it works

Algorithm: Douglas-Peucker

Both implementations use the Douglas-Peucker algorithm, the standard for polyline simplification:

  1. A straight line is drawn between the first and last point of the segment.
  2. The perpendicular distance from each intermediate point to that line is calculated (using the Haversine formula on a spherical triangle).
  3. If the farthest point exceeds the tolerance, it is kept and the algorithm recurses on both halves.
  4. If none exceed it, all intermediate points are removed.

This algorithm naturally preserves turns: points at curves and route bends deviate from the straight line and therefore exceed the tolerance, while straight sections are reduced to just two points (start and end).

Point limit (--max-points)

If the number of points is still too high after Douglas-Peucker, uniform sampling selects evenly distributed points along the segment, always keeping the first and last point.

What is preserved

  • Turns and curves: points where the route changes direction are kept.
  • Start and end: always present.
  • GPX metadata: name, activity type, track/segment structure.
  • Elevation: preserved for all surviving points.

About

GPX Simplify

Topics

Resources

Stars

Watchers

Forks

Contributors