{"id":17780682,"url":"https://github.com/sibyx/phpgpx","last_synced_at":"2025-04-12T14:20:21.162Z","repository":{"id":48374713,"uuid":"66937877","full_name":"Sibyx/phpGPX","owner":"Sibyx","description":"Simple library for reading and creating GPX files written in PHP.","archived":false,"fork":false,"pushed_at":"2024-05-06T12:16:05.000Z","size":485,"stargazers_count":158,"open_issues_count":9,"forks_count":53,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-04-03T13:18:29.330Z","etag":null,"topics":["calculations","composer","geolocation","gis","gps","gpx","gpx-files","hacktoberfest","php","php-library","statistics","xml"],"latest_commit_sha":null,"homepage":"https://sibyx.github.io/phpGPX/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Sibyx.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"ko_fi":"sibyx","custom":["https://www.buymeacoffee.com/Sibyx"]}},"created_at":"2016-08-30T12:19:00.000Z","updated_at":"2025-03-19T18:22:51.000Z","dependencies_parsed_at":"2023-01-24T01:30:58.111Z","dependency_job_id":"ad045328-ac1f-4092-8fec-f9592d3f2eb4","html_url":"https://github.com/Sibyx/phpGPX","commit_stats":{"total_commits":152,"total_committers":22,"mean_commits":6.909090909090909,"dds":0.3223684210526315,"last_synced_commit":"ecde89a9268f78340fa9c016ff68115d3efa9a42"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sibyx%2FphpGPX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sibyx%2FphpGPX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sibyx%2FphpGPX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Sibyx%2FphpGPX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Sibyx","download_url":"https://codeload.github.com/Sibyx/phpGPX/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248578874,"owners_count":21127714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["calculations","composer","geolocation","gis","gps","gpx","gpx-files","hacktoberfest","php","php-library","statistics","xml"],"created_at":"2024-10-27T03:03:30.875Z","updated_at":"2025-04-12T14:20:21.140Z","avatar_url":"https://github.com/Sibyx.png","language":"PHP","readme":"# phpGPX\n\n[![Code Climate](https://codeclimate.com/github/Sibyx/phpGPX/badges/gpa.svg)](https://codeclimate.com/github/Sibyx/phpGPX)\n[![Latest development](https://img.shields.io/packagist/vpre/sibyx/phpgpx.svg)](https://packagist.org/packages/sibyx/phpgpx)\n[![Packagist downloads](https://img.shields.io/packagist/dm/sibyx/phpgpx.svg)](https://packagist.org/packages/sibyx/phpgpx)\n[![Gitter](https://img.shields.io/gitter/room/phpgpx/phpgpx.svg)](https://gitter.im/phpGPX/Lobby)\n\n\nSimple library written in PHP for reading and creating [GPX files](https://en.wikipedia.org/wiki/GPS_Exchange_Format).\n[Documentation](https://sibyx.github.io/phpGPX/) is available using GitHub pages generated by Jekyll.\n\nContribution and feedback is welcome! Please check the issues for TODO. I will be happy every feature or pull request.\n\nRepository branches:\n\n- `master`: latest stable version\n- `develop`: works on `2.x`\n\n## Features\n\n - Full support of [official specification](http://www.topografix.com/GPX/1/1/).\n - Statistics calculation.\n - Extensions.\n - JSON \u0026 XML \u0026 PHP Array output.\n\n### Supported Extensions\n\n- Garmin [TrackPointExtension](https://www8.garmin.com/xmlschemas/TrackPointExtensionv1.xsd): \n   http://www.garmin.com/xmlschemas/TrackPointExtension/v1\n\n### Stats calculation\n\n- (Smoothed) Distance (m)\n- Average speed (m/s)\n- Average pace  (s/km)\n- Min / max altitude (m)\n- Min / max coordinates ([lat,lng])\n- (Smoothed) Elevation gain / loss (m)\n- Start / end (DateTime object)\n- Start / end coordinates ([lat,lng])\n- Duration (seconds)\n\n## Installation\n\nYou can easily install phpGPX library with [composer](https://getcomposer.org/). There is no stable release yet, so\nplease use release candidates.\n\n```\ncomposer require sibyx/phpgpx:1.3.0\n```\n\n## Examples\n\n### Open GPX file and load basic stats\n\n```php\n\u003c?php\nuse phpGPX\\phpGPX;\n\n$gpx = new phpGPX();\n\t\n$file = $gpx-\u003eload('example.gpx');\n\t\nforeach ($file-\u003etracks as $track)\n{\n    // Statistics for whole track\n    $track-\u003estats-\u003etoArray();\n    \n    foreach ($track-\u003esegments as $segment)\n    {\n    \t// Statistics for segment of track\n    \t$segment-\u003estats-\u003etoArray();\n    }\n}\n```\n\n### Writing to file\n```php\n\u003c?php\nuse phpGPX\\phpGPX;\n\n$gpx = new phpGPX();\n\t\n$file = $gpx-\u003eload('example.gpx');\n\n// XML\n$file-\u003esave('output.gpx', phpGPX::XML_FORMAT);\n\t\n//JSON\n$file-\u003esave('output.json', phpGPX::JSON_FORMAT);\n```\n\n### Creating file from scratch\n```php\n\u003c?php\n\nuse phpGPX\\Models\\GpxFile;\nuse phpGPX\\Models\\Link;\nuse phpGPX\\Models\\Metadata;\nuse phpGPX\\Models\\Point;\nuse phpGPX\\Models\\Segment;\nuse phpGPX\\Models\\Track;\n\nrequire_once '/vendor/autoload.php';\n\n$sample_data = [\n\t[\n\t\t'longitude' =\u003e 9.860624216140083,\n\t\t'latitude' =\u003e 54.9328621088893,\n\t\t'elevation' =\u003e 0,\n\t\t'time' =\u003e new \\DateTime(\"+ 1 MINUTE\")\n\t],\n\t[\n\t\t'latitude' =\u003e 54.83293237320851,\n\t\t'longitude' =\u003e 9.76092208681491,\n\t\t'elevation' =\u003e 10.0,\n\t\t'time' =\u003e new \\DateTime(\"+ 2 MINUTE\")\n\t],\n\t[\n\t\t'latitude' =\u003e 54.73327743521187,\n\t\t'longitude' =\u003e 9.66187816543752,\n\t\t'elevation' =\u003e 42.42,\n\t\t'time' =\u003e new \\DateTime(\"+ 3 MINUTE\")\n\t],\n\t[\n\t\t'latitude' =\u003e 54.63342326167919,\n\t\t'longitude' =\u003e 9.562439849679859,\n\t\t'elevation' =\u003e 12,\n\t\t'time' =\u003e new \\DateTime(\"+ 4 MINUTE\")\n\t]\n];\n\n// Creating sample link object for metadata\n$link = new Link();\n$link-\u003ehref = \"https://sibyx.github.io/phpgpx\";\n$link-\u003etext = 'phpGPX Docs';\n\n// GpxFile contains data and handles serialization of objects\n$gpx_file = new GpxFile();\n\n// Creating sample Metadata object\n$gpx_file-\u003emetadata = new Metadata();\n\n// Time attribute is always \\DateTime object!\n$gpx_file-\u003emetadata-\u003etime = new \\DateTime();\n\n// Description of GPX file\n$gpx_file-\u003emetadata-\u003edescription = \"My pretty awesome GPX file, created using phpGPX library!\";\n\n// Adding link created before to links array of metadata\n// Metadata of GPX file can contain more than one link\n$gpx_file-\u003emetadata-\u003elinks[] = $link;\n\n// Creating track\n$track = new Track();\n\n// Name of track\n$track-\u003ename = \"Some random points in logical order. Input array should be already ordered!\";\n\n// Type of data stored in track\n$track-\u003etype = 'RUN';\n\n// Source of GPS coordinates\n$track-\u003esource = \"MySpecificGarminDevice\";\n\n// Creating Track segment\n$segment = new Segment();\n\n\nforeach ($sample_data as $sample_point)\n{\n\t// Creating trackpoint\n\t$point = new Point(Point::TRACKPOINT);\n\t$point-\u003elatitude = $sample_point['latitude'];\n\t$point-\u003elongitude = $sample_point['longitude'];\n\t$point-\u003eelevation = $sample_point['elevation'];\n\t$point-\u003etime = $sample_point['time'];\n\n\t$segment-\u003epoints[] = $point;\n}\n\n// Add segment to segment array of track\n$track-\u003esegments[] = $segment;\n\n// Recalculate stats based on received data\n$track-\u003erecalculateStats();\n\n// Add track to file\n$gpx_file-\u003etracks[] = $track;\n\n// GPX output\n$gpx_file-\u003esave('CreatingFileFromScratchExample.gpx', \\phpGPX\\phpGPX::XML_FORMAT);\n\n// Serialized data as JSON\n$gpx_file-\u003esave('CreatingFileFromScratchExample.json', \\phpGPX\\phpGPX::JSON_FORMAT);\n\n// Direct GPX output to browser\n\nheader(\"Content-Type: application/gpx+xml\");\nheader(\"Content-Disposition: attachment; filename=CreatingFileFromScratchExample.gpx\");\n\necho $gpx_file-\u003etoXML()-\u003esaveXML();\nexit();\n```\n\nCurrently, supported output formats:\n\n - XML\n - JSON\n\n## Configuration\n\nUse the static constants in phpGPX to modify behaviour.\n\n```php\n/**\n * Create Stats object for each track, segment and route\n */\npublic static $CALCULATE_STATS = true;\n\n/**\n * Additional sort based on timestamp in Routes \u0026 Tracks on XML read.\n * Disabled by default, data should be already sorted.\n */\npublic static $SORT_BY_TIMESTAMP = false;\n\n/**\n * Default DateTime output format in JSON serialization.\n */\npublic static $DATETIME_FORMAT = 'c';\n\n/**\n * Default timezone for display.\n * Data are always stored in UTC timezone.\n */\npublic static $DATETIME_TIMEZONE_OUTPUT = 'UTC';\n\n/**\n * Pretty print.\n */\npublic static $PRETTY_PRINT = true;\n\n/**\n * In stats elevation calculation: ignore points with an elevation of 0\n * This can happen with some GPS software adding a point with 0 elevation\n */\npublic static $IGNORE_ELEVATION_0 = true;\n\n/**\n * Apply elevation gain/loss smoothing? If true, the threshold in\n * ELEVATION_SMOOTHING_THRESHOLD and ELEVATION_SMOOTHING_SPIKES_THRESHOLD (if not null) applies\n */\npublic static $APPLY_ELEVATION_SMOOTHING = false;\n\n/**\n * if APPLY_ELEVATION_SMOOTHING is true\n * the minimum elevation difference between considered points in meters\n */\npublic static $ELEVATION_SMOOTHING_THRESHOLD = 2;\n\n/**\n * if APPLY_ELEVATION_SMOOTHING is true\n * the maximum elevation difference between considered points in meters\n */\npublic static $ELEVATION_SMOOTHING_SPIKES_THRESHOLD = null;\n\n/**\n * Apply distance calculation smoothing? If true, the threshold in\n * DISTANCE_SMOOTHING_THRESHOLD applies\n */\npublic static $APPLY_DISTANCE_SMOOTHING = false;\n\n/**\n * if APPLY_DISTANCE_SMOOTHING is true\n * the minimum distance between considered points in meters\n */\npublic static $DISTANCE_SMOOTHING_THRESHOLD = 2;\n```\n\nI wrote this library as part of my job in [Backbone s.r.o.](https://www.backbone.sk/en/).\n\n## License\n\nThis project is licensed under the terms of the MIT license.\n","funding_links":["https://ko-fi.com/sibyx","https://www.buymeacoffee.com/Sibyx"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsibyx%2Fphpgpx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsibyx%2Fphpgpx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsibyx%2Fphpgpx/lists"}