nasauber.de

Blog

How to convert GPX to SVG

Internet forums are full with the question "How can I convert GPX to SVG?" but no really good answer is given. At least, I didn't find one program that "just" does the job. At the end of the day, we're talking about my newly released gpx2svg program and why I had to write it here. Just to have the link in the first line ;-)

What did I want to do?

I tried to convert an OpenStreetMap-extracted coastline of Iceland to an SVG file. Here is the source GPS file, shown by GpsPrune:

GPX file in GpsPrune

What do we have?

There's an online service called gpsvisualizer by which a GPX file can be converted to SVG. It actually could do that with a proper projection, but the output of my dataset was scattered in thousands of small paths, so it was completely unusable.
Then, there is one small piece of code in the OpenStreetMap SVN repository that claims to "spit out a svg file" [sic]. It's called svg.rb and resides in the directory gpx2svg. But apart from the fact it seems to be unmaintained (just a few updates back in 2007) and there's no release, it just didn't work:

This is what I got using the gpx2svg/svg.rb script from the OpenStreetMap SVN repository, viewed with Inkscape:

SVG output of svg.rb

Apparently, the script does also not use the Mercator projection. Notice the top-bottom compression.

gpx2svg

Self do, self have. Finally, here's a screenshot of the output of the gpx2svg program I wrote, also viewed with Inkscape. The whole coastline and all the islands around are closed paths that can be filled as-is:

SVG output of svg.rb

The output fitted my needs. Probably, someone else also wants to do such a conversion. If so, have a lot of fun with it :-)