Skip to content

Documentation for osm2pgrouting v2.1

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

Limitations

  • Can't 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
    

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]"

Flags

Get Version

$ osm2pgrouting -v
This is osm2pgrouting Version 2.1 beta

Get 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 Commands

From a clean database

  1. Create the database and add postGIS
createdb workshop
psql workshop
# CREATE EXTENSION postGIS;
  1. Process an osm file (NE)
osm2pgrouting osm2pgrouting \
   -f workshopNE.osm \
   --dbname workshop \
   -U foo -W bar
  1. Output of the process
Execution starts at: Sun Mar 20 11:48:32 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
    Parsing data

Spliting ways

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_tags': OK
Creating 'osm_way_types': OK
Creating 'osm_way_classes': OK
Adding auxiliary tables to database...
    Processing 4 way types:  Inserted 4 way types
    Processing way's classes:  Inserted 36 way's classes
    Processing way's relations:  Inserted: 22326way's relations
    Processing way's tags:  Inserted 25324 way's tags
    Processing 23902 ways:
Vertices inserted 16848    Ways inserted: 23902
Creating topology...
#########################
size of streets: 10959
size of splitted ways : 23902
Execution started at: Sun Mar 20 11:48:32 2016
Execution ended at:   Sun Mar 20 11:48:39 2016
Elapsed time: 7.917 Seconds.
User CPU time: -> 3.85067 seconds
#########################

From a database that already contains data

  1. Process an osm file (SE)
osm2pgrouting osm2pgrouting \
   -f workshopSE.osm \
   --dbname workshop \
   -U foo -W bar
  1. Output of the process
Execution starts at: Sun Mar 20 11:59:07 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
    Parsing data

Spliting ways

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_tags': OK
 Exists: 'osm_way_types': OK
 Exists: 'osm_way_classes': OK
Adding auxiliary tables to database...
    Processing 4 way types:  Inserted 0 way types
    Processing way's classes:  Inserted 0 way's classes
    Processing way's relations:  Inserted: 5026way's relations
    Processing way's tags:  Inserted 19271 way's tags
    Processing 22826 ways:
Vertices inserted 16880    Ways inserted: 22826
Creating topology...
#########################
size of streets: 10996
size of splitted ways : 22826
Execution started at: Sun Mar 20 11:59:07 2016
Execution ended at:   Sun Mar 20 11:59:13 2016
Elapsed time: 6.6 Seconds.
User CPU time: -> 3.12618 seconds
#########################

Using the clean flag

osm2pgrouting osm2pgrouting \
  -f workshopSmall.osm \
  --dbname workshop \
  -U foo -W bar --clean
Execution starts at: Sun Mar 20 12:10:47 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
    Parsing data

Spliting ways

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_tags': OK
 Exists: 'osm_way_types': OK
 Exists: 'osm_way_classes': OK
Adding auxiliary tables to database...
    Processing 4 way types:  Inserted 0 way types
    Processing way's classes:  Inserted 0 way's classes
    Processing way's relations:  Inserted: 6473way's relations
    Processing way's tags:  Inserted 2812 way's tags
    Processing 3625 ways:
Vertices inserted 2886    Ways inserted: 3625
Creating topology...
#########################
size of streets: 1914
size of splitted ways : 3625
Execution started at: Sun Mar 20 12:10:47 2016
Execution ended at:   Sun Mar 20 12:10:49 2016
Elapsed time: 1.742 Seconds.
User CPU time: -> 0.542412 seconds
#########################

Current Version Main contributors in alphabetical order:

Regina Obe, Sarthak Agarwal, Virginia Vergara

History of Contributors

Anton Patrushev, Daniel Kastl, Daniel Wendt, Jordan Anderson,J Kishore Kumar