36

I keep writing custom code to work with GPS tracks: GPX files and NMEA logs from my phone, dedicated GPS logger, etc. I feel like I'm reinventing the wheel and am wondering if there's some standard library / tool I can use to work with GPS tracks. Some of the things I like to do:

  • Calculate the distance travelled on the track
  • Calculate the average speed and instantaneous speeds along the track
  • Calculate time in motion vs. time stationary
  • Simplify the track, eliminate stationary segments
  • Segment a track into separate tracks, one per trip
  • Smooth out GPS sampling error
  • Create an elevation profile by looking up points in a DEM
  • Convert the tracks to GPX, KML, etc for visualization

There are a variety of applications that analyze GPS tracks. I'm looking for a software library or scriptable set of tools so I can write my own applications. I don't much care about input formats; any sort of timestamped lat/lon points is fine. I mostly work in Python on Unix but pretty much any language will do.

Existing tools I use include GPSBabel and GDAL/OGR for conversion and PostGIS for working with the track geometry as a line string. But mostly I end up writing my own Python code that works on arrays of lat/lon pairs and that feels too low level. Also some of the tasks above (like removing GPS error) are quite subtle. Is there some existing library out there I should be using?

7
  • 1
    After a week or two and a bounty I think the answer to my question here is "no, there is no library for GPX track processing". Lots of applications and code, but no general purpose tool. It's helpful to know that. For me the way forward is to write some PostGIS code that works with the schema created by ogr2ogr's GPX import. That schema contains both a simple LineString for the track and a table of points with timestamps for the time dimension.
    – Nelson
    Commented Apr 24, 2012 at 16:12
  • Is Delphi code an option too?
    – user5332
    Commented Apr 28, 2012 at 5:39
  • Google just announced a Tracks API I'm mentioning here for completeness. It looks useful but in a different direction than I'm looking for; more about breadcrumbs and geofences.
    – Nelson
    Commented Oct 17, 2012 at 15:02
  • 1
    @Nelson Take a look at this answer, from one of the creator of (rather excellent online ride editor) Ride With GPS: stackoverflow.com/a/13084082/401828 Commented Oct 26, 2012 at 12:36
  • @Nelson This question is still very current for me, nearly 4 years later. Have you found a good solution in the meantime?
    – amball
    Commented Aug 31, 2016 at 23:58

9 Answers 9

7
+100

Well, kinda depends on your programming-language of choice, but i've developed mineturer.org in Java (the site is essentially a site for uploading, analyzing and displaying GPX-data).

Iv'e used JAX-B (http://jaxb.java.net/) to read GPX files (based on the GPX schema) and JTS (http://www.vividsolutions.com/jts/) + own code for analyzing.

The source code for mineturer.org is available under a MIT-licence at https://bitbucket.org/atlefren/gpsorganizer/

I guess the code could give you some pointers at least?

3
  • Thanks! Your site looks great (and is pretty usable via Google Translate even if you don't read Norwegian). You're doing exactly the kind of analysis I want and it's a big help you've open sourced it. For Python I'd probably use GEOS instead of JTS; there's decent bindings.
    – Nelson
    Commented Apr 16, 2012 at 18:49
  • 2
    if you like it ... upvote it!!
    – Stev_k
    Commented Apr 17, 2012 at 14:50
  • 1
    Just a follow-up here: I've started porting this project to Python, using Shapely and GeoAlchemy (and Flask), it works but is rather slow at the moment. Code at github.com/atlefren/mineturer2 for the curious
    – atlefren
    Commented Aug 28, 2014 at 14:15
3

I wrote a math C#-lib for 2d/3d math targeting GPS handling: reading GPX & TCX, filtering & simplification of tracks, clustering tracks / segments and transforming to 2d plane.

https://www.nuget.org/packages/Math.Matthey/

https://www.nuget.org/packages/Math.Matthey.Tools.TrackReaders/

5
  • Is it possible to get some description or documentation for that Nugets? Commented Mar 29, 2019 at 9:53
  • I'll see if I can add a Readme.MD to the NuGet pkg.
    – tma
    Commented Mar 30, 2019 at 18:12
  • Thank you, the repository is not accessible. Is it possible to parse also gpx files containing <rte> and <rtept> elements, besides the <trk> elements? Commented Mar 30, 2019 at 19:24
  • 1
    At the moment only supporting trrk->trkseg->trkpt with Garmin track point extensions, but I added the rte->rtept in 2.3.0, but no validation so far.
    – tma
    Commented Mar 30, 2019 at 22:10
  • 1
    Added documentation for both packages on on nuget.org.
    – tma
    Commented Mar 31, 2019 at 19:34
2

The GPS Toolkit should help. It's an open source library and suite of applications that aims to free researchers from lower level coding.

It provides the following functionality:

  • RINEX utilities
  • Positioning
  • Residual analysis
  • Ionospheric modeling
  • Signal Tracking Simulation T
  • Basic transformations
  • Observation data collection and conversion
  • File comparison and validation.
  • Data editing
  • Autonomous and relative positioning.
1
  • Thanks for the answer! GPSTk looks fascinating but it's at a lower level than I'm looking for. It seems to be about working with raw GPS radio signals and deriving location fixes from them. I already have location fixes from my consumer GPS hardware and no access to the low level satellite data.
    – Nelson
    Commented Apr 15, 2012 at 18:52
1

There is a open source lib I just finished developing (to stable) and UI for analyzing GPX, TCX and fit files.

The lib is https://github.com/jimmykane/quantified-self-lib The UI based on Angular https://github.com/jimmykane/quantified-self

Live Demo https://www.quantified-self.io

What it can do is parse a GPX,TCX or Fit file, generate stats such as ascent, descent, distance,

0

Excellent question! I've been working quite a bit with GPX data lately and the simplest solution that I have found has been to convert your track points into a spatial db format and then create views (spatial and tabular) to summarize the data as needed. I was unable to get the results needed using OGR to import my GPX data, so I ended using a simple python script to traverse the XML tree structure of the GPX and load it into the db (SpatiaLite in my case). This definitely doesn't help you in avoiding reinventing the wheel, however I found that I was able to get the desired results of summarizing tracks by trip using existing SQL and spatial SQL functions.

1
  • 1
    The main drawback I've seen with using PostGIS LineStrings is they don't contain timestamp data. I can certainly track them myself in a separate schema, but then PostGIS isn't doing anything to help me do time-based calculations. Do you have any tricks for that?
    – Nelson
    Commented Apr 16, 2012 at 18:43
0

I am developing this small soft for my own use. It is mainly for visualisation and does not support all your needs, but maybe it may help!

1
  • Thanks! It's open source and in Java, so that's definitely a help.
    – Nelson
    Commented Apr 21, 2012 at 0:47
0

If you'd like some abstract specification for a language-neutral, API, there is GeoAPI:

"The development community in building GIS solutions is sustaining an enormous level of effort. The GeoAPI project aims to reduce duplication and increase interoperability by providing neutral, interface-only APIs derived from OGC/ISO Standards."

http://www.geoapi.org/

and more specifically the Implementation Standard (PDF)

0

Upload your GPX track to this URL

You will be provided with most of the services you requested, specifically:

  • Calculate the distance travelled on the track
  • Calculate the average speed
  • Calculate time in motion vs. time stationary (visible on the speed profile)
  • Simplify the track, eliminate stationary segments
  • Smooth out GPS sampling error
  • Converts the track KML/KMZ etc for visualization
-1

at the risk of not answering your actual question :-), let me suggest a great application you might not have heard of, that does all that you listed -

it's my one-stop-shop for viewing, editing, and transferring GPX, among other things.

And perhaps more on-topic, maybe checkout the Positioning namespace of dotSpatial (.NET): http://dotspatial.codeplex.com/wikipage?title=DotSpatial.Positioning

Regards.

1
  • Thanks! TopoFusion is a great application for Windows, but I really need a library. dotSpatial has some useful-looking code to crib. It's under Mozilla Public License.
    – Nelson
    Commented Apr 21, 2012 at 0:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.