OSM Map on Garmin/Contours using phygtmap

From OpenStreetMap Wiki
Jump to navigation Jump to search

OSM Map On Garmin


There are a couple of methods of making contours from SRTM3 data for a Garmin device.

OSM Map On Garmin/Topographic maps describes how to do it using the srtm2osm software.

This page describes how to do it using the phyghtmap software.

Setting up

Software to install

You will need the following software (see links on these pages for download and installation information):


To follow this tutorial, make a folder/directory on your computer somewhere for contour mapping. Inside that folder, make the following folders/directories:

For the raw STRM3 data downloads, and calculated contour PBF files.
For the IMG (Garmin-format) intermediate map files and the final map output.
For the "style" file used by mkgmap.
For miscellaneous data

You can name these whatever you want, of course, but if you do that you will need to adapt the instructions below.

File downloads

You will need to download a "sea" file, which contains pre-compiled information on the boundaries of oceans. You can get this from the mkgmap downloads page. It should be a file called something like "sea_20140511.zip"; put it into your data folder/directory.

Map region polygon file

phyghtmap needs to know the region you are making a map for. There are a couple of ways to specify this -- see phyghtmap documentation for details.

In this tutorial, I am using a polygon file. Many of the OSM Planet download sites (such as geofabrik) have polygon files available for continents, regions of continents, countries, and states, and the polygon file wiki page has some other sources listed. You can download your desired region's file (it should end in .poly) and save it in your data folder/directory.

Alternatively, You can create one yourself from latitude and longitude coordinates:

  1. http://openstreetmap.org will show you the latitude/longitude of the center of the map (or whatever you searched for) in the URL, or you can figure it out from your GPS device.
  2. Once you have the latitude/longitude of the corners of your map boundary, create a file in your data folder/directory called "mymap.poly" that will look something like this, using scientific notation (and note that the longitude comes first!):
  -1.295E+02 5.1E+01
  -1.04E+02  5.1E+01
  -1.04E+02  4.0E+01
  -1.295E+02 4.0E+01

Style files for mkgmap

mkgmap needs ["style" and "type" files] in order to take PBF data and create a Garmin IMG map. These are several plain text files, most of which go into your style-contours directory/folder.

  • A plain text file called version. This just needs to have the number 1 in it.
  • A plain text file called options. This gives mkgmap the options to create contours. Mine contains these options -- the really key ones are the draw priority and "transparent" (which makes the contour map overlay other maps), and levels, which defines the zoom levels. Note that this "draw priority" assumes that the regular map you are trying to overlay this on has a lower number priority -- I made my other map with a draw priority of 25 (which is the default), and they work fine together. Here are my options:
levels = 0:24, 1:23, 2:22, 3:20, 4:18
  • A plain text file called lines. This gives mkgmap the instructions for how to take the contour lines and render them. Mine contains these instructions, which make the "minor" contour lines appear up to map level 0, the "medium" contour lines appear up to map level 1, and the "major" contour lines appear up to map level 3 (you may need to adjust these settings if your contours become a jumbled mess when you zoom out, or if they disappear too soon):
contour=elevation & contour_ext=elevation_minor { name '${ele|conv:m=>ft}'; } [0x20 level 0]
contour=elevation & contour_ext=elevation_medium { name '${ele|conv:m=>ft}'; } [0x21 level 1]
contour=elevation & contour_ext=elevation_major { name '${ele|conv:m=>ft}'; } [0x22 level 3]
  • A plain text "type" file (which works in conjunction with the styles). This should go into your data folder and be named "contours.txt". This gives instructions for colors and line widths, which may or may not be obeyed by your device. Here is what mine contains:
; contours.typ
Xpm="0 0 2 0"
"a c #778899"
"b c #223322"
Xpm="0 0 2 0"
"a c #778899"
"b c #223322"
Xpm="0 0 2 0"
"a c #778899"
"b c #223322"

Creating the contour map

There are two steps in making the contour map.

First, run this from the contours folder/directory at the command line (you may need to change the name of the polgon file):

phyghtmap \
 --step=20 \
 --line-cat=400,100 \
 --polygon=../data/mymap.poly \
 --pbf \

This takes quite a while. It will download data from SRTM3 create minor contour lines at 20 meter intervals, medium at 100 meters, and major at 400 meters. You can adjust these values if you want. If you adjust the values or polygon and want to run it again, delete all of the *.pbf files it created in the contours folder/directory, but keep the "hgt" folder/directory, which contains the raw downloaded SRTM3 files so it will not have to download them again.

Once that is done, run this from the contours-out folder/directory at the command line. You may need to adjust the location of the "mkgmap.jar" file in the first line, and the "sea" zip file farther down. You can also adjust the "max-jobs" setting (if you have more/fewer processors on your computer, you might want it to use more/fewer of them). You might also want to change the "area name". Anyway, here is the command:

java -Xmx6000m  -jar ../mkgmap-r3288/mkgmap.jar \
 --max-jobs=2 \
 --keep-going \
 --gmapsupp \
 --mapname=20130001 \
 --description=Contours \
 --area-name=USWest \
 --precomp-sea=../data/sea_20140511.zip \
 --read-config=../style_contours/options \
 --style-file=../style_contours \
  ../data/contours.txt ../contours/*.pbf

This will result in a gmapsupp.img file. The OSM Map On Garmin page describes how to install this on your Garmin device. Note that if you have an older device that only supports one map file, you will probably need to use mkgmap to combine this map with another map file, so that you can see both together. However, if your device supports multiple map files, that is better, because then it will be separate and you can turn it off/on as desired.