osm2pgrouting is a powerful tool that handles a lot of the translation of OSM data into a format that can be used in pgRouting. In this case, it creates eight tables from our input file. Of those eight, we'll address the two primary tables: the ways table and the nodes table.
Our ways table is a table of the lines that represent all our streets, roads, and trails that are in OSM. The nodes table contains all the intersections. This helps us identify the beginning and end points for routing.
Let's apply an A* ("A star") routing approach to this problem.
You will recognize the following syntax from Dijkstra:
WITH astar AS (
SELECT * FROM pgr_astar(
'SELECT gid AS id, source, target,
length AS cost, x1, y1, x2, y2
FROM chp06.cleveland_ways', 89475, 14584, false
)
)
SELECT gid, the_geom
FROM chp06.cleveland_ways w, astar a
WHERE w.gid = a.edge;
The following screenshot shows the results displayed on a map (map tiles by Stamen Design, under CC BY 3.0; data by OpenStreetMap, under CC BY SA):
