Enrich OSM maps with additional information

About Rules and Commands

Two terms always occur in Maperitive: rules and commands. Both affect the way maps are displayed but at different levels. Commands refer to the program functions and call them, whereas rules control the appearance of objects on the map, by controlling the interpretation of the data used [5].

Rules in particular define which objects from the data upload are displayed. The rule set is usually stored in a specially formatted file, with the .mrules ("Maperitive rules") extension. To tell the program to use these rules for rendering, you can enable them using the use-ruleset and apply-ruleset commands in the Commander. This process takes a while – Running a task in the preview shows you the current status. You can see the effect of changed rules using reload-ruleset after you have rewritten the rules file.

A rule file consists of several parts. As a special feature, these files use indentation to distinguish different structures. The software works with three main kinds of objects:

  • Point features (represented by OSM nodes) for items such as mountain peaks, viewpoints, but also city centers.
  • Line features for objects such as OSM ways, that is, roads of all types, routes, rivers, and
  • Area features, areas generated by closed OSM ways (buildings, squares, forests, or lakes).

Listing 1 shows the principle structure of a rule file on the basis of extracts from various MRULES files. You do not indent the features keyword, but you do indent the following keywords: points, areas, lines, and the other specific targets. Interestingly, several points areas can occur in a file, which improves the readability, as does inserting comments ("routes").

Listing 1

Structure of a Rule File


Because of the variety of tags [6], it is not easy to find the correct tags for specific objects in an OSM database. One typical example is forests, sometimes designated as natural=wood, and sometimes also as landuse=forest. It's even harder with expanses of water: These can be found under natural=water, waterway=riverbank, landuse=reservoir, landuse=basin, waterway=dock, and many other tags. To find the typical tags for structures that are definitely in the maps, you need to check out sites such as the OSM overview [7] and a list of special objects [8].

Many objects appear as icons or text, as the following examples show. Because Maperitive evaluates the OSM database, the program can basically view all the objects that exist in the database. A multi-stage process controls the rendering of the objects. This is demonstrated by a typical problem when creating rules: the absence of certain entries in the maps.

If you want to add shelters of various types to a map, you need a target definition for these objects. They are maintained in the OSM database as amenity=shelter. You can copy the required definitions, for example, from Hiking.mrules (Listing 2). However, just adding this definition to your MRULES file in not enough; you also need to declare a corresponding feature:

Listing 2



shelter : amenity=shelter

If this entry is missing under features in the points area, or if it is not correctly indented, then the shelters will not appear in the map. The indentations are a frequent source of error in these definitions. Make sure that the draw statement appears at the same level as define and indent the additional information icon-width.

Unfortunately, the error messages give hardly any information about why something is not correctly displayed. The same applies for commented-out entries; these also must be at the appropriate level, if you want to avoid the Maperitive parser tripping over them.

There is in fact yet another level for rules, which you also need to note: You see precisely the subset of a target that you output in the target definition with draw. If you want to include the available supermarkets, this is done with a target like the one in Listing 3.

Listing 3

Define a Target


Supermarkets usually have a name, such as the name of the chain to which they belong, and it would be handy to see this in addition to the identical symbol for all supermarkets. You can achieve this through an entry in the form draw : text (same indentation depth as for draw : icon).

Maperitive so far only supports PNG graphics as icons. You must also make sure that the dimensions of the icons match the desired destination, for example, that arrows actually point to the right spot. If the application cannot display an icon, it is simply dropped without comment from the output.

Another special feature: The rules usually use fixed sizes regardless of the zoom level of the map to provide identical output of draw structures. When displaying birds eye views of the map, the software displays the icons and text at the same size as in views from a shorter distance.

There is only one way to modify the display as a function of the zoom level: To find the places where there is, for example, a supermarket at greater distances, you can enable the appropriate icons at low zoom levels. Do this with min-zoom in the target definition: 5.

To prevent the icon from looking too large and covering other important information, you need to modify the icon-width. Instead of icon-width: 24, reduce the icon width to, say, icon-width: 5:8;10:12;13:24. The program interprets this as: Up to zoom level 5, use the 8pt icons; up to level 10, use the 12pt icons; and up to level 13, use the 24pt icons.

Exporting Maps

The maps produced with Maperitive so far exist only as patterns in the memory space reserved by the program. To use the maps elsewhere, you need to export them. There are two possibilities: Exporting as a bitmap (export bitmap) stores the current preview in the pixel format (by default as a PNG). This results in lower quality, but it is perfectly suitable except for tasks where you need map images – e.g., for the web maps of navigation systems.

You can also export as an SVG graphic (export-svg), which creates a scalable graphic whose components exist as editable objects. This variant type is useful for high-resolution maps and downstream processing. Maperitive provides numerous arguments for the SVG export (Table 2).

Table 2

SVG Export






Define output file, default Maperitive/output/output.svg.


<zoom level>

Define section for output. This parameter conflicts with map-scale.



Define scale of output map. map-scale=10000 generates a map with a scale of 1: 10,000.


inkscape or illustrator

Compatibility of the SVG data, default inkscape.



Create compressed SVG file (svgz).



Scaling used, default 1.


true or false

Copy images to the output file (default). copy-images=false includes references only.


true or false

Special specification for Adobe Illustrator.


true or false

Convert text to path to achieve optimum quality. Usually not necessary.

The order of the arguments is arbitrary, as long as you specify the arguments with values. In the case of arguments that normally expected values after the equals sign, you can specify the arguments without these if they come first. You would thus create a map with a scale of 1:10000 with the following command:

export-svg compressed compatibility=inkscape map-scale=10000 copy-images=false

Because SVG graphics consist of vectors, you can reproduce them at any resolution. You can thus create an overview map, as well as maps of sections in any quality without special adaptations. You can set the exported section of the loaded map in advance. To do so, define the desired area independently of the OSM data scope using Maps | Set Print Bounds.

The ability to export the current map as an OSM file in XML format is still relatively new. It offers the possibility to create multiple variants of the current map from the same data and to edit the variants again.

Contour Lines

Sometimes the OSM data is not sufficient to generate all the information you need. The routes and POIs in the maps are great, but to gain a realistic impression of a location, you definitely need to add contour lines at least. To do this, Maperitive uses a Digital Elevation Model (DEM) server from which the application queries the altitude data. When using the default DEM server SRTM3, you should mention the data source on any maps you create, however.

Maperitive's algorithm for calculating the contour lines does not work perfectly (Figure 3). Contour lines are equipotential lines that are always shown as closed. In Maperitive, the generate-contours command generates contour lines. The <limits>, <interval>, <maximum>, and <minimum> arguments let you adjust the contour lines to the requirements of the terrain.

Figure 3: A small error in the contour lines has little effect on the overall result.

Using <borders> lets you limit the edited area with a bounding box (the default is the preview pane). <Interval> defines the density of the contour lines, specified in meters (default: 10). <Maximum> defines the highest contour, and Minimum the lowest.

Contour labeling is done automatically, but the algorithm can quickly become overwhelmed in case of deviating values for the interval. There is room for improvement here. Contour lines appear in the SVG export as various levels with the contour major prefix in the Line artwork group.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Digitizing Analog Music Media

    Armed with the Audacity sound editor, you can convert the analog content of LPs, tapes, and cassettes to the digital world.

  • FileZilla

    High-performance GUI-based ftp clients for Linux are hard to find. The graphical FileZilla ftp client closes the gap.

  • KTools: Treeline

    Mindmaps are useful for organizing ideas and data. Treeline is a promising mindmap tool for KDE.

  • Labyrinth

    The Labyrinth mind mapper lets you collect and organize your thoughts and ideas without major detours.

  • Command Line: Using udev

    Learn how to create your own udev rules and deploy command-line tools to monitor and control udev events to clear your way through the Linux device jungle.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More