Open Street Map with Tilemill (for beginners)

I’ve recently had to develop a mapping solution that needed to use Open Street Maps data in a MapBox style map (i.e. not Google Maps). There is a tool called TileMill from MapBox that is really great and allows you to style the map exactly the way you want it.

However I found it really tricky to figure out how to get the data you need in to the map. It took me a good day to figure it, so I though a simple guide would be useful for everyone else (and me next time I need to do it).

Hopefully you’ll fine it useful too.


1.Install PostgreSQL

A PostgreSQL database is required to hold the map data. I’ve used MySQL and MSSQL before so PostgreSQL is a bit odd to me. Don’t worry though, unless you need to do anything custom then you won’t need to do much with it manually.
Download the PostgreSQL app from


2. Install osm2pgsql

The osm2pgsql extracts the data from Open Street Map (osm) files into the PostgreSQL database. Instructions to install it on various platforms can be found at The Mac OSX install is straightforward from Binary, the link is also on this page.


3. Download Open Street Map data

My advice on this is don’t download more than you need to, some of the files are huge. The full world of data is currently 23Gb. Not only does it take a while to download, it also takes even longer to process. I tried processing the planet OSM and it was still running 18 hours later. Probably better to do it one country or continent at a time.
I found two sources of data; the first from Open Street Map ( and the with more specific country breakdowns ( Download the .osm.pbf files, they work well.


4. Open psql command line

If you have installed PostgreSQL correctly, on Mac OSX at least, you should have a little elephant in your top bar (or elsewhere on other OS). From the elephant select open pqsl. This will open up a new psql terminal/command prompt where you should run the following (one line at a time);

\c osm

This creates a new extension for the postgis dta, then creates a database called osm, switches to that database using the \c and then sets the postgis schema to it.


5. Open a new terminal/command window

Now you can extract the data from the osm files into the PostgreSQL database. Run the following (one line at a time);

cd [location of your opm files]
osm2pgsql -U yourusername -H localhost -P 5432 -d osm -C 32000 xxxx.osm.pbf

Remember to change your username [mac user] and the filename.
This should start processing the data and will show you some progress, though not a % complete. Just wait now!


6. Download Open Streets Style

Download or clone the Open Streets Style project from This is a project you can open in TileMill that has pretty much all the data you’ll need loaded in and styled for you, which you can then customise using Carto.

Once downloaded move it into your Mapbox projects folder, on a Mac this is in ~/Documents/Mapbox/projects. The file sits directly in the projects folder.


You shouldn’t need to edit the file, but you will need to run the file from a terminal window.

cd ~/Documents/Mapbox/projects

7. Download Layers

Download the files and and extract them. Then copy the files out of the folders into the open-streets/layers folder in the Mapbox project.


8. Open TileMill and open the open-streets project

It may take a minute or two to open but hopefully you should see some streets for the area you wanted?

I hope you do because I can’t offer much more advise. It took me ages to get this far.

Related Items