If you happen to prefer OpenStreetMap data for your routing solutions, you can use the osm2pgrouting utility to import network data directly from the OSM format.
As mentioned earlier, pgRouting may have been bundled with your PostGIS installation. In such cases, osm2pgrouting should already be installed - see if the utility is available in the PgSQL's bin, or simply type osm2pgrouting in the console.
If you see help for the tool, you're good to go; otherwise, you will have to install it.
osm2pgrouting gets much more love from Unix users (obviously), so if you happen to be one of a kind, in order to get the utility, follow the instructions from here: https://github.com/pgRouting/osm2pgrouting/tree/osm2pgrouting-2.1.0.
Windows versions of osm2pgrouting are available under the Unreleased PostGIS Versions section of the PostGIS download website (http://postgis.net/windows_downloads/) - do make sure you download the version appropriate for your setup - make sure the database version and PostGIS version match. Once downloaded, follow the instructions in the readme.
For this example, we will use data for Vienna from MapZen's metro extracts: https://s3.amazonaws.com/metro-extracts.mapzen.com/vienna_austria.osm.bz2. This is the Raw OpenStreetMap dataset in XML format.
Once downloaded and extracted, we can import it:
osm2pgrouting --conf <mapconfig.xml path> --file vienna_austria.osm --schema pgr --clean 1 --host localhost --db_port 5434 --user postgres --passwd postgres --dbname mastering_postgis
When you review the pgr schema, you will notice that there are a few more tables now - a couple of OSM dictionaries and ways and ways_vertices_pgr tables.
The data model of the ways table differs from the model imported from SHP. It is worth knowing the meaning of some of the data:
- length: Length of an edge in degrees
- length_m: Length of an edge in metres
- cost/reverse_cost: Length of an edge in degrees; negative value is for the wrong way
- cost_s/reverse_cost_s: Time in seconds calculated for the max speed for an edge