Fix support for GPX files without tracks - #1228
Conversation
Fixes 2 issues: 1. GPXRoute in gpxpy doesn't have a length_3d/length_2d field, just length. This simply cause a warning and a missing length calculation. 2. When converting to geojson, only tracks were taken into account; this now uses routes for files without tracks.
|
@aronsky is attempting to deploy a commit to the Sean Morley's Projects Team on Vercel. A member of the Team first needs to authorize it. |
|
🤖 AdventureLog Bot 🚫 This PR was automatically closed because it does not reference an issue. Please link an issue using |
|
🤖 AdventureLog Bot 🚫 This PR was automatically closed. Pull requests may only be opened for issues labeled ready. |
There was a problem hiding this comment.
🟢 Approval recommended
Only a minor naming nit remains; no blocking issues were identified.
Pull request overview
Fixes support for GPX files containing routes without tracks, including map rendering and distance calculation.
Changes:
- Converts GPX routes to GeoJSON when tracks are absent.
- Uses
GPXRoute.length()for route distance calculations.
File summaries
| File | Summary |
|---|---|
backend/server/adventures/utils/geojson.py |
Adds route-to-GeoJSON conversion; a minor fallback-label nit remains. |
backend/server/adventures/serializers.py |
Corrects GPX route distance calculation. |
Review details
Suppressed comments (2)
backend/server/adventures/serializers.py:554
- This now makes route-only files work, but a GPX can also contain both recorded tracks and planned routes. Because this loop always adds every route after the track lengths, such a file reports the combined track-plus-route distance, while
gpx_to_geojsongives tracks precedence. Treat routes as the fallback when no track data is present so the displayed distance and geometry refer to the same path.
for route in gpx.routes:
route_length = route.length()
if route_length:
total_meters += route_length
backend/server/adventures/utils/geojson.py:34
elifskips every route whenever the GPX contains any track object. GPX permits both tracks and routes, and_parse_gpx_distance_kmcounts both, so the API can report distance for route data that is missing from the map. Process routes independently (or only fall back when no track features were emitted) so both representations remain consistent.
elif gpx.routes:
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
seanmorley15
left a comment
There was a problem hiding this comment.
One little thing, do you agree that it should use the existing _gpx_to_feature_collection function instead of replicating that here?
|
Hi, I'll take a look at this in the coming week or two. Just got back from the trip I planned with AdventureLog, and I'm still getting back on track. |
OK, checked the code. Agreed - the change should be in the function. I missed it because I based my code on the latest release version, and that function simply wasn't there in 0.12.1. |
|
🤖 AdventureLog Bot 🚫 This PR was automatically closed. Pull requests may only be opened for issues labeled ready. |
|
Hi Sean, Just checking in - what's blocking this? It says "changes requested", but I don't see any comments regarding that. |
Related Issue
Closes #1229
Fixed the issue right away, before opening an issue in the repo.
Description
Fixes 2 issues:
GPXRouteobjects ingpxpydon't have alength_3d/length_2dfield, justlength. This simply caused a warning and a missing length calculation.geojson, only tracks were taken into account; this now uses routes for files without tracks.Without these fixes, when a GPX file with just a route (no tracks/segments) was added to a Transportation, the distance of the transportation wasn't calculated based on the route, and the route wasn't displayed on the map (contrary to the promise of the UI : )).
Type of Change
Checklist
Before submitting this PR, please confirm:
Screenshots (if applicable)
If this PR includes UI changes, please include screenshots or GIFs.
Thank you for contributing to AdventureLog! Your efforts help make this project better for everyone. We’ll review your PR as soon as we can. 🙌