Skip to content

Fix imported routes collapsing to straight lines on heatmap#2291

Merged
robiningelbrecht merged 8 commits into
dreeveapp:masterfrom
cgtobi:fix/heatmap-polyline-simplify-tolerance
Jul 21, 2026
Merged

Fix imported routes collapsing to straight lines on heatmap#2291
robiningelbrecht merged 8 commits into
dreeveapp:masterfrom
cgtobi:fix/heatmap-polyline-simplify-tolerance

Conversation

@cgtobi

@cgtobi cgtobi commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Improvement
  • Translations
  • Documentation Update

Description

Polyline::simplify() defaulted to a tolerance of 0.4, but the tolerance is expressed in degrees (~44km). Douglas-Peucker therefore dropped every point within 0.4 degrees of the start-end chord, collapsing any normal GPS route to just its endpoints - a straight line on the heatmap.

Affected all file imports (FIT/TCX/GPX), which run coordinates through simplify(); Strava import is unaffected as its polyline comes from the API.

Lower the default tolerance to 0.0001 (~11m) and add a regression test pinning the default against a realistic GPS-scale route.

Fixes #2289

Polyline::simplify() defaulted to a tolerance of 0.4, but the tolerance
is expressed in degrees (~44km). Douglas-Peucker therefore dropped every
point within 0.4 degrees of the start-end chord, collapsing any normal
GPS route to just its endpoints - a straight line on the heatmap.

Affected all file imports (FIT/TCX/GPX), which run coordinates through
simplify(); Strava import is unaffected as its polyline comes from the API.

Lower the default tolerance to 0.0001 (~11m) and add a regression test
pinning the default against a realistic GPS-scale route.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@robiningelbrecht

robiningelbrecht commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

We need a migration to fix the faulty activities (any activity with importSource=files) so people do not need to re-import those activities.

I'll add some other small improvements as well.

cgtobi and others added 4 commits July 21, 2026 11:40
Activities already imported from FIT/TCX/GPX files have a collapsed
2-point polyline stored (the straight line caused by the simplify(0.4)
bug). Recompute their polyline from the still-intact latlng stream, using
the corrected simplify tolerance, so users don't have to re-import.

Scoped to file imports (fitFile/tcxFile/gpxFile); Strava API polylines are
left untouched. Irreversible data migration (down() is a no-op).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Lowering the simplify() tolerance for the heatmap made the stored polyline
denser. That polyline is also fed to the geosop binary for country
detection, where the route WKT is passed as a single CLI argument; a dense,
high-frequency route produces a WKT exceeding the OS MAX_ARG_STRLEN (~128KB)
and crashes the import with "Failed to run geosop" (regression of dreeveapp#2230).

Simplify the geosop input on its own (aggressive ~1.1km tolerance) so the
argument stays bounded regardless of the stored polyline's density. The
stored polyline keeps full fidelity for the heatmap. Add a regression test
with a 40k-point route that previously overflowed the argument.

Also pin the data migration's simplify() tolerance explicitly so the
historical migration is frozen against future default changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@robiningelbrecht
robiningelbrecht merged commit c12cce6 into dreeveapp:master Jul 21, 2026
1 check passed
@cgtobi
cgtobi deleted the fix/heatmap-polyline-simplify-tolerance branch July 21, 2026 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Heatmap - imported routes (FIT) collapse to straight line start→end

2 participants