Creating a Garmin map using "mkgmap" - a very simple example

Posted by SomeoneElse on 5/14/2016

On many occasions in the past I’ve said “it’s really easy to create your own Garmin maps” but I don’t think I’ve ever documented the procedure. This is an attempt to do that.

Assumptions:

You’ve got some sort of Garmin device with an SD card in it with some maps that you’ve downloaded from somewhere on it.

You want to replace those with a map you’ve created yourself.

You’ve got a PC with “enough” memory in it. The one I used for the examples below had 4Gb; it’s possible that less may be needed for a small file such as the one used in the examples below.

All the path examples below for for Windows (actually tested on Windows 7), but it should be relatively straightforward to adapt them to work on other operating systems.

What you need to do

The easiest way to create Garmin maps from OSM data is to use “mkgmap”. That’s available from:

http://www.mkgmap.org.uk/

The download page for the latest mkgmap is http://www.mkgmap.org.uk/download/mkgmap.html and the current version is “3676”.

Unzip the zip file and move the folders intact to a known location. In my case I moved it so that “mkgmap.jar” file was in: C:\Utils\mkgmap-r3676

I didn’t use a path with a space in it or a path that Windows recognises as “special” to avoid any possible confusion later.

“Splitter” is a separate program used to split a large OSM data file into portions small enough for mkgmap to work with (the resultant Garmin map can still route between portions).

The latest Splitter is here: http://www.mkgmap.org.uk/download/splitter.html and the current version is “437”.

Unzip the zip file and move the folders intact to a known location. In my case I moved it so that splitter.jar was in: C:\Utils\splitter-r437

Next, we need to download an OSM extract to use to create maps from. As an example I’ll use Romania, and extract for which can be downloaded from here:

http://download.geofabrik.de/europe/romania.html

That page currently says:

1 romania-latest.osm.pbf, suitable for Osmium, Osmosis, imposm, osm2pgsql, mkgmap, and others. This file was last modified 7 hours ago and contains all OSM data up to 2016-05-13T19:45:03Z. File size: 146 MB; MD5 sum: b0554ae9632cc6c2be1c1e3525b5dcb5.

After downloading, check that the file is intact:

md5sum romania-latest.osm.pbf b0554ae9632cc6c2be1c1e3525b5dcb5 *romania-latest.osm.pbf

(see links from https://en.wikipedia.org/wiki/Md5sum for where to get an “md5sum” program from if you don’t already have one)

That matches so we can continue.

Create a directory to work in - in my case I created “D:\doc\gps\romania” and copied romania-latest.osm.pbf to it.

From a command prompt (on Windows), change the current directory to be where the downloaded .pbf file is.

1 2 d: cd \doc\gps\romania

See what version of “java” you have installed. Type “java -version” at the command prompt to find out. In my case that says:

java version “1.8.0_91” Java(TM) SE Runtime Environment (build 1.8.0_91-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

so Java is already installed. If you don’t already have Java installed download and install from somewhere like: http://java.com/en/download/windows_xpi.jsp

Next, run splitter. The “-Xmx1200m” tells it how much memory to allocate; the “–max-nodes” how big to make each split piece. The examples for the parameters given here should “just work”:

1 java -Xmx1200m -jar c:\utils\splitter-r437\splitter.jar romania-latest.osm.pbf --max-nodes=800000 --output=xml

That should create lots of “.osm.gz” files. Then run mkgmap. Here “–style” determines the style of map to create - “default” is actually a folder containing several files that make up that style. Unsurprisingly the style called “default” is the default mkgmap style - not particularly optimised for foot, bicycle or car use.

1 java -Xmx1200M -jar C:\Utils\mkgmap-r3676\mkgmap.jar --style-file=C:\Utils\mkgmap-r3676\examples\styles\default --route --gmapsupp *.osm.gz

When that finishes it should say something like “Total time taken: 621133ms” (i.e. about 10 minutes on a fairly slow PC for a country that is relatively small in OSM terms).

That creates:

1 2 3 4 d:\doc\gps\romania: -rw-rw-rw- 1 A.Townsend None 123359232 05-14 13:31 gmapsupp.img -rw-rw-rw- 1 A.Townsend None 4270 05-14 13:31 osmmap.tdb -rw-rw-rw- 1 A.Townsend None 73728 05-14 13:31 osmmap.img

Create a subdirectory and move those files into there for safekeeping:

1 2 3 4 d:\doc\gps\romania\default: -rw-rw-rw- 1 A.Townsend None 123359232 05-14 13:31 gmapsupp.img -rw-rw-rw- 1 A.Townsend None 73728 05-14 13:31 osmmap.img -rw-rw-rw- 1 A.Townsend None 4270 05-14 13:31 osmmap.tdb

Copy those files to the GPS. The method to do this varies by device. I’d expect that people reading this will already do this with files they’ve downloaded from elsewhere; if not there are lots of examples on places such as http://help.openstreetmap.org.

When it’s copied across, turn on the GPS and check that the new map is visible.

Next, how to change the style slightly?

In C:\Utils\mkgmap-r3676\examples\styles, take a copy of the “default” folder and call it something like “mystyle”. We’ll leave “default” as it was and make a simple change to “mystyle”. As a test we’re going to make tracks appear like unclassified roads.

Edit c:\Utils\mkgmap-r3676\examples\styles\mystyle\lines in a text editor. The “lines” file is the one that deals with linear items - things such as roads.

Here’s the line in that file that deals with unclassified roads:

1 highway=unclassified [0x06 road_class=0 road_speed=3 resolution 21]

It’s pretty straightforward what is happening - the OSM feature at the left (“highway=unclassified”) is to be transformed into the Garmin feature at the right (“0x06”).

Here’s the line that deals with tracks:

1 highway=track [0x0a road_class=0 road_speed=1 resolution 22]

change the latter line to:

1 highway=track [0x06 road_class=0 road_speed=3 resolution 21]

(i.e. so that “highway=track” is treated as if it was “highway=unclassified”)

Rerun mkgmap with the new style:

1 java -Xmx1200M -jar C:\Utils\mkgmap-r3676\mkgmap.jar --style-file=C:\Utils\mkgmap-r3676\examples\styles\mystyle --route --gmapsupp *.osm.gz

Create somewhere safe to store the new files, and put them there:

1 2 3 4 d:\doc\gps\romania\mystyle: -rw-rw-rw- 1 A.Townsend None 123338752 05-14 14:23 gmapsupp.img -rw-rw-rw- 1 A.Townsend None 73728 05-14 14:23 osmmap.img -rw-rw-rw- 1 A.Townsend None 4270 05-14 14:23 osmmap.tdb

Copy to the GPS again, and check that tracks do indeed appear as roads.

… and that’s it.

Obviously there are many more changes that can be made. There’s quite a lot of information on the OSM wiki at places such as http://wiki.openstreetmap.org/wiki/Mkgmap/help .

The resulting example “default” files can be found at this link:

https://drive.google.com/open?id=0BwHcCIjlU11ucl9HYzdzdmc1OGs

The resulting example “mystyle” files can be found at this link:

https://drive.google.com/open?id=0BwHcCIjlU11ueWlTX1J5Q3paUnM