Table Of Contents

Previous topic

Database Schema

This Page

Data Mapping

The data mapping defines which OSM feature types should be imported in which table. The mapping is described with a Python file using classes from imposm.mapping package.

See defaultmapping.py as an example.

Tables

There are three classes for the base geometries: Points, LineStrings and Polygons. All three clases take the same arguments:

name
The name of the resulting table (without any prefix).
mapping
The mapping of tags keys and tag values that should be inserted into this table.
fields
Mapping of additional tags into table columns.
field_filter
Filter table entries based on field values.

mapping

Mapping should be a dictionary where the keys are the feature keys (e.g. highway, leisure, amenity, etc.) and the values are tuples of the feature values (e.g. motorway, trunk, primary, etc.).

For a table with bus stops, tram stops and railways stations and halts the mapping should look like the following:

mapping = {
    'highway': (
        'bus_stop',
    ),
    'railway': (
        'station',
        'halt',
        'tram_stop',
    )
}

fields

Fields should be a list (or tuple) of column name and column type tuples. You can use fields to add additional columns to your tables. There are predefined classes for the most common types. These classes can do processing on the values, like converting 1, yes and true to TRUE for boolean columns.

For example:

fields = (
    ('tunnel', Bool()),
    ('bridge', Bool()),
    ('oneway', Direction()),
    ('ref', String()),
    ('z_order', WayZOrder()),
)

Classes

class imposm.mapping.Points(name, mapping, fields=None, field_filter=None)

Table class for point features.

Postgis datatype:
 POINT (for multi-polygon support)
class imposm.mapping.LineStrings(name, mapping, fields=None, field_filter=None)

Table class for line string features.

Postgis datatype:
 LINESTRING (for multi-polygon support)
class imposm.mapping.Polygons(name, mapping, fields=None, field_filter=None)

Table class for polygon features.

Postgis datatype:
 GEOMETRY (for multi-polygon support)

Example Mapping

Here is a example of a data mapping that creates a table towers. All nodes with man_made=tower or man_made=water_tower will be inserted. It will also create the column height with the values of the height tag as integers. [1]

 towers = Points(
   name = 'towers',
   mapping = {
     'man_made': (
       'tower',
       'water_tower',
     )
   }
   fields = (
     ('height', Integer()),
   )
)
[1]It will set the height to NULL for non-integer values (like values with a unit, 15 m or 80 ft). A custom column type Height() could automatically convert these values to a common unit. This is left as an exercise for the reader.

Column types

class imposm.mapping.String

Field for string values.

Postgresql datatype:
 VARCHAR(255)
class imposm.mapping.Bool(default=True)

Field for boolean values. Converts false, no, 0 to False and true, yes, 1 to True.

Postgresql datatype:
 SMALLINT
class imposm.mapping.Integer

Field type for integer values. Converts values to integers, defaults to NULL.

Postgresql datatype:
 INTEGER
class imposm.mapping.Direction

Field type for one-way directions. Converts yes, true and 1 to 1 for one ways in the direction of the way, -1 to -1 for one ways against the direction of the way and 0 for all other values.

Postgresql datatype:
 SMALLINT
class imposm.mapping.OneOfInt(values)

Field type for integer values. Converts values to integers, drops element if is not included in values.

Postgresql datatype:
 SMALLINT
class imposm.mapping.ZOrder(types)

Field type for z-ordering based on the feature type.

Parameters:types – list of mapped feature types, from highest to lowest ranking
Postgresql datatype:
 SMALLINT
class imposm.mapping.WayZOrder

Field type for z-ordered based on highway types.

Ordering based on the osm2pgsql z-ordering: From roads = 3 to motorways = 9, railway = 7 and unknown = 0. Ordering changes with tunnels by -10, bridges by +10 and layer by 10 * layer.

Postgresql datatype:
 SMALLINT