Skip to content

"argument is of length zero" for trkpt with no lat/lon #22

Description

@hugovk

I have a GPX from my Strava ZIP that looks like this (I've snipped away most of the track points), where the first <trkpt> has no lon or lat attributes:

<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" creator="Wahoo ELEMNT BOLT" version="5.8">
  <metadata>
    <link href="https://gotoes.org/strava/Combine_GPX_TCX_FIT_Files.php">
      <text>GOTOES STRAVA TOOLS</text>
    </link>
    <time>2019-08-31T09:02:36Z</time>
  </metadata>
  <trk>
    <type>Other</type>
    <trkseg>
      <trkpt>
        <ele>31.2</ele>
        <time>2019-08-31T09:02:36Z</time>
        <extensions>
          <gpxdata:temp>0</gpxdata:temp>
        </extensions>
      </trkpt>
      <trkpt lon="24.93841" lat="60.16992">
        <ele>31.2</ele>
        <time>2019-08-31T09:02:37Z</time>
        <extensions>
          <gpxdata:temp>29</gpxdata:temp>
        </extensions>
      </trkpt>
      <trkpt lon="24.93841" lat="60.16992">
        <ele>31.2</ele>
        <time>2019-08-31T09:02:38Z</time>
        <extensions>
          <gpxdata:temp>29</gpxdata:temp>
        </extensions>
      </trkpt>
    </trkseg>
  </trk>
</gpx>

Putting that at /tmp/test/test.gpx and running:

> library(gtools)
> library(strava)
> library(tidyverse)
── Attaching packages ─────────────────────────────────────── tidyverse 1.2.1 ──
✔ ggplot2 3.2.0purrr   0.3.2tibble  2.1.3dplyr   0.8.1tidyr   0.8.3stringr 1.4.0readr   1.3.1forcats 0.4.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
> data <- process_data("/tmp/test")
Error in if (ncol(coords) < 2) return(NULL) : argument is of length zero

It probably happens because the first track point doesn't have latitude or longitude attributes (see GPX above).

Can such track points be skipped?

About the data: the problematic file was generated by combining two files using this tool, which is recommended by Strava so will be quite widely used. I don't have the original pre-merge files handy to check if the same issue occurs there or if it was introduced by the merge tool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions