How to edit GPX files in a text editor

From OpenStreetMap Wiki
Jump to navigation Jump to search

This is an example of how to edit GPX files in a text editor based on this task: delete an trackpoint entry from the gpx file

Summary

Just open it up in a text editor and delete the entire trackpoint entry from the xml.

Here's one of my trackpoints that I don't need:

  <trkpt lat="-37.772000" lon="145.024740">
   <ele>111.781</ele>
   
  </trkpt>

Steps

Here are your rough steps:

  1. Open the track log
    $ java -jar josm-latest.jar 20070915.gpx
    
  2. put your mouse over the cloud of points to be deleted, and write down the coordinates
  3. Open the track log in your favourite text editor
    $ vi 20070915.gpx
    
    (or emacs, or Microsoft WordPad, or whatever)
  4. Search for the co-ordinates you wrote down, leaving off the last part for precision.
  5. Delete all points either side, by looking at the time. You should be able to work out when you stopped moving and roughly when you started again.
  6. If you cross over a <trkseg> take out the end of the first </trkseg> and the beginning of the next, so you'd just end up with one <trkseg>.
  7. After editing, you can run the resulting gpx file through GPSBabel going from gpx to gpx, and it will rebuild a correct bounding tag, which is nice if you've chopped a really long file into smaller bits.

See also