Here is a worked example, from start to finish, showing how to create a map from OpenStreetMap data with the following features:
- urban area shading
- terrain shading
- heights in metres
- contour lines
The map is of part of Scotland including Perthshire. For the purpose of making a simple example, the bounds of the this map are on lines of longitude and latitude, from 3 to 5 degrees west and from 56 to 57 degrees north.
This article assumes you have the appropriate version of makemap, the map creation tool, and have downloaded the coastline data and created a coastlines.makemap file to access it. If not please read How to Create CartoType maps first.
Getting the OpenStreetMap data
To get the data, go to www.openstreetmap.org, find Scotland on the map and choose 'Export', then 'Manually select a different area'. Set the bounds to -5 (west), 56 (south), -3 (east) and 57 (north), then click on 'Overpass API'. The data will arrive as a file called 'map'. Change its name to perthshire.osm and put it in your working directory.
Getting the elevation data
The easiest way to get elevation data for a relatively small area like this map, for which two one-degree tiles are needed, is to use http://rmw.recordist.com/. Fill in the minimum longitude as -5, the minimum latitude as 56, the maximum longitude as -3, and the maximum latitude as 57, choose SRTM 3 (World) from the 'Select product' dropdown menu, then click on 'Get available tiles'. You then need to click on the two links, download the zip files, and put the resulting files, N56W005.hgt and N56W004.hgt, in your working directory.
You can create contours from the elevation data using gdalbuildvrt and gdal_contour from the GDAL suite of free GIS utilities. If you're using Windows the easiest way to get gdal_contour is to install OSGeo4W.
First combine the HGT files into a virtual dataset (VRT file), to avoid artefacts where they abut:
gdalbuildvrt perthshire.vrt N56W004.hgt N56W005.hgt
Then create an ESRI shapefile containing the contours:
gdal_contour -a height -i 10 perthshire.vrt perthshire-contours.shp
The -a option tells gdal_contour to put the contour heights in an attribute called height. The -i option gives the contour interval in metres.
Now you'll need to create a file to tell makemap what to do with the contour file. Create a file called perthshire-contours.makemap, with the following text:
<?xml version="1.0" encoding="UTF-8"?>
<set name='_h' value='height+0'/>
This file has some interesting features. The contour heights are put into a string attribute called '_h'; a leading underscore in the attribute name tells makemap not to put these values into the text index. The expression 'height+0' is used to create the height string because of a bug in gdal_contour: it creates heights as string values to three decimal places; adding zero to the string converts it into a number, which is then automatically converted back to a string in standard form, with no trailing zeroes.
The makemap command line
It is best to put the makemap command line in a batch file or script so that the options can be stored for re-use and modification. On Windows, for example, put the command line into a file called make-perthshire.bat, with the following contents:
makemap /project=osgb /driveonleft=yes /urbanareas=yes /extent=-5,56,-3,57 /usgs=. /terrain=height-metres /usgs=. /input=perthshire-contours.makemap /input=coastlines.makemap perthshire.osm
This command line assumes that you have put the two HGT files in your working directory. If you have already downloaded a lot of them to a special directory, use that after /usgs= instead of the full stop indicating the working directory.
The options in the command line are:
- /project=osgb - use the Ordnance Survey of Great Britain projection
- /driveonleft=yes - the rule of the road in the UK is to drive on the left; omitting this option doesn't matter unless you need to display traffic information or other highlights on the driver's side of the road
- /urbanareas=yes - create shaded urban areas
- /extent=-5,56,-3,57 - the extent of the map in degrees, in the order west, south, east, north: that is, anticlockwise from the left
- /usgs=. - read the appropriate HGT files and create terrain shading from them
- /terrain=height-metres /usgs=. - read the HGT files again and store point heights in metres
- /input=perthshire-contours.makemap - read the contour files that were created earlier
- /input=coastlines.makemap - read the coastlines
- perthshire.osm - the main input file
Some important implicit options, which are of course unspecified, are
- /clip=yes - clip to the extent
- /lowreslayers=yes - create low-resolution layers for use at small scales, to improve performance
- /route=yes - create routing data
Now run the command, and you should get a map called perthshire.ctm1, somewhat larger than 60Mb.
Displaying the contours
If you load the map into the CartoType Maps App and use the standard style sheet, osm-style.xml, you won't see any contours. Here is a suitable contour layer. It should be inserted into the style sheet immediately after the 'outline' layer:
<line fill='#C76300FF' width='0.5pt' opacity='0.4'/>
<label priority='-10' font-size='5pt' color='#C76300FF' opacity='0.4' baseline='text-after-edge' labelFormat='_h'/>