How to install pgRouting in Windows.
I ran through a day trying to get everything works for PostgreSQL 9.1, PostGIS 2.0 & pgRouting 1.03.
But so far, pgRouting not working when run in Windows, missing librouting.dll when execute the SQL file provided from pgRouting page, even thought the library is there…not sure why…so I skip the part investigating this issue.
And for you Ubuntu, i’m pretty sure it’s working fine with PostgresSQL 9.1 version even thought am yet try to install it. 😉
Here the installation process:
- Install PostgreSQL 8.4.4 (follow the instructions – and remember the password! 😉 )
- Install PostGIS 2.0 (follow the instructions)
- Extract pgRouting-1.03_pg-8.4.2.zip then, copy & paste following to PostgreSQL/8.4/lib.
- Open up pgAdmin3(which installed together in #1) & connect to the PostgreSQL. Proceed with following
1. Open up SQL Pane.
2. Execute all SQL located in ‘<path_to_the_folder>/pgRouting-1.03_pg-8.4.2/Share/Contrib’
Now, we done with pgRouting core.
Next, to the table schema & data. For this purpose, If you already have routes in shapefile ( or any other format ), you can insert it to PostgreSQL using any tools you like to. In my case, I use QGis – Spit.
Once you already export it to the database, ensure the table have the following columns:
- gid (integer)
- id (integer)
- the_geom ()
You may need to add id column if you don’t have one – my case, I don’t have..so just add the `id` column and update `id` = `gid`.
Next, you need 3 main columns – source, target & length. Just run following command and of course, change the table name. 🙂
- ALTER TABLE <table_name> ADD COLUMN source integer;
- ALTER TABLE <table_name> ADD COLUMN target integer;
- ALTER TABLE <table_name> ADD COLUMN length double precision;
OK, now we’re done with table fields. Next, with table index, run following queries:
- SELECT assign_vertex_id(‘<table_name>’, 0.001, ‘the_geom’, ‘gid’);
- UPDATE <table_name> SET length = length(the_geom);
- CREATE INDEX source_idx ON <table_name>(source);
- CREATE INDEX target_idx ON <table_name>(target);
- CREATE INDEX geom_idx ON <table_name> USING GIST(the_geom GIST_GEOMETRY_OPS);
Hopefully there’s no issue so far… ^_^
Now, it’s the test part…let’s test it! Run following queries!
- Test core function of shortest path – SELECT * FROM shortest_path(‘SELECT gid as id,source::integer,target::integer,length::double precision as cost FROM road_malaysia’,<source>,<target>, false, false);
- Test Dijkstra – SELECT gid, AsText(the_geom) AS the_geom FROM dijkstra_sp(‘road_malaysia’,<source>,<target>);
If you get the results, means all OK! if not…it’s better to run through step by step…or..diagnose what’s the error message…or can drop by the message here. 😉