DIY Guidebook – Parsing OSM data

I used the Geofabrik package of OpenStreetMap data for Berlin as a basis for several layers in my map. Once I unpackaged the file to a simple .osm, it’s over 700 MB. I did try to open this in QGIS, but… that didn’t work so well.

Fortunately, you can filter the file before bringing it into your mapping software using osmfilter. The OSM wiki and/or the query feature on will help you figure out how to filter for what you’re interested in.

For example: I wanted to grab all the museums that OpenStreetMap knows about. I looked on the OSM wiki for museums. This page shows that museums will be labelled with the tag “tourism=museum”. Then I ran this command:

./osmfilter berlin-latest.osm --keep="tourism=museum" -o=museums.osm

This runs the osmfilter script (located in the folder in which I’m executing the command) on the berlin-latest.osm. It exports a file museums.osm that includes only those objects with the tag “tourism=museum”.

I separated the transit information I wanted to import into stations and lines. It’s also divided by operator and type (S-Bahn, U-Bahn, tram, etc). To get the U-Bahn stations, for example, I ran

./osmfilter berlin-latest.osm --keep"railway=station AND station=subway" -o=ubahnstations.osm

For the tram lines, I ran commands like this:

./osmfilter berlin-latest.osm --keep"route=tram AND operator=BVG" -o=trams/TramWays.osm

./osmfilter trams/TramWays.osm --keep"ref=M1" -o=trams/M1.osm

I could definitely also have left the tram routes all as one file and done filtering in QGIS to change the colour, but this way seemed easier.

Here’s how it looks after I import some layers this way:

QGIS with imported layers