[postgis-users] dijkstra.sql
Rob Tester
robtester at gmail.com
Tue Apr 3 07:16:30 PDT 2007
I believe that the cartoweb precompiled binary is for 8.1 of PostgreSQL.
Download the source code for PostgreSQL 8.2 and the source for the dijkstra
lib and recompile using MinGW.
Install the new DLL in the <postgresql install>/lib directory
Then try and use the provided script.
That should take care of your problems.
Rob.
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Bayu
Kurniawan
Sent: Tuesday, April 03, 2007 6:45 AM
To: PostGIS Users Discussion
Subject: Re: [postgis-users] dijkstra.sql
This is sql file in dijkstra.sql, i'm using lib with the package in
http://cartoweb.org/downloads.html#pgdijkstra
i'm using mapserver ms4w, postgresql 8.2 and postgis 1.2.0-1 in windows
system
--
-- Shortest path algorithm for PostgreSQL
--
-- Copyright (c) 2005 Sylvain Pasche
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
--
CREATE TYPE path_result AS (step integer, vertex_id integer, edge_id
integer, cost float8);
-----------------------------------------------------------------------
-- Core function for shortest_path computation
-- See README for description
-----------------------------------------------------------------------
CREATE OR REPLACE FUNCTION shortest_path(sql text, source_id integer,
target_id integer,
directed boolean, has_reverse_cost
boolean)
RETURNS SETOF path_result
AS '$libdir/libdijkstra.dll'
LANGUAGE 'C' IMMUTABLE STRICT;
-----------------------------------------------------------------------
-- Drops the vertices and edges tables related to the given geom_table
-----------------------------------------------------------------------
CREATE OR REPLACE FUNCTION drop_graph_tables(geom_table varchar) RETURNS
void AS
$$
DECLARE
vertices_table varchar := quote_ident(geom_table) || '_vertices';
edges_table varchar := quote_ident(geom_table) || '_edges';
BEGIN
BEGIN
EXECUTE 'DROP TABLE ' || vertices_table;
EXCEPTION
WHEN UNDEFINED_TABLE THEN
END;
BEGIN
EXECUTE 'DROP TABLE ' || edges_table;
EXCEPTION
WHEN UNDEFINED_TABLE THEN
END;
RETURN;
END;
$$
LANGUAGE 'plpgsql' VOLATILE STRICT;
-----------------------------------------------------------------------
-- This function should not be used directly. Use create_graph_tables
instead
--
-- Insert a vertex into the vertices table if not already there, and
-- return the id of the newly inserted or already existing element
-----------------------------------------------------------------------
CREATE OR REPLACE FUNCTION insert_vertex(vertices_table varchar, geom_id
anyelement) RETURNS int AS
$$
DECLARE
vertex_id int;
myrec record;
BEGIN
LOOP
FOR myrec IN EXECUTE 'SELECT id FROM ' ||
quote_ident(vertices_table) ||
' WHERE geom_id = ' ||
quote_literal(geom_id) LOOP
IF myrec.id IS NOT NULL THEN
RETURN myrec.id;
END IF;
END LOOP;
EXECUTE 'INSERT INTO ' || quote_ident(vertices_table) || '
(geom_id) VALUES (' || quote_literal(geom_id) || ')';
END LOOP;
END;
$$
LANGUAGE 'plpgsql' VOLATILE STRICT;
-----------------------------------------------------------------------
-- Create the vertices and edges tables from a table matching the
-- geometry schema described above.
-----------------------------------------------------------------------
CREATE OR REPLACE FUNCTION create_graph_tables(geom_table varchar,
column_type varchar)
RETURNS void AS
$$
DECLARE
geom record;
edge_id int;
myrec record;
source_id int;
target_id int;
vertices_table varchar := quote_ident(geom_table) || '_vertices';
edges_table varchar := quote_ident(geom_table) || '_edges';
BEGIN
EXECUTE 'CREATE TABLE ' || vertices_table || ' (id serial, geom_id '
|| quote_ident(column_type) || ' NOT NULL
UNIQUE)';
EXECUTE 'CREATE INDEX ' || vertices_table || '_id_idx on ' ||
vertices_table || ' (id)';
EXECUTE 'CREATE TABLE ' || edges_table || ' (id serial, source int,
target int, '
|| 'cost float8, reverse_cost float8, UNIQUE
(source, target))';
EXECUTE 'CREATE INDEX ' || edges_table || '_source_target_idx on '
|| edges_table || ' (source, target)';
FOR geom IN EXECUTE 'SELECT gid as id, ' || ' source_id AS source, '
||
' target_id AS target FROM ' ||
quote_ident(geom_table) LOOP
SELECT INTO source_id insert_vertex(vertices_table,
geom.source);
SELECT INTO target_id insert_vertex(vertices_table,
geom.target);
edge_id := nextval(edges_table || '_id_seq');
EXECUTE 'INSERT INTO ' || edges_table || ' (id, source,
target) VALUES ('
|| edge_id || ', '
|| quote_literal(source_id) || ', '
|| quote_literal(target_id) || ')';
EXECUTE 'UPDATE ' || quote_ident(geom_table) || ' SET
edge_id = '
|| edge_id || ' WHERE gid = ' ||
quote_literal(geom.id);
END LOOP;
RETURN;
END;
$$
LANGUAGE 'plpgsql' VOLATILE STRICT;
----- Original Message ----
From: Rob Tester <robtester at gmail.com>
To: PostGIS Users Discussion <postgis-users at postgis.refractions.net>
Sent: Tuesday, April 3, 2007 8:22:01 PM
Subject: RE: [postgis-users] dijkstra.sql
What version of the lib did you install? Was it built against Postgre 8.1?
I would download the source and rebuild it against 8.2 then try to install
it again.
From: postgis-users-bounces at postgis.refractions.net
[mailto:postgis-users-bounces at postgis.refractions.net] On Behalf Of Bayu
Kurniawan
Sent: Monday, April 02, 2007 6:39 PM
To: postgis-users at postgis.refractions.net
Subject: [postgis-users] dijkstra.sql
I have some problems with installation of the pgdikstra. Running
dijkstra.sql gives this error message:
psql:dijkstra.sql:32: ERROR: incompatible library "C:/Program
Files/PostgreSQL/
8.2/lib/libdjikstra.dll" : missing magic block
HINT : Extension libraries are required to use the PG_MODULE_MAGIC macro
Any solutions for this?
Send instant messages to your online friends http://uk.messenger.yahoo.com
_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users
Send instant messages to your online friends http://uk.messenger.yahoo.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20070403/06c3d580/attachment.html>
More information about the postgis-users
mailing list