ixnode / php-gpx-reader
PHP GPX Reader - A versatile library for reading GPX files and efficiently retrieving GPS coordinates based on timestamps.
Requires
- php: ^8.2
- ext-bcmath: *
- ext-curl: *
- ext-simplexml: *
- adhocore/cli: ^v1.0.0
- ixnode/php-container: ^1.0
- ixnode/php-coordinate: ^1.0
- ixnode/php-date-parser: ^1.0
- ixnode/php-exception: ^0.1
- ixnode/php-timezone: ^0.1.25
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.13
- ixnode/bash-version-manager: ^0.1.10
- jetbrains/phpstorm-attributes: ^1.0
- phpmd/phpmd: ^2.13
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^9.5
- povils/phpmnd: ^3.0
- rector/rector: ^0.15.1
README
PHP GPX Reader - A versatile library for reading GPX files and efficiently retrieving GPS coordinates based on timestamps.
The PHP GPX Reader is a lightweight and powerful tool to find the nearest GPS coordinate from a GPX file based on a specific timestamp. While it's perfect for photo geotagging (e.g., matching photo timestamps to GPS data), the tool can be used in many other scenarios where time-based GPS data needs to be processed.
1. Features
- Reads GPX files and retrieves the closest GPS coordinate to a given timestamp.
- Efficiently handles GPX tracks with multiple points.
- Allows precise time matching to find the nearest location.
- Supports time offset adjustments for scenarios where the reference time is inaccurate.
- Flexible and easy to integrate for different use cases.
2. Usage
use Ixnode\PhpGpxReader\GpxReader; ... $gpxReader = new GpxReader($fileObject); /* Set time gap from camera time: The clock goes ahead. */ $gpxReader->setTimeGapFromString('-00:13:00'); /* Set (real) time to search. */ $gpxReader->setDateTimeFromString('2024-05-05 13:04:16', new DateTimeZone(Timezones::EUROPE_BERLIN)); /* Get the closest coordinate from GPX file. */ $coordinate = $gpxReader->getCoordinate(); /* Time difference to next point. */ print $gpxReader->getTimeDifference(); // (int) 5 /* Latitude to the closest point. */ print $coordinate->getLatitude(); // (float) 47.099262 /* Longitude to the closest point. */ print $coordinate->getLongitude(); // (float) 9.942202 /* Google maps link. */ print $coordinate->getLinkGoogle().PHP_EOL; // (string) https://www.google.de/maps/place/47.099262+9.942202
3. Installation
composer require ixnode/php-gpx-reader
vendor/bin/php-gpx-reader -V
0.1.0 (2024-12-07 19:00:00) - Björn Hempel <bjoern@hempel.li>
4. Command line tool
4.1 Search for the closest point with given taken time
Search for the closest point within a gpx file with given date and camera time gap.
bin/console gpx:read data/gpx/2024-05-05.gpx --date="2024-05-05 13:04:16" --gap="\-00:13:00"
or within your composer project:
vendor/bin/php-gpx-reader gpx:read data/gpx/2024-05-05.gpx --date="2024-05-05 13:04:16" --gap="\-00:13:00"
Time to search: 05.05.2024 10:51:16 UTC
Time difference: 5s
Coordinate: lat=47.099262; lon=9.942202
Coordinate: 47.099262, 9.942202
Google link: https://www.google.de/maps/place/47.099262+9.942202
4.2 Search for the closest point with given image (to read the taken time)
Search for the closest point within a gpx file with given date and camera time gap.
bin/console gpx:read data/gpx/2024-05-05.gpx --image="data/image/example-basic.jpg" --gap="\-00:13:00"
or within your composer project:
vendor/bin/php-gpx-reader gpx:read data/gpx/2024-05-05.gpx --image="data/image/example-basic.jpg" --gap="\-00:13:00"
Time to search: 05.05.2024 10:51:17 UTC
Time difference: 4s
Coordinate: lat=47.099251; lon=9.942342
Coordinate: 47.099251, 9.942342
Google link: https://www.google.de/maps/place/47.099251+9.942342
5. Library development
git clone git@github.com:ixnode/php-gpx-reader.git && cd php-gpx-reader
composer install
composer test
6. License
This library is licensed under the MIT License - see the LICENSE file for details.