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

Error when TrkSeg is empty #33

Closed
QmarXX opened this issue May 20, 2018 · 1 comment
Closed

Error when TrkSeg is empty #33

QmarXX opened this issue May 20, 2018 · 1 comment
Assignees
Labels
Milestone

Comments

@QmarXX
Copy link

QmarXX commented May 20, 2018

TrkSeg can be empty on GPX 1.1 and it causes a problem in your library in method \phpGPX\Models\Track::recalculateStats when I try calculate statistics.

I got a few files with empty on end of files when I using export option on Endomondo.

I wrote quick fix to check trkseg is not empty and use only segments that have points:

$firstSegment = null;

foreach ($this->segments as $segment) {
    if (!empty($segment->points)) {
        if (is_null($firstSegment)) {
            $firstSegment = $segment;
        }

        $lastSegment = $segment;
    }
}

if (!isset($firstSegment) || !isset($lastSegment)) {
    return;
}

$firstPoint = $firstSegment->points[0];
$lastPoint = end($lastSegment->points);

but maybe you will find more optimal solution.

@Sibyx Sibyx self-assigned this May 17, 2020
@Sibyx Sibyx added the bug label May 17, 2020
@Sibyx Sibyx added this to the v1 release milestone May 17, 2020
@Sibyx Sibyx removed this from the v1 release milestone Feb 4, 2021
@Sibyx Sibyx added this to the 1.2 milestone Feb 17, 2021
@Sibyx
Copy link
Owner

Sibyx commented Feb 17, 2021

Resolved in #40

@Sibyx Sibyx closed this as completed Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants