I have written a parser in Python that extracts the coordinates out of a GPX file and I would like to view those points on a map. I have done a little research and it seems like either Fiona or Shapely is capable of doing this, but all of the examples I find handle shape files.

My coordinates are stored as tuples in a list. I was wondering if there was an easy way to use either of these packages to plot my coordinates.


Given you're already familiar with Python I'd recommend taking a look at the cartopy library for plotting spatial data with matplotlib. It's a much nicer replacement to matplotlib-basemap.

The basic idea of cartopy is that you can apply a projection to both your matplotlib frame as well as everything you're plotting to the frame. It also includes a lot of helper methods for adding base data, displaying shapely geometries, etc (even in v0.12 released earlier this month, reading in mapbox tiles as a basemap!).

In your case you've got a set of points that are (presumably) in WGS84 longitude, latitude pairs. You could build a shapely geometry and plot that, but the easiest method would be to use the standard matplotlib scatter to see the data. In which case I'm going to assume that your points rather than being a list of tuples, are in a 2d numpy array called points. For my example I grabbed a trail from the OpenStreetMap gpx trail store.

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

First you should define some projections. See the cartopy projection list for a whole stack of different options.

data_crs = ccrs.PlateCarree()
map_crs = ccrs.UTM(zone=32)

Then build the axis and plot some points with a bit of basemap information.

ax = plt.axes(projection=map_crs)

ax.add_feature(cartopy.feature.OCEAN, zorder=0)
ax.add_feature(cartopy.feature.LAND, zorder=0, edgecolor='black')

Finally add your data (and apply the transform)

ax.scatter(points[:, 0], points[:, 1], transform=data_crs)


Plot of gpx trail

  • I thank you for your answer. I have no doubt it works, but I have had such a hard time downloading and installing packages. I follow instructions explicitly and yet I still get a failure to recognize a package or module, even though the installation said it was successful. – user50802 Apr 21 '15 at 7:58
  • 2
    @user50802 What is your setup like currently? If you're on windows for example Christoph Gohlke has put up a huge number of Python Pacakges for Windows which might help you out. – om_henners Apr 21 '15 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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