Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route import generates error #19

Open
paceband opened this issue Jul 1, 2017 · 4 comments
Open

Route import generates error #19

paceband opened this issue Jul 1, 2017 · 4 comments

Comments

@paceband
Copy link

paceband commented Jul 1, 2017

Hi,

Route import generates error. Adding this line fix the problem:
$this->journey->related->routes = new \stdClass();

	/** Standard constructor
	*
	*/
	function __construct(){
		$this->journey = new \stdClass();
		$this->journey->related = new \stdClass();
		$this->journey->related->waypoints = new \stdClass();
		$this->journey->related->waypoints->points = array();
		$this->journey->related->routes = new \stdClass();
	}

See attached file.

Moreover, in order to make this file work, I had to add thoses lines before ingesting the file:

        $gpx->suppress('speed');
        $gpx->suppress('elevation');
        $gpx->suppress('location');
        $gpx->suppress('date');

gpx-ingest-pb.zip

Thanks

@bentasker
Copy link
Owner

bentasker commented Jul 2, 2017

Hi,

You're right, routes should be defined ahead of time. Will look at fixing that.

Odd that you've had to explicitly suppress those - obviously they're missing from your file, but as of GPXIN-16 it should auto-detect and suppress speed. I'm guessing the way I implemented it doesn't get applied to routes.

Will take a look at it (thanks for providing an example file, makes life much easier).

They won't be in the project mirror quite yet, but have raised the following to track

@paceband
Copy link
Author

paceband commented Jul 2, 2017

Hi,
Importing route was working fine but I've just tested importing a track and I had issues because of the suppression of "elevation" and "location". So now, I just remove those 2 informations that I do not need:

        $gpx->suppress('speed');
        $gpx->suppress('date');

So, importing a track was working back but I had issues with the import of a route.

Here are some quick fix that I did in order to make everthing working fine:

		if (!$this->suppresselevation){
			if (isset($this->journey->journeys)) {
				$this->journey->journeys->$jkey->segments->$segkey->stats->elevation = new \stdClass();
				$this->journey->journeys->$jkey->segments->$segkey->stats->elevation->max = max($this->jeles);
				$this->journey->journeys->$jkey->segments->$segkey->stats->elevation->min = min($this->jeles);
				$this->journey->journeys->$jkey->segments->$segkey->stats->elevation->avgChange = round(array_sum($this->jeledevs)/count($this->jeledevs),2);
			}
		}

		if (!$this->suppresslocation){
			$this->journey->stats->distanceTravelled = array_sum($this->jdist); // See GPXIN-6

			if (!empty($this->journeylats)) {
				// Update the Lat/Lon bounds. See GPXIN-26
				$this->journey->stats->bounds->Lat->min = min($this->journeylats);
				$this->journey->stats->bounds->Lat->max = max($this->journeylats);
			}
			if (!empty($this->journeylons)) {
				$this->journey->stats->bounds->Lon->min = min($this->journeylons);
				$this->journey->stats->bounds->Lon->max = max($this->journeylons);
			}
		}

You can see that I added isset and isempty... This is just a patch but that might give you some hint about making everthing working fine including "speed" and "date"...

BTW, you should hamonize "ele" vs "elevation" for a track point. A route is "ele" and a track is "elevation". My guess is that "ele" would be better for both as you us "lat" and "lon" for coordinates.

Thanks.

@bentasker
Copy link
Owner

Hi,

Yup thats more or less along the lines of the fix I was thinking about.

I may also split the suppression out into being grouped by type (i.e. route vs track) so that if auto suppress fires on one it won't affect the other.

Will take a look at this when I have some time, which should hopefully be within the next couple of days. I think you're right about ele vs elevation, I'll likely look at changing that too to keep things consistent.

If you want, I'm happy to merge a pull with the changes you've made in the meantime?

bentasker added a commit that referenced this issue Jul 3, 2017
#19) to prevent WARNING level entries

Test case is fairly simple:

{noformat}
    <?php

    error_reporting(E_ALL);
    ini_set('display_errors','On');

    require 'src/GPXIngest/GPXIngest.php';

    $gpx = new GPXIngest\GPXIngest;
    $gpx->loadFile('gpx-ingest-pb.gpx');
{noformat}

Where gpx-ingest-pb is a GPX file that makes use of rte points (see #19 for an example)
bentasker added a commit that referenced this issue Jul 3, 2017
…d and only fire if some tracks have been processed

This prevents the fatal error from occurring. There may be other edge cases that can still trigger errors though, so more testing is needed
@bentasker
Copy link
Owner

Hi,

So as I had a bit of time free and haven't touched this project in ages, I've been catching up on the backlog of issues in JIRA.

If you want to give the master branch a try, you should find this issue is resolved.

I've added some route related stats GPXIN-33, as well as methods to get the route data - https://www.bentasker.co.uk/documentation/development-programming/222-php-gpx-ingest#routes (might need to wait for the CDN caches to update)

As your GPX file seemed to be about a marathon, I figured elevation stats might be useful (where the data's available) so you can see how knackering a given route might actually be (i.e. is it mostly uphill?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants