Step 1 Getting the data.

Unfortunately the elevation data is not part of the Open Street Maps data. Open Streets is all about streets and towns and not about physical geography. It is a shame but not a difficult problem to deal with.

Fortunately those very nice people in NASA spent a shuttle mission (the shuttle radar topography mission) zipping around the earth documenting the elevations of the various land masses. This information is freely available in the form of osm data (

As you can see there is alot of data. The data is stored in squares of 1 degree of latitude and 1 degree of longitude. For Luxembourg we need 4 squares. So download the following 4 files:

Step 2 Convert the data format.

The bad news is that the data is in an old osm data format and needs to be converted first. The current format is version 0.6 and the contour data is version 0.5. Download version 0.35 of osmosis from this site (

Unzip osmosis into a directory, unzip the contour files into the osmosis directory . Open a dos box (cmd window) change directory to the bin sub directory and execute the following command:

binosmosis.bat --read-xml-0.5 enableDateParsing=no file="Lat50Lon5Lat51Lon6.osm" --migrate --write-xml file="Lat50Lon5Lat51Lon6_0.6.osm"

execute this for each file, changing the input and output file names in bold for each one. This will create new 0.6 versions of the contour files.

The output per file should be something like this:

D:developmentprojectsMappingTutorialsosmosis-0.35>binosmosis.bat --read-xml-0.5 enableDateParsing=no file="Lat50Lon5Lat51Lon
6.osm" --migrate --write-xml file="Lat50Lon5Lat51Lon6.0.6.osm"
Sep 15, 2013 12:49:02 PM org.openstreetmap.osmosis.core.Osmosis run
INFO: Osmosis Version 0.35
Sep 15, 2013 12:49:03 PM org.openstreetmap.osmosis.core.Osmosis run
INFO: Preparing pipeline.
Sep 15, 2013 12:49:03 PM org.openstreetmap.osmosis.core.Osmosis run
INFO: Launching pipeline execution.
Sep 15, 2013 12:49:03 PM org.openstreetmap.osmosis.core.Osmosis run
INFO: Pipeline executing, waiting for completion.
Sep 15, 2013 12:49:08 PM org.openstreetmap.osmosis.core.Osmosis run
INFO: Pipeline complete.
Sep 15, 2013 12:49:08 PM org.openstreetmap.osmosis.core.Osmosis run
INFO: Total execution time: 5520 milliseconds.

Copy the 4 new files into the data sub-directory of the mapping project and we are almost there.

Step 3  Modify our application.

In order to display the application wee need to:

  1. Update the MapCanvas class to load the new files.
  2. Update the Features enum class to recognise the noew features.
  3. Update the renderer class to draw the new features.

To load the files we add the following in the initialise method of the MapCanvas class:

processFile(new File("data/srtm/Lat49Lon5Lat50Lon6_0.6.osm"));
processFile(new File("data/srtm/Lat49Lon6Lat50Lon7_0.6.osm"));
processFile(new File("data/srtm/Lat50Lon5Lat51Lon6_0.6.osm"));
processFile(new File("data/srtm/Lat50Lon6Lat51Lon7_0.6.osm"));

We add the following to the Feature class:


Update the get main type method:

if (contains(way.getTags(), "contour")) {
   return getFeature(contour, getTag(tags, "contour").getValue());

Add the following to the isLine() method:

        case contour:
        case elevation:

And add the following to the MapRenderer class in the processLines method:

            case elevation:
                fillColor =;
                drawLine(layer, map, way.getWayNodes(), edgeColor, fillColor, false);

All three classes can be downloaded here:03-01

Running the map viewer should now give output like this:


You will notice that the contours have been clipped so that they do not go outside of the bounding rectangle for Luxembourg. This is done with the following code in the MapCanvas class:

                    processFile(new File("data/luxembourg-latest.osm.pbf"));
                    Rectangle2D clipBounds = renderer.getBounds();
                    clip.append(clipBounds, false);

What happens is that the luxembourg file is loaded and the bounds of the country calculated. (min anx max x a y values).

The bounds are then set into the clip layer and the layer added to the main layer of the canvas. The clip layer is a PClip object which will ensure that lines outside the clipping region will not be displayed.


Right so now we have the Luxembourg map being displayed with the contours. What is next? In the next tutorial I will try to be a bit more clever with the parameterisation of the different features. I now need to work out a better way of configuring the rendering. hard coding is not really very clever !!