[GIS] How to get a route between two points using PgRouting with TIGER2010 Data

pgroutingpostgis

A little background:

I've got PostGIS 2.0 and all the TIGER2010 data loaded for a U.S. State California.

I've got a table with points stored as data type geometry. I've learned enough to get the distance "as the crow flies" between two of the points and my samples are satisfactory when comparing them with Google Earth.

Now, I'd like to generate distance via a street/highway route. The requirements on the route are that it be the shortest. I only need shortest travel distance as a numeric value. No pretty maps.

-I've got every TIGER 2010 shape files loaded for California in PostGIS 2.0. I'm such a newbie it's not clear to me if this is sufficient data for calculating a route using PgRouting. Is it?

-If TIGER 2010 data is sufficient, does it need to be prepared somehow for a shortest_distance query?

If there's a useful how-to somewhere, then please send that along as a reply.


As a total newbie, I didn't know that the roads data is already loaded in the 'edges' table. Thanks to the commenter below for pointing it out!

Now, follow the instructions here: http://underdark.wordpress.com/2011/02/07/a-beginners-guide-to-pgrouting/

That should satisfy the 'lines layer' requirement Fabien is referring to.

Best Answer

All you need if you want to run the shortest path (Dirkjtra algorithm) is a basic set if colomns listed in this workshop :

http://workshop.pgrouting.org/chapters/shortest_path.html

You need only one polylines or lines layer. The function assign vertex creates the topology.

source and target are the identifier for the first and last node of each geometry. It is used to build the topology. You have to use the funciton assign_vertex in the link above.

Then you need a colomn that is your cost. Again all explained the document above. All the algorithm except the shooting star crash if cost are negative.

You can use the reverse_cost is you want a cost from source to target and a different cost from target to node.

Algorithms A* and Dirkjtra are from node to node. The example of queries are in the link above. Shooting * goes from segment to segment. Shooting * accepts cost that are negative as a way to prevent one way of a segment to be used.

A* need additionnal fields compared to Dirkjtra, becauses it uses heuristics relying on geography. Shooting * requires even more field, for it can implements turn restrictions. Go through the document.

This website also register other tutos that are not official. http://ebmgh.com/blog/2009/12/computing-directions-with-pgrouting/

Take it step by step, READ the documentation and for Dirkjtra and A* there is no real difficulty.

Good luck. As for the data, if you can build a topology, you're good to go.

Related Question