Skip to content

Documentation for osm2pgrouting v2.2

Vicky Vergara edited this page Nov 3, 2016 · 21 revisions

Index of this page:

What's new

  • mapconfig_for_bicycles.xml
  • progress bar
  • Foreign keys to tables
  • No use of pointers

Limitations

  • Can not process "large" files, continents, big countries, or very large states.

  • Undefined behaviour when: The tables already exist but not all the columns that are needed

    • Use --clean to drop old tables (only drops old routing tables)
  • PostGIS must be installed on the database, otherwise the following error will appear.

    ERROR: postGIS not found
    

Command

Version

$ osm2pgrouting --version
This is osm2pgrouting Version 2.2

Help

$ osm2pgrouting --help

Allowed options:

Help:
  --help                Produce help message for this version.
  -v [ --version ]      Print version string

General:
  -f [ --file ] arg                     REQUIRED: Name of the osm file.
  -c [ --conf ] arg (=/usr/share/osm2pgrouting/mapconfig.xml)
                                        Name of the configuration xml file.
  --schema arg                          Database schema to put tables.
                                          blank: defaults to default schema
                                          dictated by PostgreSQL Search_path.
  --prefix arg                          Prefix added at the beginning of the
                                        table names.
  --suffix arg                          Suffix added at the end of the table names.
  --addnodes                            Import the osm_nodes table.
  --clean                               Drop previously created tables.
               
Database options:
  -d [ --dbname ] arg               Name of your database (Required).
  -U [ --username ] arg (=postgres) Name of the user, which have write access 
                                    to the database.
  -h [ --host ] arg (=localhost)    Host of your postgresql database.
  -p [ --port ] arg (=5432)         db_port of your database.
  -W [ --password ] arg             Password for database access.

Sample Use

To a clean database

  1. Create the database and add postGIS
createdb workshop
psql workshop
# CREATE EXTENSION postGIS;
  1. Process an osm file (NE)
$ osm2pgrouting \
   -f workshopNE.osm \
   --dbname workshop \
   -U foo -W bar
  1. Output of the process
Execution starts at: Thu Nov  3 11:30:15 2016

***************************************************
           COMMAND LINE CONFIGURATION             *
***************************************************
Filename = workshopNE.osm
Configuration file = /usr/share/osm2pgrouting/mapconfig.xml
host = localhost
port = 5432
dbname = workshop
username = foo
password = bar
schema= 
prefix = 
suffix = 
Don't drop tables
Don't add nodes
***************************************************
Connecting to the database
host=localhost user=foo dbname=workshop port=5432 password=bar
connection success
Opening configuration file: /usr/share/osm2pgrouting/mapconfig.xml
    Parsing configuration

Opening data file: workshopNE.osm total lines 2601890
    Parsing data

[***********************************************|   ] (94%) Total Processed: 2471710    Finish Parsing data


Creating tables...
Creating 'ways_vertices_pgr': OK
   Adding Geometry: Creating 'ways': OK
   Adding Geometry: Creating 'relations_ways': OK
Creating 'osm_nodes': OK
   Adding Geometry: Creating 'osm_relations': OK
Creating 'osm_way_types': OK
Creating 'osm_way_classes': OK
Adding auxiliary tables to database...

Export Types ...
    Processing 4 way types:      Inserted: 4 in osm_way_types

Export Classes ...
    Processing way's classes:    Inserted: 36 in osm_way_classes

Export Relations ...
    Processing 0 relations:     Inserted: 0 in osm_relations

Export RelationsWays ...
    Processing way's relations:          Inserted: 0 in relations_ways

Export Ways ...
    Processing 110706 ways:
[*************************************************| ] (99%)    Ways Processed: 110706       Split Ways generated: 26435 Vertices inserted 18885 Inserted 26435 split ways
Creating Foreign Keys ...
Foreign keys for osm_way_classes table created
Foreign keys for relations_ways table created
Foreign keys for Ways table created
#########################
size of streets: 110706
Execution started at: Thu Nov  3 11:30:15 2016
Execution ended at:   Thu Nov  3 11:30:31 2016
Elapsed time: 16.606 Seconds.
User CPU time: -> 12.0584 seconds
#########################

To a database that already contains data

  1. Process an osm file (SE)
osm2pgrouting \
   -f workshopSE.osm \
   --dbname workshop \
   -U foo -W bar
  1. Output of the process
Execution starts at: Thu Nov  3 11:32:06 2016

***************************************************
           COMMAND LINE CONFIGURATION             *
***************************************************
Filename = workshopSE.osm
Configuration file = /usr/share/osm2pgrouting/mapconfig.xml
host = localhost
port = 5432
dbname = workshop
username = foo
password = bar
schema= 
prefix = 
suffix = 
Don't drop tables
Don't add nodes
***************************************************
Connecting to the database
host=localhost user=foo dbname=workshop port=5432 password=bar
connection success
Opening configuration file: /usr/share/osm2pgrouting/mapconfig.xml
    Parsing configuration

Opening data file: workshopSE.osm total lines 2136528
    Parsing data

[**********************************************|    ] (93%) Total Processed: 2008310    Finish Parsing data


Creating tables...
 Exists: 'ways_vertices_pgr': OK
 Exists: 'ways': OK
 Exists: 'relations_ways': OK
 Exists: 'osm_nodes': OK
 Exists: 'osm_relations': OK
 Exists: 'osm_way_types': OK
 Exists: 'osm_way_classes': OK
Adding auxiliary tables to database...

Export Types ...
    Processing 4 way types:      Inserted: 0 in osm_way_types

Export Classes ...
    Processing way's classes:    Inserted: 0 in osm_way_classes

Export Relations ...
    Processing 1 relations:     Inserted: 1 in osm_relations

Export RelationsWays ...
    Processing way's relations:          Inserted: 2 in relations_ways

Export Ways ...
    Processing 96407 ways:
[*************************************************| ] (99%)    Ways Processed: 96407        Split Ways generated: 27603 Vertices inserted 20735 Inserted 27564 split ways
Creating Foreign Keys ...
Foreign keys for osm_way_classes table created
Foreign keys for relations_ways table created
Foreign keys for Ways table created
#########################
size of streets: 96407
Execution started at: Thu Nov  3 11:32:06 2016
Execution ended at:   Thu Nov  3 11:32:22 2016
Elapsed time: 16.108 Seconds.
User CPU time: -> 10.3232 seconds
#########################

Using the clean flag

  1. Process an osm file (workshopSmall)
osm2pgrouting \
  -f workshopSmall.osm \
  --dbname workshop \
  -U foo -W bar --clean
  1. Output of the process
Execution starts at: Thu Nov  3 11:39:02 2016

***************************************************
           COMMAND LINE CONFIGURATION             *
***************************************************
Filename = workshopSmall.osm
Configuration file = /usr/share/osm2pgrouting/mapconfig.xml
host = localhost
port = 5432
dbname = workshop
username = foo
password = bar
schema= 
prefix = 
suffix = 
Drop tables
Don't add nodes
***************************************************
Connecting to the database
host=localhost user=foo dbname=workshop port=5432 password=bar
connection success
Opening configuration file: /usr/share/osm2pgrouting/mapconfig.xml
    Parsing configuration

Opening data file: workshopSmall.osm total lines 319513
    Parsing data

[***********************************************|   ] (94%) Total Processed: 303525    Finish Parsing data


Dropping tables...

Creating tables...
Creating 'ways_vertices_pgr': OK
   Adding Geometry: Creating 'ways': OK
   Adding Geometry: Creating 'relations_ways': OK
 Exists: 'osm_nodes': OK
 Exists: 'osm_relations': OK
 Exists: 'osm_way_types': OK
 Exists: 'osm_way_classes': OK
Adding auxiliary tables to database...

Export Types ...
    Processing 4 way types:      Inserted: 0 in osm_way_types

Export Classes ...
    Processing way's classes:    Inserted: 0 in osm_way_classes

Export Relations ...
    Processing 0 relations:     Inserted: 0 in osm_relations

Export RelationsWays ...
    Processing way's relations:          Inserted: 0 in relations_ways

Export Ways ...
    Processing 14354 ways:
[*************************************************| ] (98%)    Ways Processed: 14354        Split Ways generated: 3810  Vertices inserted 3050 Inserted 3810 split ways
Creating Foreign Keys ...
Foreign keys for osm_way_classes table created
Foreign keys for relations_ways table created
Foreign keys for Ways table created
#########################
size of streets: 14354
Execution started at: Thu Nov  3 11:39:02 2016
Execution ended at:   Thu Nov  3 11:39:05 2016
Elapsed time: 2.977 Seconds.
User CPU time: -> 1.56543 seconds
#########################

Table structure

  • <prefix>ways<suffix> The following shows when there are no prefix-suffix

    CREATE TABLE ways
    (
      gid bigserial NOT NULL,
      class_id integer NOT NULL,
      length double precision,
      length_m double precision,
      name text,
      source bigint,
      target bigint,
      x1 double precision,
      y1 double precision,
      x2 double precision,
      y2 double precision,
      cost double precision,
      reverse_cost double precision,
      cost_s double precision,
      reverse_cost_s double precision,
      rule text,
      one_way integer,
      maxspeed_forward integer,
      maxspeed_backward integer,
      osm_id bigint,
      source_osm bigint,
      target_osm bigint,
      priority double precision DEFAULT 1,
      the_geom geometry(LineString,4326),
      CONSTRAINT ways_pkey PRIMARY KEY (gid)
    )
  • <prefix>ways<suffix>_vertices_pgr The following shows when there are no prefix-suffix

    CREATE TABLE ways_vertices_pgr (
      id bigserial NOT NULL,
      osm_id bigint,
      cnt integer,
      chk integer,
      ein integer,
      eout integer,
      lon numeric(11,8),
      lat numeric(11,8),
      the_geom geometry(Point,4326),
      CONSTRAINT ways_vertices_pgr_pkey PRIMARY KEY (id),
      CONSTRAINT vertex_id UNIQUE (osm_id)
    )

Auxiliary tables

This queries are executed after executing osm2pgrouting (see bellow)

SELECT * FROM osm_way_types ;
 type_id |   name    
---------+-----------
       2 | cycleway
       1 | highway
       4 | junction
       3 | tracktype
(4 rows)
SELECT * FROM osm_way_classes;
 class_id | type_id |       name        | priority | default_maxspeed 
----------+---------+-------------------+----------+------------------
      201 |       2 | lane              |        1 |               50
      204 |       2 | opposite          |        1 |               50
      203 |       2 | opposite_lane     |        1 |               50
      202 |       2 | track             |        1 |               50
...
SELECT * FROM osm_way_tags;
 class_id | way_id 
----------+--------
      101 |   9751
      101 |   9753
      101 |   9768
...

Data

The following sample data used in this documentation:

BBOX="-122.8,45.4,-122.5,45.6"
wget --progress=dot:mega -O "workshop.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]"
BBOX="-122.65,45.5, -122.5,45.6"
wget --progress=dot:mega -O "workshopNE.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]"
BBOX="-122.65,45.4, -122.5,45.5"
wget --progress=dot:mega -O "workshopSE.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]"
BBOX="-122.8,45.5, -122.65,45.6"
wget --progress=dot:mega -O "workshopNW.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]"
BBOX="-122.8,45.4, -122.65,45.5"
wget --progress=dot:mega -O "workshopSW.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]"
BBOX="-122.65,45.4, -122.6,45.45"
wget --progress=dot:mega -O "workshopSmall.osm" "http://www.overpass-api.de/api/xapi?*[bbox=${BBOX}][@meta]"

Contributors

Version 2.2 contributors in alphabetical order:

  • Adrien Pavie - added mapconfig_for_bycicles.xml
  • Luís de Sousa - added foreign keys
  • Mark Dimond, - testing
  • Virginia Vergara - eliminate the use of pointers, progress bar, bugs fixing

History of Contributors

Adrien Pavie, Anton Patrushev, Daniel Kastl, Daniel Wendt, Jordan Anderson, J Kishore Kumar, Ko Nagase, Luís de Sousa, Mark Dimond, Regina Obe, Sarthak Agarwal, Virginia Vergara

Clone this wiki locally