Importing OpenStreetMap

We assume you have downloaded the area of your interest as a plain OpenStreetMap XML file (*.osm). Other formats are currently not supported.

In a first step, you have to write this data into a database. This is done using the script “osm2db.py”. Then, you probably want to build a road network from this data. This is done using the script “osmdb_buildWays.py”. You may as well extract origins and destinations from your OSM database using the script “osmdb_buildStructures.py”.

Importing OpenStreetMap into the database

The purpose of the osm2db.py tool is to store the contents of a given OSM XML file into a PostGIS-enabled PostgreSQL database.

The osm2db.py tool gets two parameters on the command line:

  • The definition of the database that shall be used to store the data and the access information;
  • The OSM XML file to get the data from.

Consequently, the call is:

python osm2db.py <HOST>,<DB>,<SCHEMA>.<PREFIX>,<USER>,<PASSWD> <FILE>

Where:

  • <HOST>: the name of your database server
  • <DB>: the name of your database
  • <SCHEMA>: the database schema to store the database tables at
  • <PREFIX>: a prefix for the database tables
  • <USER>: the name of the user who has access (can generate tables and write into them) the database
  • <PASSWD>: the password of the user
  • <FILE>: the name of the OSM XML file that shall be imported.

The tool reads the OSM nodes, ways, and relations and stores them into generated database tables. The generated database tables are:

  • <PREFIX>_member: an OSM relation member (rid — relation id, elemid — the element id, type — the element's type as text, role — the element's role as text, idx — the element's index)
  • <PREFIX>_node: an OSM node (id, pos — the position in WGS84)
  • <PREFIX>_ntag: a node attribute (id, k — key as text, v — value as text)
  • <PREFIX>_rel: an OSM relation (id)
  • <PREFIX>_rtag: a relation attribute (id, k — key as text, v — value as text)
  • <PREFIX>_way: an OSM way (id, refs — list of geometry node ids)
  • <PREFIX>_wtag: a way attribute (id, k — key as text, v — value as text)

Building the road network from OpenStreetMap data

After inserting the data into the database using osm2db.py, you may extract/build the transport network using this data. This is done using the osmdb_buildWays.py script. It reads the imported OSM data and builds a database table that matches the road network representation used by UrMoAC. The generated database table is called “<PREFIX>_network”.

The call is:

python osmdb_buildWays.py <HOST>,<DB>,<SCHEMA>.<PREFIX>,<USER>,<PASSWD>

Where:

  • <HOST>: the name of your database server;
  • <DB>: the name of your database;
  • <SCHEMA>: the database schema to store the database tables at;
  • <PREFIX>: a prefix for the database tables;
  • <USER>: the name of the user who has access (can generate tables and write into them) the database;
  • <PASSWD>: the password of the user.

Using OpenStreetMap data to build tables of certain structures

The script osmdb_buildStructures.py builds a database table that can be used to read origins / destinations from by parsing the contents of an OSM representation imported using osm2db.py.

Some structures can be represented in different ways within OpenStreetMap. The script osmdb_buildStructures.py tries to offer a simple way to gather the information about all instances of specific structures and store them into a single table, independent to their original representation within OpenStreetMap.

For this purpose, osmdb_buildStructures.py reads a definition file that describes which nodes, ways, or relations, defined by their tags, belong to a specific kind of structures. The format of the definitions file is:

[<OSM_DATATYPE>]
<FILTER>
...
<FILTER>

The <OSM_DATATYPE> is one of “node”, “way”, and “relation”. After this data type definition, the filtering options are given that describe which elements of this data type shall be included. Each line describes a single set and the sets will be merged. A <FILTER> includes one or more key/value pairs. If more than one is given, they are divided by a ‘&’. An element needs to match all of the key/value pairs within a line for being included.

Some examples:

[node]
public_transport=stop_position

All OpenStreetMap nodes that have the combination key='public_transport' and value='stop_position' — all public transport stops — are included.

[node]
public_transport=stop_position&bus=yes

All OpenStreetMap nodes that have the combination key='public_transport' and value='stop_position' and the combination key='bus' and value='yes' — all public transport stops where busses stop — are included.

The call is:

python osmdb_buildStructures.py <INPUT_TABLES_PREFIX> <DEF_FILE> <OUTPUT_TABLE>

Where:

  • <INPUT_TABLES_PREFIX>: definition of the database to find the imported OSM data at;
  • <DEF_FILE>: path to the definitions file to use;
  • <OUTPUT_TABLE>: definition of the database table to generate.

<INPUT_TABLES_PREFIX> is defined as following: <HOST>,<DB>,<SCHEMA>.<PREFIX>,<USER>,<PASSWD>

Where:

  • <HOST>: the name of your database server;
  • <DB>: the name of your database;
  • <SCHEMA>: the database schema to store the database tables at;
  • <PREFIX>: a prefix for the database tables;
  • <USER>: the name of the user who has access (can generate tables and write into them) the database;
  • <PASSWD>: the password of the user.

<OUTPUT_TABLE> is defined as following:<HOST>,<DB>,<SCHEMA>.<TABLE>,<USER>,<PASSWD>

Where:

  • <HOST>: the name of your database server;
  • <DB>: the name of your database;
  • <SCHEMA>: the database schema to store the database tables at;
  • <TABLE>: the name of the table to generate;
  • <USER>: the name of the user who has access (can generate tables and write into them) the database;
  • <PASSWD>: the password of the user.