An open API service indexing awesome lists of open source software.

https://github.com/bernhardangerer/gpx-stats-helper

The "GPX stats helper" library allows reading from GPX files (GPS data) and calculates a lot of helpful parameters
https://github.com/bernhardangerer/gpx-stats-helper

geocoding gps-data gpx gpx-library gpx-reader java java-11 openstreetmap reverse-geocoding statistics

Last synced: 6 months ago
JSON representation

The "GPX stats helper" library allows reading from GPX files (GPS data) and calculates a lot of helpful parameters

Awesome Lists containing this project

README

          

[![Maven Package](https://github.com/BernhardAngerer/gpx-stats-helper/actions/workflows/maven-publish.yml/badge.svg)](https://github.com/BernhardAngerer/gpx-stats-helper/actions/workflows/maven-publish.yml)
[![Maven Package](https://github.com/BernhardAngerer/gpx-stats-helper/actions/workflows/maven-verify.yml/badge.svg)](https://github.com/BernhardAngerer/gpx-stats-helper/actions/workflows/maven-verify.yml)

# πŸ›°οΈ GPX Stats Helper Library

A lightweight Java library for **reading, manipulating, writing, and analyzing statistics** from GPX 1.1 files using the official [TopoGrafix XSD schema](https://www.topografix.com/gpx.asp).

This library enables developers to:
- Parse and generate GPX 1.1-compliant files
- Integrate with external APIs for reverse geocoding (OpenStreetMap/Nominatim)
- Calculate key track statistics (distance, elevation, duration, speed, slope, etc.)

## πŸ“Š Track Statistics Calculated

### 🧭 General Track Info
- Number of waypoints

### πŸ“ Distance & Elevation
- Total / ascent / flat / descent distance `[m]`
- Ascent / descent elevation `[m]`
- Lowest / highest point `[m]`
- Slope between two waypoints as percentage `%`
- Slope distribution summary: percentage range β†’ distance `[%, m]`

### ⏱️ Time & Duration
- Total duration `[h]`
- Duration in motion / at rest `[h]`
- Start / end time `[h]`

### 🚴 Speed & Movement
- Max / average speed `[km/h]`
- Total / In Motion average pace `[min/km]`

### πŸ—ΊοΈ Geographic Extents
- Latitude range `[lat, lat]`
- Longitude range `[lon, lon]`

### πŸ“ Geopositions
- Start / end / farthest position `[lon, lat, m]`
- Positive and negative elevation peak positions `[lon, lat, m]`

### πŸ”„ Coordinate Format Conversion
- Convert decimal degrees to Degrees Minutes Seconds (DMS) format

### πŸ—£οΈ Geolocation Metadata
- Description of any geo-position
*(using the free [Nominatim API](https://nominatim.org/release-docs/develop/api/Reverse/) for reverse geocoding based on OpenStreetMap data)*

## βœ… Requirements
+ Java 17+
+ Maven

## πŸš€ Examples

### πŸ“₯ Read GPX object from file
```java
GpxReader.fromFile("example/example1.gpx").getTrk().stream()
.flatMap(track -> track.getTrkseg().stream())
.flatMap(trackSegment -> trackSegment.getTrkpt().stream())
.forEach(waypoint -> System.out.println(formatWaypoint(waypoint)));
```

### πŸ’Ύ Write GPX object to file
```java
Gpx gpx = new Gpx();
Track track = new Track();
TrackSegment segment = new TrackSegment();

segment.getTrkpt().addAll(List.of(
createWaypoint(47.80743, 12.378228, 587, LocalDateTime.of(2025, 4, 7, 16, 14, 16)),
createWaypoint(47.807343, 12.378138, 588, LocalDateTime.of(2025, 4, 7, 16, 14, 17))
));

track.getTrkseg().add(segment);
gpx.getTrk().add(track);

File file = GpxWriter.toFile(gpx, "output/generatedFile.gpx");
```

### 🧾 Example Output (`example.gpx`)

> Generated by running `Example.main()`
```
πŸ—‚οΈ Metadata
Name: "My sport activities"
Author Name: "Bernhard Angerer"
Copyright Year: "2022"
Copyright Author: "Bernhard Angerer"
Link Href: "https://github.com/BernhardAngerer"

### Track Nr. 1 - "Mountainbike-Tour to the Kampenwand/Germany" ###

🧭 General Track Info
Number Of Waypoints: 2108

πŸ“ Distance & Elevation
Distance (Total): 26,42 km
Distance (Ascent): 9,56 km
Distance (Flat): 7,78 km
Distance (Descent): 9,07 km
Distance (Unknown Elevation): 0 km
Elevation (Ascent): 1008 m
Elevation (Descent): 997 m
Highest Point: 1547 m.s.l.
Lowest Point: 587 m.s.l.
Slope between start and end point: 69 %
Slope 20 to 30 % -> 0,02 km
Slope 10 to 20 % -> 2,03 km
Slope 0 to 10 % -> 15,3 km
Slope -10 to 0 % -> 5 km
Slope -20 to -10 % -> 3,66 km
Slope -30 to -20 % -> 0,41 km

πŸ—ΊοΈ Geographic Extents
Latitude Range: 47.754356 => 47.80743
Longitude Range: 12.334281 => 12.378897

⏱️ Time & Duration
Duration (Total): 02:36:34 h
Duration (Motion): 02:15:36 h
Duration (Rest): 00:20:58 h
Start Time: 07.09.2021, 15:37:42 h
End Time: 07.09.2021, 18:14:16 h

🚴 Speed & Movement
Speed (Maximum): 51,9 km/h
Speed (Average): 11,7 km/h
Pace Average (Total): 05:56 min/km
Pace Average (Motion): 05:08 min/km

πŸ“ Geopositions
Start Position: Lat 47.80743, Lon 12.378228, Ele 587
End Position: Lat 47.807346, Lon 12.378055, Ele 598
Farthest Point: Lat 47.754356, Lon 12.355104, Ele 1546
Positive Peak 1: Lat 47.754635, Lon 12.355498, Ele 1547
Negative Peak 1: Lat 47.80743, Lon 12.378228, Ele 587
Negative Peak 2: Lat 47.807049, Lon 12.378118, Ele 598

πŸ”„ Coordinate Format Conversion
Lat 47.80743, Lon 12.378228 -> 47Β°48'26.748"N, 12Β°22'41.621"E

πŸ—£οΈ Geolocation Metadata
Start = End - Geoposition: Lindenstraße, Bergham, Kraimoos, Bernau am Chiemsee, Landkreis Rosenheim, Bayern, 83233, Deutschland
Start = End - Geoposition URL: https://nominatim.openstreetmap.org/ui/reverse.html?lat=47.80743&lon=12.378228&zoom=18&layer=poi

### Track Nr. 2 - "Mountainbike-Tour in the Karwendel-Mountains from Scharnitz to Radfeld" ###
...
```

## πŸ“¦ Dependency (Maven / Gradle)

Add the dependency via https://jitpack.io/private#BernhardAngerer/gpx-stats-helper/4.0.0