Python GPX Import Coordinates

By | May 20, 2016

Gpx (GPS Exchange Format) is a common file format used to store exported GPS data. In this post I use the python module gpxpy to simply import the gpx coordinates from a gpx file.

Search for Python Geospatial Analysis on Amazon [Sponsored Link]

Python GPX Import Made Easy With gpxpy

A Python GPX import is made a lot easier with the gpxpy package, which does the hard work of parsing the GPX file is done by gpxpy:

import gpx.py
import gpx.gpx
gpx = gpxpy.parse(gpx_file)
points = []
for track in gpx.tracks:
    for segment in track.segments:        
        for point in segment.points:
            points.append([point.latitude, point.longitude])

Which gives us a list containing the points of latitude and longitude, representing the trackpoints in our route.

Visualise With Folium

We can visualise our list of coordinates with Folium – check out the code for this map here.

We can see that in this case the GPX coordinates represent movement around two areas of London.

Find more examples on the gpxpy github page