PHP Classes

PHP GPX Library: Parser and generator of GPS Exchange files

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStar 58%Total: 238 All time: 8,054 This week: 86Up
Version License PHP version Categories
phpgpx 16MIT/X Consortium ...5XML, PHP 5, Geography
Description 

Author

This package is a parser and generator of GPS Exchange files.

It can create a new GPX file adding coordinates of the geographic points of the tracks. It can save the track information in GPX XML format or JSON.

The package can also read and parse a GPX file and extract its track statistics like distance, average speed, average pace, minimum and maximum altitude, start and end time, and duration.

Innovation Award
PHP Programming Innovation award nominee
March 2017
Number 13
GPX is a format for exchanging geographic information like waypoints, tracks and routes.

This package parse and write geographic file information in the GPX format.

Manuel Lemos
Picture of Jakub Dubec
  Performance   Level  
Name: Jakub Dubec <contact>
Classes: 1 package by
Country: United Kingdom
Age: ???
All time rank: 4026177 in United Kingdom
Week rank: 200 Up10 in United Kingdom Up
Innovation award
Innovation award
Nominee: 1x

Example

<?php
/**
 * @author Jakub Dubec <jakub.dubec@gmail.com>
 */

use phpGPX\Models\GpxFile;
use
phpGPX\Models\Link;
use
phpGPX\Models\Metadata;
use
phpGPX\Models\Point;
use
phpGPX\Models\Segment;
use
phpGPX\Models\Track;
use
phpGPX\Models\Extensions;
use
phpGPX\Models\Extensions\TrackPointExtension;

require_once
'../vendor/autoload.php';

$sample_data = [
    [
       
'longitude' => 9.860624216140083,
       
'latitude' => 54.9328621088893,
       
'elevation' => 0,
       
'aTemp' => 22,
       
'time' => new \DateTime("+ 1 MINUTE")
    ],
    [
       
'latitude' => 54.83293237320851,
       
'longitude' => 9.76092208681491,
       
'elevation' => 10.0,
       
'aTemp' => 23,
       
'time' => new \DateTime("+ 2 MINUTE")
    ],
    [
       
'latitude' => 54.73327743521187,
       
'longitude' => 9.66187816543752,
       
'elevation' => 42.42,
       
'aTemp' => 24,
       
'time' => new \DateTime("+ 3 MINUTE")
    ],
    [
       
'latitude' => 54.63342326167919,
       
'longitude' => 9.562439849679859,
       
'elevation' => 12,
       
'aTemp' => 25,
       
'time' => new \DateTime("+ 4 MINUTE")
    ]
];

// Creating sample link object for metadata
$link = new Link();
$link->href = "https://sibyx.github.io/phpgpx";
$link->text = 'phpGPX Docs';

// GpxFile contains data and handles serialization of objects
$gpx_file = new GpxFile();

// Creating sample Metadata object
$gpx_file->metadata = new Metadata();

// Time attribute is always \DateTime object!
$gpx_file->metadata->time = new \DateTime();

// Description of GPX file
$gpx_file->metadata->description = "My pretty awesome GPX file, created using phpGPX library!";

// Adding link created before to links array of metadata
// Metadata of GPX file can contain more than one link
$gpx_file->metadata->links[] = $link;

// Creating track
$track = new Track();

// Name of track
$track->name = sprintf("Some random points in logical order. Input array should be already ordered!");

// Type of data stored in track
$track->type = 'RUN';

// Source of GPS coordinates
$track->source = sprintf("MySpecificGarminDevice");

// Creating Track segment
$segment = new Segment();


foreach (
$sample_data as $sample_point) {
   
// Creating trackpoint
   
$point = new Point(Point::TRACKPOINT);
   
$point->latitude = $sample_point['latitude'];
   
$point->longitude = $sample_point['longitude'];
   
$point->elevation = $sample_point['elevation'];
   
$point->time = $sample_point['time'];

   
// Creating trackpoint extension
   
$point->extensions = new Extensions();
   
$trackPointExtension = new TrackPointExtension();
   
$trackPointExtension->aTemp = $sample_point['aTemp'];
   
$point->extensions->trackPointExtension = $trackPointExtension;

   
$segment->points[] = $point;
}

// Add segment to segment array of track
$track->segments[] = $segment;

// Add track to file
$gpx_file->tracks[] = $track;

// Create waypoint
$point = new Point(Point::WAYPOINT);
$point->name = 'Example Waypoint';
$point->latitude = $sample_point['latitude'];
$point->longitude = $sample_point['longitude'];
$point->elevation = $sample_point['elevation'];
$point->time = $sample_point['time'];

// Add waypoint to file
$gpx_file->waypoints[] = $point;

// GPX output
$gpx_file->save('CreateFileFromScratchExample.gpx', \phpGPX\phpGPX::XML_FORMAT);

// Serialized data as JSON
$gpx_file->save('CreateFileFromScratchExample.json', \phpGPX\phpGPX::JSON_FORMAT);

// Direct GPX output to browser

header("Content-Type: application/gpx+xml");
header("Content-Disposition: attachment; filename=CreatingFileFromScratchExample.gpx");

echo
$gpx_file->toXML()->saveXML();
exit();


  Files folder image Files (119)  
File Role Description
Files folder imagedocs (37 files, 1 directory)
Files folder imageexample (6 files)
Files folder imagesrc (1 directory)
Files folder imagetests (3 files, 2 directories)
Accessible without login Plain text file .codeclimate.yml Data Auxiliary data
Accessible without login Plain text file .php_cs Example Example script
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file CODE_OF_CONDUCT.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file ISSUE_TEMPLATE.md Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (119)  /  docs  
File Role Description
Files folder image_data (1 file)
  Accessible without login Plain text file index.md Example Example script
  Accessible without login Plain text file phpGPX-Helpers-DateTimeHelper.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Helpers-GeoHelper.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Helpers-SerializationHelper.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Bounds.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Collection.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Copyright.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Email.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Exte...bstractExtension.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Exte...ckPointExtension.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Extensions.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-GpxFile.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Link.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Metadata.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Person.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Point.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Route.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Segment.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Stats.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-StatsCalculator.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Summarizable.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Models-Track.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-BoundsParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-CopyrightParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-EmailParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-ExtensionParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-Ext...tExtensionParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-LinkParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-MetadataParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-PersonParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-PointParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-RouteParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-SegmentParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-TrackParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-Parsers-WaypointParser.md Data Auxiliary data
  Accessible without login Plain text file phpGPX-phpGPX.md Data Auxiliary data
  Accessible without login Plain text file _config.yml Data Auxiliary data

  Files folder image Files (119)  /  docs  /  _data  
File Role Description
  Accessible without login Plain text file authors.yml Data Auxiliary data

  Files folder image Files (119)  /  example  
File Role Description
  Accessible without login Plain text file CreateFileFromScratch.php Example Example script
  Accessible without login Plain text file Example.php Example Example script
  Accessible without login Plain text file output_waypoint_test.gpx Data Auxiliary data
  Accessible without login Plain text file waypoints_create.php Example Example script
  Accessible without login Plain text file waypoints_load.php Example Example script
  Accessible without login Plain text file waypoint_test.gpx Data Auxiliary data

  Files folder image Files (119)  /  src  
File Role Description
Files folder imagephpGPX (1 file, 3 directories)

  Files folder image Files (119)  /  src  /  phpGPX  
File Role Description
Files folder imageHelpers (5 files)
Files folder imageModels (16 files, 1 directory)
Files folder imageParsers (12 files, 1 directory)
  Plain text file phpGPX.php Class Class source

  Files folder image Files (119)  /  src  /  phpGPX  /  Helpers  
File Role Description
  Plain text file DateTimeHelper.php Class Class source
  Plain text file DistanceCalculator.php Class Class source
  Plain text file ElevationGainLossCalculator.php Class Class source
  Plain text file GeoHelper.php Class Class source
  Plain text file SerializationHelper.php Class Class source

  Files folder image Files (119)  /  src  /  phpGPX  /  Models  
File Role Description
Files folder imageExtensions (2 files)
  Plain text file Bounds.php Class Class source
  Plain text file Collection.php Class Class source
  Plain text file Copyright.php Class Class source
  Plain text file Email.php Class Class source
  Plain text file Extensions.php Class Class source
  Plain text file GpxFile.php Class Class source
  Plain text file Link.php Class Class source
  Plain text file Metadata.php Class Class source
  Plain text file Person.php Class Class source
  Plain text file Point.php Class Class source
  Plain text file Route.php Class Class source
  Plain text file Segment.php Class Class source
  Plain text file Stats.php Class Class source
  Plain text file StatsCalculator.php Class Class source
  Plain text file Summarizable.php Class Class source
  Plain text file Track.php Class Class source

  Files folder image Files (119)  /  src  /  phpGPX  /  Models  /  Extensions  
File Role Description
  Plain text file AbstractExtension.php Class Class source
  Plain text file TrackPointExtension.php Class Class source

  Files folder image Files (119)  /  src  /  phpGPX  /  Parsers  
File Role Description
Files folder imageExtensions (1 file)
  Plain text file BoundsParser.php Class Class source
  Plain text file CopyrightParser.php Class Class source
  Plain text file EmailParser.php Class Class source
  Plain text file ExtensionParser.php Class Class source
  Plain text file LinkParser.php Class Class source
  Plain text file MetadataParser.php Class Class source
  Plain text file PersonParser.php Class Class source
  Plain text file PointParser.php Class Class source
  Plain text file RouteParser.php Class Class source
  Plain text file SegmentParser.php Class Class source
  Plain text file TrackParser.php Class Class source
  Plain text file WaypointParser.php Class Class source

  Files folder image Files (119)  /  src  /  phpGPX  /  Parsers  /  Extensions  
File Role Description
  Plain text file TrackPointExtensionParser.php Class Class source

  Files folder image Files (119)  /  tests  
File Role Description
Files folder imagefixtures (3 files)
Files folder imageUnitTests (1 directory)
  Plain text file CreateWaypointTest.php Class Class source
  Plain text file LoadFileTest.php Class Class source
  Plain text file LoadRouteFileTest.php Class Class source

  Files folder image Files (119)  /  tests  /  fixtures  
File Role Description
  Accessible without login Plain text file gps-track.gpx Data Auxiliary data
  Accessible without login Plain text file route.gpx Data Auxiliary data
  Accessible without login Plain text file timezero.gpx Data Auxiliary data

  Files folder image Files (119)  /  tests  /  UnitTests  
File Role Description
Files folder imagephpGPX (2 directories)

  Files folder image Files (119)  /  tests  /  UnitTests  /  phpGPX  
File Role Description
Files folder imageHelpers (3 files)
Files folder imageParsers (19 files)

  Files folder image Files (119)  /  tests  /  UnitTests  /  phpGPX  /  Helpers  
File Role Description
  Plain text file DateTimeHelperTest.php Class Class source
  Plain text file GeoHelperTest.php Class Class source
  Plain text file SerializationHelperTest.php Class Class source

  Files folder image Files (119)  /  tests  /  UnitTests  /  phpGPX  /  Parsers  
File Role Description
  Plain text file AbstractParserTest.php Class Class source
  Accessible without login Plain text file BoundsParserTest.json Data Auxiliary data
  Plain text file BoundsParserTest.php Class Class source
  Accessible without login Plain text file BoundsParserTest.xml Data Auxiliary data
  Accessible without login Plain text file CopyrightParserTest.json Data Auxiliary data
  Plain text file CopyrightParserTest.php Class Class source
  Accessible without login Plain text file CopyrightParserTest.xml Data Auxiliary data
  Accessible without login Plain text file EmailParserTest.json Data Auxiliary data
  Plain text file EmailParserTest.php Class Class source
  Accessible without login Plain text file EmailParserTest.xml Data Auxiliary data
  Accessible without login Plain text file ExtensionParserTest.json Data Auxiliary data
  Plain text file ExtensionParserTest.php Class Class source
  Accessible without login Plain text file ExtensionParserTest.xml Data Auxiliary data
  Accessible without login Plain text file LinkParserTest.json Data Auxiliary data
  Plain text file LinkParserTest.php Class Class source
  Accessible without login Plain text file LinkParserTest.xml Data Auxiliary data
  Accessible without login Plain text file PersonParserTest.json Data Auxiliary data
  Plain text file PersonParserTest.php Class Class source
  Accessible without login Plain text file PersonParserTest.xml Data Auxiliary data

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:238
This week:0
All time:8,054
This week:86Up
User Ratings User Comments (1)
 All time
Utility:75%StarStarStarStar
Consistency:68%StarStarStarStar
Documentation:68%StarStarStarStar
Examples:75%StarStarStarStar
Tests:-
Videos:-
Overall:58%StarStarStar
Rank:1386
 
nice
7 years ago (muabshir)
80%StarStarStarStarStar