[pgrouting-users] Dijkstra algorithm

Alexander Logvinov avl at logvinov.com
Mon Nov 9 03:30:20 EST 2009


Hello!

 I try to use pgRouting from trunk with my map by setting up the table
for Dijkstra:

blg=# ALTER TABLE blg_street_line ADD COLUMN source integer;
blg=# ALTER TABLE blg_street_line ADD COLUMN target integer;
blg=# ALTER TABLE blg_street_line ADD COLUMN length double precision;
blg=# SELECT assign_vertex_id('blg_street_line', 0.001, 'the_geom', 'gid');
blg=# UPDATE blg_street_line SET length = length(the_geom);
blg=# CREATE INDEX source_idx ON blg_street_line(source);
blg=# CREATE INDEX target_idx ON blg_street_line(target);
blg=# CREATE INDEX geom_idx ON blg_street_line USING GIST(the_geom
GIST_GEOMETRY_OPS);

blg=# \d blg_street_line;
                                  Table "public.blg_street_line"
  Column  |         Type          |                           Modifiers

----------+-----------------------+---------------------------------------------------------------
 gid      | integer               | not null default
nextval('blg_street_line_gid_seq'::regclass)
 type     | character varying(80) |
 name     | character varying(80) |
 the_geom | geometry              |
 priority | smallint              | default 2
 trafdir  | smallint              | default 0
 source   | integer               |
 target   | integer               |
 length   | double precision      |
Indexes:
    "blg_street_line_pkey" PRIMARY KEY, btree (gid)
    "geom_idx" gist (the_geom)
    "source_idx" btree (source)
    "target_idx" btree (target)
Check constraints:
    "enforce_dims_the_geom" CHECK (ndims(the_geom) = 2)
    "enforce_geotype_the_geom" CHECK (geometrytype(the_geom) =
'MULTILINESTRING'::text OR the_geom IS NULL)
    "enforce_srid_the_geom" CHECK (srid(the_geom) = 3395)

blg=# SELECT * FROM geometry_columns WHERE f_table_name = 'blg_street_line';
 f_table_catalog | f_table_schema |  f_table_name   | f_geometry_column
| coord_dimension | srid |      type
-----------------+----------------+-----------------+-------------------+-----------------+------+-----------------
                 | public         | blg_street_line | the_geom
|               2 | 3395 | MULTILINESTRING
(1 row)

blg=# SELECT gid, source, target, length FROM blg_street_line;
gid | source | target |      length
-----+--------+--------+------------------
   2 |      1 |      2 | 359.786582322708
   3 |      3 |      4 | 641.174982348269
   5 |      5 |      6 | 356.647744733623
   4 |      7 |      8 | 430.543306405701
  38 |     67 |     68 | 452.542721018381
  66 |    119 |    120 |  821.46240325183
  73 |    133 |    134 |  849.62842916855
  75 |    136 |    137 | 341.969523123143
  81 |    144 |    145 | 7680.05384737189
  82 |    146 |    147 | 9040.75287387348
 116 |    206 |    207 | 1742.55535248839
 150 |    267 |    268 | 6687.15130571971
 151 |    269 |    270 | 9235.48566584237
 153 |    273 |    274 | 10074.3326260434
 147 |    275 |    276 |   11871.93556267
 146 |    277 |    278 | 7862.21121678247
 161 |    290 |    291 | 1288.55040633845
 162 |    292 |    275 | 10810.0035547453
...

 It works with source and target from the same gid:

blg=# SELECT gid, AsText(the_geom) AS the_geom FROM
dijkstra_sp('blg_street_line', 67, 68);
 gid |
                         the_geom

-----+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  38 | MULTILINESTRING((14195089.2850832
6462945.07615143,14195062.8051868 6462796.06054766,14195055.5221706
6462744.72404812,14195031.5212768 6462621.58249126,14195009.0101087
6462499.76150234))
(1 row)

 And no luck with another source and target:

blg=# SELECT gid, AsText(the_geom) AS the_geom FROM
dijkstra_sp('blg_street_line', 67, 145);
 gid | the_geom
-----+----------
(0 rows)

# pkg_info -Ix post
postgis-1.4.0       Adds support for geographic objects to PostgreSQL
databases
postgresql-client-8.3.7,1 PostgreSQL database (client)
postgresql-server-8.3.7 The most advanced open-source database available
anywhere

# uname -sr
FreeBSD 9.0-CURRENT

 Here is blg_street_line and vertices_tmp tables:
http://www.logvinov.ru/files/pg/sql.tar.bz2
 And the screenshot of blg_street_line with OpenLayers:
http://www.logvinov.ru/files/pg/preview.png

 Something wrong with my table content? Thanks!

Best regards,
Alexander



More information about the Pgrouting-users mailing list