If you are developing a Streams application that uses the Geospatial toolkit to monitor moving objects, you may have come across sample data in GPX (GPS Exchange) format and want to use it to test your application. This article will show you how to do so.


  • Streams version 4.0 and above, which includes version 2.0+ of the Geospatial toolkit.
  • GPXToTuple toolkit from Github.
  • (Optional) MapViewer toolkit (to run the sample application).


GPX, or GPS Exchange format, is a file format used to store GPS based location data.  Although they generally have a .gpx extension, GPX files are really XML files.  Each element in the file represents an entity’s location (latitude, longitude, elevation) at a specific point in time. An entire file would thus represent an entity’s movements over time.  Below is a sample element from a GPX file, that shows the aforementioned attributes:

<trkpt lat="43.702397" lon="-79.640605">


GPS tracking applications, such as those that can be installed on a smartphone, will often generate data representing trips in this format.  Since all of the operators in the Geospatial toolkit detect patterns in the location of a moving object, GPX data is a natural fit to provide input to these operators. This article will show you how to read data from a GPX file and produce Streams tuples that can be then used with any of the Geospatial toolkit operators. We will create a simple Streams app that imports the GPX data and demonstrate how to quickly visualize it using the MapViewer utility application.

GPXToTuple toolkit

The GPXToTuple toolkit in the samples project on GitHub has been developed to show you how this can be done. The toolkit includes a composite operator called GPXFileToTuple for converting GPX files to tuples.

The GPXFileToTuple operator takes the name of a GPX file as input, and for each location element in the file, emits a Streams tuple describing that location.

Here is the example of an invocation of the composite:

stream<EntityLocationData> ConvertedData= GPXFileToTuple()


fileName : "input/sample.gpx" ; //name of the file to read
entityId : "Natasha" ; //name of the moving entity



How it Works

Inside the GPXToTuple operator, the bulk of the work is done by the XMLParse operator, which parses each line from the GPX file and extracts the needed attributes using XPath expressions, as shown below in this excerpt:


 stream<rstring line> Input = FileSource()
   file: $fileName;
   format : line ;
stream<GPX_Data> ParsedXML = XMLParse(Input)
   trigger : "/gpx/trk/trkseg/trkpt" ;
   parsing : permissive ; // log and ignore errors
   ignoreNamespaces : true ;
   ParsedXML : entityId = $entityId, longitude =(float64) XPath("@lon"),
               latitude =(float64) XPath("@lat"), time = XPath("time/text()") ;

If you are interested in extracting other attributes from the GPX file you can do so easily by adding another XPath expression. The operator also does

Trying it out

The toolkit includes a sample application, called PlotGPXFile, that shows how to use the operator. This application uses the operator to read trip history recorded in a GPX file and sends the tuples to a web application that displays it in a map.

Here is a screenshot showing the result of running the PlotGPXFile sample. Each red marker represents the entity’s location at a specific point in time.



To try the application yourself, download the project from GitHub and compile and launch the PlotGPXFile application, optionally specifying the port for the web app. The default port is 8081. After launching, go to http://[PE Host]:[PORT]/map/map.html in your browser.

The sample application uses the MapViewer operator to display the location data on a map in the browser. To learn more about the MapViewer operator, see this article.


This has been a brief demonstration of how to parse GPX files in Streams applications. Now that you can consume location data, learn how to put it to work with the Geospatial toolkit by tracking moving vehicles or in a smart marketing campaign.

Download the toolkit from GitHub.

Join The Discussion