Skip to main content

Open StreetMap and pgRouting on OS X

Add APIDB Schema Support to your database (osm)

/usr/local/pgsql/bin/psql --user osm -d osm -f script/contrib/apidb_0.6.sql 

Download the .osm file from cloudmade or openstreetmap.org

Finally, import the file into postgres using the osmosis tool

bin/osmosis --read-xml file=../australia.osm \
--write-apidb host="localhost" database="osm" user="osm"

Which will produce the following output ... and it will take a LONG time... it takes a 2-3 gb .osm file (for Australia at least) and loads it into Postgres - resulting in a 100Gb+ database file containing all the nodes, and roads etc.

Apr 29, 2011 7:29:28 PM org.openstreetmap.osmosis.core.Osmosis run INFO: Osmosis Version 0.39
Apr 29, 2011 7:29:28 PM org.openstreetmap.osmosis.core.Osmosis run INFO: Preparing pipeline.
Apr 29, 2011 7:29:28 PM org.openstreetmap.osmosis.core.Osmosis run INFO: Launching pipeline execution.
Apr 29, 2011 7:29:28 PM org.openstreetmap.osmosis.core.Osmosis run INFO: Pipeline executing, waiting for completion.
Apr 29, 2011 8:55:11 PM org.openstreetmap.osmosis.core.Osmosis run INFO: Pipeline complete.
Apr 29, 2011 8:55:11 PM org.openstreetmap.osmosis.core.Osmosis run INFO: Total execution time: 1822346 milliseconds.
Apr 29, 2011 8:55:11 PM org.openstreetmap.osmosis.core.Osmosis run INFO: Pipeline complete.
Apr 29, 2011 8:55:11 PM org.openstreetmap.osmosis.core.Osmosis run INFO: Total execution time: 1822346 milliseconds.

Next install pgRouting and load support for the osm database and enable postgis support also

createlang plpgsql osm
psql -U osm -d osm -f postgis-1.5/postgis.sql
psql -U osm -d osm -f postgis-1.5/spatial_ref_sys.sql
psql -U osm -d osm -f routing_core.sql
psql -U osm -d osm -f routing_core_wrappers.sql
osm2pgrouting -file map.osm -conf mapconfig.xml -dbname osm -user osm -clean
SELECT assign_vertex_id('ways', 0.00001, 'the_geom', 'gid');
SELECT gid, AsText(the_geom) AS the_geom FROM dijkstra_sp('ways', 10, 20);