-1

I installed postgresql 9.1.12 & created database "mydb" with user "abc" as below:

sudo apt-get install postgresql-9.1 postgresql-9.1-contrib postgresql-9.1-postgis and created databse "mydb". Then extended the mydb using

psql -h localhost -d mydb -U abc -f /usr/share/postgresql/9.1/contrib/postgis-1.5/postgis.sql

psql -h localhost -d mydb -U abc -f /usr/share/postgresql/9.1/contrib/postgis-1.5/spatial_ref_sys.sql

Then installed pgrouting to "mydb" in my ubuntu 12.04 machine after downloading .deb file using:

sudo dpkg -i Downloads/postgresql-9.1-pgrouting_2.1.0-ppa1~precise1_i386.deb

psql -h localhost -d mydb -U abc -f /usr/share/postgresql/9.1/extension/pgrouting--2.1.0.sql 

How to calculate shortest path of table "roads" ? I tried this https://anitagraser.com/2011/02/07/a-beginners-guide-to-pgrouting/ but the function shortest_path is not working.

1

try dijsktra algorithm:

SELECT * FROM pgr_dijkstra('
    SELECT id,
         source,
         target,
         cost,
         reverse_cost
        FROM ways',
    15, 
    16, 
    directed := true)
  • source and target - columns which represent id of vertices
  • cost and reverse cost - cost of edges for calculate shortest path. you can use cost for time for fastest path or lentg of edges for shortest path
  • 15, 16 - some numbers, ending vertices of your path
  • directed - true for directed graph, false for undirected

If you want shortest path replace cost and reverse_cost column with st_length(geometry_column)

Keep in mind this function you can use only for network topology. I does not, use pgr_createTopology function. More informations you can find here: http://workshop.pgrouting.org/2.1.0-dev/en/index.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.