jamesblanksby/gpxtoolbox

A library for creating, parsing, and modifying GPX files.

2.1.0 2024-06-12 06:25 UTC

README

Maintainability Latest version Downloads

A library for creating, parsing, and modifying GPX files.

📍 Features

  • Full* support for official specification.
  • High performance polyline simplification.
  • Statistics analysis.
  • Activity splits.
  • GPX, JSON, GeoJSON and PHP Array output.

* Extensions coming soon!

Statistics Analysis

  • Smoothed distance (m)
  • Moving duration (s)
  • Total duration (s)
  • Average speed (km/h)
  • Maximum speed (km/h)
  • Average pace (min/km)
  • Best pace (min/km)
  • Minimum elevation (m)
  • Maximum elevation (m)
  • Elevation gain (m)
  • Elevation loss (m)

⚡️ Installation

You can install GPXToolbox with composer.

$ composer require jamesblanksby/gpxtoolbox

📖 Getting Started

Load a GPX file and retrieve statistical analysis.

<?php

use GPXToolbox\GPXToolbox;

include 'vendor/autoload.php';

$toolbox = new GPXToolbox();
$gpx = $toolbox->load('examples/input.gpx');

$statistics = $gpx->getTracks()->getStatistics();

echo sprintf('<pre>%s</pre>', print_r($statistics->toArray(), true));

The above example will output:

Array
(
    [distance] => 51946.58
    [movingDuration] => 29940
    [totalDuration] => 32678
    [averageSpeed] => 6.23
    [maxSpeed] => 13.45
    [averagePace] => 637.46
    [bestPace] => 267.62
    [minElevation] => 64.32
    [maxElevation] => 240.6
    [gainElevation] => 2113.4
    [lossElevation] => 2104.17
)

See the examples directory for more…