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.
There are three classes for the base geometries: Points, LineStrings and Polygons. All three clases take the same arguments:
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 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()),
)
Table class for point features.
Postgis datatype: | |
---|---|
POINT (for multi-polygon support) |
Table class for line string features.
Postgis datatype: | |
---|---|
LINESTRING (for multi-polygon support) |
Table class for polygon features.
Postgis datatype: | |
---|---|
GEOMETRY (for multi-polygon support) |
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. |
Field for string values.
Postgresql datatype: | |
---|---|
VARCHAR(255) |
Field for boolean values. Converts false, no, 0 to False and true, yes, 1 to True.
Postgresql datatype: | |
---|---|
SMALLINT |
Field type for integer values. Converts values to integers, defaults to NULL.
Postgresql datatype: | |
---|---|
INTEGER |
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 |
Field type for integer values. Converts values to integers, drops element if is not included in values.
Postgresql datatype: | |
---|---|
SMALLINT |
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 |
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 |