I have an existing .osm file (containing a small part of OpenStreetMap database). I am looking for way to convert it into .svg file.

Note that I am not interested in applying any styling based on data, I am interested solely in geometry of objects.

  • 1
    There's so many possibilities of how you style the OSM data that I can't see a simple solution...Post your overcomplicated solution in your question and point out how its not adequate. – Spacedman Dec 12 '18 at 21:44
  • @Spacedman I updated my question, sorry for not specifying earlier that I am interested solely in geometries. I got so focused on my usecase that I forgot that generating instruction for CNC laser is not a typical use of .svg files :( – reducing activity Dec 12 '18 at 22:53
  • Given that both .osm and .svg are XML dialects I think that means it could be doable with an XSLT - a spec (also in XML) for converting between XMLs. But its not a job I'd like to take on! – Spacedman Dec 12 '18 at 23:03

Based on https://help.openstreetmap.org/questions/27436/easiest-way-to-render-several-svg-maps-in-mapnik-style you have some choices that work for me:

It lets you download osm data for the current view, and export to SVG for Inkscape or Adobe Illustrator. It uses the OSM styles by default

It requires the data to be in a postgis database populated with osm2pgsql, and uses OSM stylesheets as well. The command line would be something like

nik2img\nik2img.py osm-de.xml out.svg --format svg --srs 900913 --bbox 6.47 51.4 6.48 51.41 --world-file wld 

Mapnik is also able to consume raw osm data and output SVG, but I have not tested it myself. At lest the demo of Mapnik 2.2.0 has SVG output on a very simple stylesheet (rendering shapefiles).

  • I will accept your answer, as while I will use osmtogeojson + mapshaper script your answer is more likely to be useful for a typical visitor. – reducing activity Dec 13 '18 at 21:25

Following method is nice for automatic scipts:

Convert .osm to GeoJSON (for example using https://github.com/tyrasd/osmtogeojson ) or to obtain it directly in GeoJSON (for example using Overpass Turbo).

Import GeoJSON file to https://mapshaper.org/ and export .svg file.

There is also CLI, see https://github.com/mbloch/mapshaper for details. For example

osmtogeojson file.osm > file.geojson
mapshaper -i file.geojson -o format=svg

will convert file.osm to file.svg

It was partially based on https://wiki.openstreetmap.org/wiki/SVG (and I added to this page parts that were missing).

  • Osm to geojson should be possible with GDAL too. Do you use the mapshaper command line? – AndreJ Dec 13 '18 at 18:55

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.