[GIS] How to route between lat/lon pairs in pgRouting

openstreetmappgroutingpostgispostgresql

I have set up Postgresql, PostGIS and pgrouting on Ubuntu.
I have imported an osm for wales using the following command:

./osm2pgrouting -file wales.osm \
                            -conf mapconfig.xml \
                            -dbname routing \
                            -user postgres \
                            -clean

All I now want to do is execute something to give me the fastest route between 2 Latitude/Longitude points.

Start: 51.499954,-3.571651
End: 53.386809,-4.445

The route has to be in the format of a series of latitude/longitude positions that make up the route.

Is this even possible? If not, what would it take to make it possible.

If it is possible, what sql do I need to execute?

I have been looking everywhere for an answer to no avail.

Further to Steve Horn's recommendation. I have now managed to get 5000 points coming back using this sql:

SELECT gid, AsText(the_geom) AS the_geom FROM dijkstra_sp('ways', 15522, 26857);

However, the points all seem to be ignoring the road type.
(When I run it using Google Directions, the route mainly follows the main roads).
What have I done wrong?

Best Answer

There is a great walkthrough of using the shortest_path() and shortest_path_astar() methods here: http://workshop.pgrouting.org/chapters/shortest_path.html

These methods rely on parameters representing vertex Ids from your table that was created using osm2pgrouting. The vertex Ids are the source and target columns in the ways table.

To find the closest vertex to your lat/lng pair, you can use find_nearest_node_within_distance from the script found here: https://github.com/pgRouting/pgrouting/blob/master/core/sql/matching.sql

Related Question