<?php if (version_compare(PHP_VERSION, '5.6.0') <= 0) { die('This example requires at least PHP version 5.6.0' . PHP_EOL . ' but you are only running version ' . PHP_VERSION . PHP_EOL); } include __DIR__ . '/classes/Bootstrap.php'; include __DIR__ . '/functions/filter.php'; // Create our initial Generator to read the gpx file $gpxFilename = __DIR__ . '/data/Roman_2015-11-23.gpx'; $gpxReader = new GpxReader\GpxHandler($gpxFilename); // Define the date/time filter parameters $startTime = new DateTime('2015-11-23 13:20:00Z'); $endTime = new DateTime('2015-11-23 13:30:00Z'); // Create the filter callback with the date/time parameters we've just defined $timeFilter = function ($timestamp) use($startTime, $endTime) { return $timestamp >= $startTime && $timestamp <= $endTime; }; // Iterate over the trackpoint set from the gpx file, displaying each point detail in turn foreach (filter($gpxReader->getElements('trkpt'), $timeFilter, ARRAY_FILTER_USE_KEY) as $time => $element) { printf('%s' . PHP_EOL . ' latitude: %7.4f longitude: %7.4f elevation: %d' . PHP_EOL, $time->format('Y-m-d H:i:s'), $element->position->latitude, $element->position->longitude, $element->elevation); }
<?php if (version_compare(PHP_VERSION, '5.5.0') <= 0) { die('This example requires at least PHP version 5.5.0' . PHP_EOL . ' but you are only running version ' . PHP_VERSION . PHP_EOL); } include __DIR__ . '/classes/Bootstrap.php'; include __DIR__ . '/functions/map.php'; include __DIR__ . '/functions/column.php'; // Create our initial Generator to read the gpx file $gpxFilename = __DIR__ . '/data/Roman_2015-11-23.gpx'; $gpxReader = new GpxReader\GpxHandler($gpxFilename); // Set the mapper to calculate the distance between a trackpoint and the previous trackpoint $distanceCalculator = new GpxReader\Helpers\DistanceCalculator(); // Iterate over the trackpoint set from the gpx file, mapping the distance and extracting only that property to display foreach (column(map([$distanceCalculator, 'setDistance'], $gpxReader->getElements('trkpt')), 'distance') as $key => $value) { printf('%d => %5.2f' . PHP_EOL, $key, $value); }
<?php if (version_compare(PHP_VERSION, '5.5.0') <= 0) { die('This example requires at least PHP version 5.5.0' . PHP_EOL . ' but you are only running version ' . PHP_VERSION . PHP_EOL); } include __DIR__ . '/classes/Bootstrap.php'; include __DIR__ . '/functions/map.php'; include __DIR__ . '/functions/reduce.php'; // Create our initial Generator to read the gpx file $gpxFilename = __DIR__ . '/data/Roman_2015-11-23.gpx'; $gpxReader = new GpxReader\GpxHandler($gpxFilename); // Set the mapper to calculate the distance between a trackpoint and the previous trackpoint $distanceCalculator = new GpxReader\Helpers\DistanceCalculator(); // Reduce our trackpoint set from the gpx file (mapping the distance as we go) and summing the results to calculate the total distance travelled $totalDistance = reduce(map([$distanceCalculator, 'setDistance'], $gpxReader->getElements('trkpt')), function ($runningTotal, $value) { $runningTotal += $value->distance; return $runningTotal; }, 0.0); // Display the results of our reduce printf('Total distance travelled is %5.2f km' . PHP_EOL, $totalDistance / 1000);
<?php if (version_compare(PHP_VERSION, '5.5.0') <= 0) { die('This example requires at least PHP version 5.5.0' . PHP_EOL . ' but you are only running version ' . PHP_VERSION . PHP_EOL); } include __DIR__ . '/classes/Bootstrap.php'; include __DIR__ . '/functions/withGenerator.php'; // Create our initial Generator to read the gpx file $gpxFilename = __DIR__ . '/data/Roman_2015-11-23.gpx'; $gpxReader = new \GpxReader\GpxHandler($gpxFilename); $trackPoints = $gpxReader->getElements('trkpt'); // Create a bounding box defining the coordinates we want to test each point against // This bounding box is for inside the house/garden $boundaries = new \GpxReader\Helpers\BoundingBox(); $boundaries->setLatitudes(53.54382, 53.5434); $boundaries->setLongitudes(-2.74059, -2.74005); // We want to set the filter to include only points inside the bounding box $boundingBoxFilter = [$boundaries, 'inside']; // Define the date/time filter parameters $startTime = new \DateTime('2015-11-23 12:00:00Z'); $endTime = new \DateTime('2015-11-23 12:20:00Z'); // Create the filter callback with the date/time parameters we've just defined $timeFilter = function ($timestamp) use($startTime, $endTime) { return $timestamp >= $startTime && $timestamp <= $endTime; }; // Set the mapper to calculate the distance between a trackpoint and the previous trackpoint $distanceCalculator = new \GpxReader\Helpers\DistanceCalculator(); // We'll use a callback for the display as well $display = function ($time, $element) { printf('%s' . PHP_EOL . ' latitude: %7.4f longitude: %7.4f elevation: %d' . PHP_EOL . ' distance from previous point: %5.2f m' . PHP_EOL, $time->format('Y-m-d H:i:s'), $element->position->latitude, $element->position->longitude, $element->elevation, $element->distance); };
<?php if (version_compare(PHP_VERSION, '5.5.0') <= 0) { die('This example requires at least PHP version 5.5.0' . PHP_EOL . ' but you are only running version ' . PHP_VERSION . PHP_EOL); } include __DIR__ . '/classes/Bootstrap.php'; // Create our initial Generator to read the gpx file $gpxFilename = __DIR__ . '/data/Roman_2015-11-23.gpx'; $gpxReader = new GpxReader\GpxHandler($gpxFilename); // Iterate over the trackpoint set from the gpx file, displaying each point detail in turn foreach ($gpxReader->getElements('trkpt') as $time => $element) { printf('%s' . PHP_EOL . ' latitude: %7.4f longitude: %7.4f elevation: %d' . PHP_EOL, $time->format('Y-m-d H:i:s'), $element->position->latitude, $element->position->longitude, $element->elevation); }
<?php if (version_compare(PHP_VERSION, '5.5.0') <= 0) { die('This example requires at least PHP version 5.5.0' . PHP_EOL . ' but you are only running version ' . PHP_VERSION . PHP_EOL); } include __DIR__ . '/classes/Bootstrap.php'; include __DIR__ . '/functions/filter55.php'; // Create our initial Generator to read the gpx file $gpxFilename = __DIR__ . '/data/Roman_2015-11-23.gpx'; $gpxReader = new GpxReader\GpxHandler($gpxFilename); // Create a bounding box defining the coordinates we want to test each point against $boundaries = new GpxReader\Helpers\BoundingBox(); $boundaries->setLatitudes(53.54382, 53.5434); $boundaries->setLongitudes(-2.74059, -2.74005); // We want to set the filter to include only points inside the bounding box $boundingBoxFilter = [$boundaries, 'inside']; // Iterate over the trackpoint set from the gpx file, displaying each point detail in turn foreach (filter($gpxReader->getElements('trkpt'), $boundingBoxFilter) as $time => $element) { printf('%s' . PHP_EOL . ' latitude: %7.4f longitude: %7.4f elevation: %d' . PHP_EOL, $time->format('Y-m-d H:i:s'), $element->position->latitude, $element->position->longitude, $element->elevation); }
<?php if (version_compare(PHP_VERSION, '5.5.0') <= 0) { die('This example requires at least PHP version 5.5.0' . PHP_EOL . ' but you are only running version ' . PHP_VERSION . PHP_EOL); } include __DIR__ . '/classes/Bootstrap.php'; include __DIR__ . '/functions/reduce.php'; // Create our initial Generator to read the gpx file $gpxFilename = __DIR__ . '/data/Roman_2015-11-23.gpx'; $gpxReader = new GpxReader\GpxHandler($gpxFilename); // Set our bounding box callback $boundaries = new GpxReader\Helpers\BoundingBox(); // Reduce our trackpoint set from the gpx file against the bounding box callback $boundingBox = reduce($gpxReader->getElements('trkpt'), [$boundaries, 'calculate']); // Display the results of our reduce echo 'Bounding box co-ordinates:', PHP_EOL; printf('Top: %7.4f Bottom: %7.4f' . PHP_EOL . 'Left: %7.4f Right: %7.4f' . PHP_EOL, $boundingBox->top, $boundingBox->bottom, $boundingBox->left, $boundingBox->right);
<?php if (version_compare(PHP_VERSION, '5.5.0') <= 0) { die('This example requires at least PHP version 5.5.0' . PHP_EOL . ' but you are only running version ' . PHP_VERSION . PHP_EOL); } include __DIR__ . '/classes/Bootstrap.php'; include __DIR__ . '/functions/map.php'; // Create our initial Generator to read the gpx file $gpxFilename = __DIR__ . '/data/Roman_2015-11-23.gpx'; $gpxReader = new GpxReader\GpxHandler($gpxFilename); // Set the mapper to calculate the distance between a trackpoint and the previous trackpoint $distanceCalculator = new GpxReader\Helpers\DistanceCalculator(); // Iterate over the trackpoint set from the gpx file, mapping the distances as we go, displaying each point detail in turn foreach (map([$distanceCalculator, 'setDistance'], $gpxReader->getElements('trkpt')) as $time => $element) { printf('%s' . PHP_EOL . ' latitude: %7.4f longitude: %7.4f elevation: %d' . PHP_EOL . ' distance from previous point: %5.2f m' . PHP_EOL, $time->format('Y-m-d H:i:s'), $element->position->latitude, $element->position->longitude, $element->elevation, $element->distance); }