marcusvolz / strava

Create artistic visualisations with your exercise data
Other
523 stars 57 forks source link

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

Open hugovk opened 5 years ago

hugovk commented 5 years ago

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.0     ✔ purrr   0.3.2
✔ tibble  2.1.3     ✔ dplyr   0.8.1
✔ tidyr   0.8.3     ✔ stringr 1.4.0
✔ readr   1.3.1     ✔ forcats 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.

narfel commented 4 years ago

Just my two cents: Since you will invariably have to prepare gpx files these days anyway, i'm afraid the solution of cleaning up bogus trackpoints is outside the scope of this script. A trackpoint with no coordinates is pointless (sorry about that 💃 ).