OS Landranger style maps using Open Street Map (OSM) data for display on your Garmin


I had been tempted to buy a mapman GPS to replace my Garmin, as it offers full OS mapping of the UK...but at a price.  I had a Garmin e-trex Cx already, so when my son showed me open street map and how it could be downloaded I was interested, but it wasnt't all plain sailing which is why I am explaining what I did here, in case it is of use to you.  I am not trying to replicate the many excellent resources available, just to bring together a few things.

I ended up with a gmapsupp.img file to put on my GPS (just copy it into the GARMIN folder on e-trex or edge models) which has mapping for the UK  in OS landranger style (red for A roads, blue for motorways, standard land use) which routes me along cycepaths as well as roads (I have avoid highways selected to avoid major roads).  I used a machine running Ubuntu 10.04 to do most of the processing (because my Ubuntu laptop is much faster than my Windows desktop) and one running windows (for mapsource as it is a Windows prog).

I started my experiment with the ready built maps from VeloMap and OpenMTBmap.  I found them admirable, but I did't like the way they routed me down bridleways and footpaths, so  I wanted to customise them a bit.  This is where the complication started.

Creating custom maps for a Garmin is basically a 6 step process.

Download the OSM file (and Split into manageable chunks)
Download contour files
Make into a set of img files
Compile into a single gmapsupp file
Load into mapsource (windows)
Copy to your Garmin device
EdgeMap
Finished map on a Garmin Edge 605

Download the OSM ("planet") file

Find the file for the area you want and download it into a new directory into a new directory - I used the bzipped files from geofabrik site, .  You can also find them at
Cloud Made Downloads.  Geofabrik has a subdirectory with English counties in which is ideal for experimenting - in that case you don't need to use splitter.  Then right click the bzipped file and extract it into the same directory (on my machine, unzipping the UK took a good 15 minutes).

To split larger files into manageable chumks I used mkgmap splitter . I downloaded splitter and unzipped it into the same directory as my mapping stuff (I used a machine running Ubuntu 10.04, but it is a java prog, so you should be able to use a windows machine just the same.

I then open a terminal (CTRL+ALT+T) cd to the directory with your downloaded osm file and type in (or copy/paste):

java -Xmx2048m -jar splitter.jar --max-nodes=300000 --output=xml  united_kingdom.osm

This takes a while (20 minutes for the UK on my machine), but creates a set of tiles with names like 6324001.osm.gz

I found the OSM on Garmin wiki  useful in working this out.  I also took the hint from the splitter web site that you might need to increase the -Xmx parameter if you get java out of memory messages.  I started at 1024 (copying from what I found on the web, but after about 15 mins procesing, this gave:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

The answer was to up the memory allocated to java to 2048 (I think you can make it what you like, provided you have that much physical memory).
In MapSource
Finished map viewed in mapsource

Download contour files

The contour files get overlayed onto your map (at least that's how I understand it), they are relatively small (compared with the OSM "planet" files).  I got them from openvelomap.  Just unzip into your maps folder to get a (small) set of img files starting with the number 7 (I had four files covering the UK).  
GoogleMaps
The same area in Google maps
OSM
...this time the on-line Open Street Map

Make into a set of img files and applying styles.

The files created int step 2 contain the map data, but they need to be processed into garmin format for display. In this  I used mkgmap for this. It is a java program.  For simplicity I just downloaded it and extracted it into my mapping directory.  I wanted by maps to look like Ordnance Survey maps, so I downloaded the ordnance survey style from the excellent http://pinns.co.uk/osm/ web site. The OS50 style is a folder of files that needs to go in the directory with your osm file. You might as well download the TYP files now too - they are for loading your maps into mapsource and onto your Garmin device.

To create a set of img files that correspond to your map tiles created with splitter use:

java -jar mkgmap.jar --remove-short-arcs --style-file=os50 --route --net  -c template.args

Note 1: I originally had --no-sorted-roads in the above line, but I removed it as it seems to be no longer supported (I'm not an expert, I don't know what it does!).

Note 2: template.args is a file created by splitter that gives a list of the osm files in the right form for processing by mkgmap - if you are only processing one map tile you can replace this with the name of the osm file - when testing I just did Oxfordshire and replaced "-c template,args" with "oxfordshire.osm" which I downloaded from geofabrik).

Note 3:  this can be a long process...it takes about half an hour on my aged laptop.  You don't get much feedback from mkgmap, but if you leave a directory listing in date order (newest first) visible then you can see new files being added as mkgmap does its stuff.

A digression on styles

I wanted the OS50 look, but I also wanted to be routed down cycle paths as well as roads, but not down footpaths and bridleways.  I had looked at velomap and openmtbmap, and was amazed by the level of detail for the UK.  I was intrigued by the idea of cycle-specific routing, but found myself routed down bridleways and tracks.  Maybe more fiddling with the settings on my GPS would have sorted this, but I think I tried everything before moving on.   The velomap lines style is massive, being used to redefine route styles to match a cycle perspective, and I soon gave up trying to edit it to remove routing from tracks and bridleways.  It turns out that the lines file in the style direcotry does all the work on routing.

The OS50  default lines file was much shorter, but still by default routed me down bridleways and footpaths.  It has lots of lines like:

highway=bridleway    [0x11 road_class=0 road_speed=1 resolution 21]

changing this to remove the routing means removing the road_class and road_speed thus:

highway=bridleway    [0x11 resolution 21]

Once this is done the line on the map is no longer treated as a followable route.  A good explanation of this is given here.

This is where I had my biggest problem.  When I open the lines file in gedit it has lots of line feeds, when I remove them and complete the process below I don't get the OS style applied at all when I compile the maps.  Much frustration and trial and error later I find that any editing in gedit messes it up.  So I resort to vi (having dredged from memory the appropriate commands a=amend (aka edit), :wq (write out and quit).  I now have a clue about the issue as there are lots of ^Ms at the end of lines and the bottom of the file - I know from days gone by that this is probably to do with swapping files between dos/windows and unix based OSes.  Again after some trial and error I find that my efforts to add taxi=no to routes I don't want to road bike down (so that I can describe myself as a taxi on my GPS when necessary) fail as the style is then not applied, BUT I can delete stuff and it still works. So I just deleted out the routing for footpaths, bridleways etc.

(For those not in the know about vi, in Ubuntu open a terminal, cd to where your file is, type vi filename to get started.

Here is my cusomised lines file if you want to use it - simply copy it to the os50 style in place of the original lines.

Compile into a single gmapsupp file on Ubuntu

According to all my research this shoudl have done the trick, creating a single gmapsupp.ing file ready for transfer to your Garmin applying the os50g type file.  In fact, while the gmapsupp file was created, the style was definitely not applied.

java -ea -Xmx1500m -jar mkgmap.jar --gmapsupp --remove-short-arcs --route --net --style-file=os50 -c template.args os50g.TYP

I only managed to make it work by creating the gmapsupp.img on a Windows PC as described below.

View in mapsource/compile gmapsupp on a windows PC

I had previously downloaded velomap onto my PC (it isn't 100% obvious, but look for the "Europe maps downloads link", then go for your country.  It gives a couple of vey useful batch files, one to install the .img tile files into mapsource, the other to create a gmapsupp.img file to transfer to your garmin.  These invoke cgpsmapper and gmt.exe.  Gmt.exe is part of the velomap download, but you need to install cgpsmapper.

I created a copy of the velomap folder.  Deleted the IMG files that came with it.  I copied across the .img files created previously and the TYP files for the OS50 style.  I also put the contour files in this folder.  I then amended the batch files to use these TYP files rather than velomap's own by doing a search and replace (replacing velo*.TYP with os50g.TYP and trdn*.TYP with os50.TYP - to save you the bother, here are my amended files:

create_mapsource_os50_installationfiles.bat
create_gmapsupp_os50.bat

All I have done is adjusted the type file references,  The mapsource batch file creates an install (and uninstall) batch file which lets you install your maps in mapsource - you need to put in a unique code - I used the first 4 letters from the img files.

The gmapsupp batch file creates a gmapsupp file which you just need to transfer to your garmin and now, hey presto, OS landranger maps on my etrex legend.
In MapSource


Copy to your device

I had an Etrex legend Cx.  It had a removeable micro sd card, so I just removed it and copied the gmapsupp.ing file to the GARMIN folder. I now have an Edge 605, for which I copy direct via usb.

Download the map

If you just want to get hold of a UK map without doing it yourself here it is (as February 2012), I have no intention of posting regular updates: gmapsupp.img.

I also have a map of the Loire, Brittany, besse-Normandy region of France available for download.