GPS Data

From Processing

Jump to: navigation, search

This page presents a Processing library to help you read and manipulate GPS data in the GPX format. Only basic information (latitude, longitude, elevation and time) is parsed but this should cover most uses; you will need to adjust the library if you need to support GPX extensions.

A GPX file is an XML file with a collection of GPS Tracks inside. Each GPS Track has a name, and is a collection of GPS Track Segments. Each segment is a collection of GPS Points with latitude and longitude as well as an elevation and timestamp. A GPX file can also contain waypoints, with lat/lon position and name and type. No other information is parsed by this library.


Reading and Displaying GPS Data Using a Simple GPX Library

First, import the library and declare a global instance of the GPX object.

import tomc.gpx.*;
// declare a GPX object
GPX gpx;

Then, inside setup(), instantiate the GPX object, and tell it which file to parse. The file should be inside your data folder, or you can use a full URL.

//initialise the GPX object
gpx = new GPX(this);
// parse test.gpx from the sketch data folder
gpx.parse("test.gpx"); // or a URL

Finally, in your draw() function, loop through the tracks and waypoints and draw them however you would like. See the example applet for drawing GPS tracks on a sphere.

for (int i = 0; i < gpx.getTrackCount(); i++) {
  GPXTrack trk = gpx.getTrack(i);
  // do something with
  for (int j = 0; j < trk.size(); j++) {
    GPXTrackSeg trkseg = trk.getTrackSeg(j);
    for (int k = 0; k < trkseg.size(); k++) {
      GPXPoint pt = trkseg.getPoint(k);
      // do something with or pt.lon
for (int i = 0; i < gpx.getWayPointCount(); i++) {
  GPXWayPoint wpt = gpx.getWayPoint(i);
  // do something with or wpt.lon or or wpt.type


Unzip the archive and place the gpx folder into your Processing libraries folder, then restart Processing.

Bugs / Requests

This library has only been tested with a few different files, and I expect it will need updating to properly handle things like waypoints with elevation, and so on. If you find a file that breaks it, please file an issue at


This library is distributed with full source code under the LGPL.


Processing GPX project on Github (use the downloads button to get the latest in a zip file)

Related Links

  • GPX homepage
  • example applet (Note that raw GPS is not a clean format, and that it requires further processing to remove erroneous data. Thanks to Toby for the file.)
Personal tools