root/trunk/core/sql/routing_core.sql

Revision 43, 3.5 KB (checked in by anton, 3 years ago)

trunk replaced with 1.0RC1

Line 
1--
2-- Copyright (c) 2005 Sylvain Pasche,
3--               2006-2007 Anton A. Patrushev, Orkney, Inc.
4--
5-- This program is free software; you can redistribute it and/or modify
6-- it under the terms of the GNU General Public License as published by
7-- the Free Software Foundation; either version 2 of the License, or
8-- (at your option) any later version.
9--
10-- This program is distributed in the hope that it will be useful,
11-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13-- GNU General Public License for more details.
14--
15-- You should have received a copy of the GNU General Public License
16-- along with this program; if not, write to the Free Software
17-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18--
19
20
21CREATE TYPE path_result AS (vertex_id integer, edge_id integer, cost float8);
22CREATE TYPE vertex_result AS (x float8, y float8);
23
24-----------------------------------------------------------------------
25-- Core function for shortest_path computation
26-- See README for description
27-----------------------------------------------------------------------
28CREATE OR REPLACE FUNCTION shortest_path(sql text, source_id integer,
29        target_id integer, directed boolean, has_reverse_cost boolean)
30        RETURNS SETOF path_result
31        AS '$libdir/librouting'
32        LANGUAGE 'C' IMMUTABLE STRICT;
33
34-----------------------------------------------------------------------
35-- Core function for shortest_path_astar computation
36-- Simillar to shortest_path in usage but uses the A* algorithm
37-- instead of Dijkstra's.
38-----------------------------------------------------------------------
39CREATE OR REPLACE FUNCTION shortest_path_astar(sql text, source_id integer,
40        target_id integer,directed boolean, has_reverse_cost boolean)
41         RETURNS SETOF path_result
42         AS '$libdir/librouting'
43         LANGUAGE 'C' IMMUTABLE STRICT;
44
45-----------------------------------------------------------------------
46-- Core function for shortest_path_astar computation
47-- Simillar to shortest_path in usage but uses the Shooting* algorithm
48-----------------------------------------------------------------------
49CREATE OR REPLACE FUNCTION shortest_path_shooting_star(sql text, source_id integer,
50        target_id integer,directed boolean, has_reverse_cost boolean)
51         RETURNS SETOF path_result
52         AS '$libdir/librouting'
53         LANGUAGE 'C' IMMUTABLE STRICT;
54
55-----------------------------------------------------------------------
56-- This function should not be used directly. Use create_graph_tables instead
57--
58-- Insert a vertex into the vertices table if not already there, and
59--  return the id of the newly inserted or already existing element
60-----------------------------------------------------------------------
61CREATE OR REPLACE FUNCTION insert_vertex(vertices_table varchar,
62       geom_id anyelement)
63       RETURNS int AS
64$$
65DECLARE
66        vertex_id int;
67        myrec record;
68BEGIN
69        LOOP
70          FOR myrec IN EXECUTE 'SELECT id FROM ' ||
71                     quote_ident(vertices_table) ||
72                     ' WHERE geom_id = ' || quote_literal(geom_id)  LOOP
73
74                        IF myrec.id IS NOT NULL THEN
75                                RETURN myrec.id;
76                        END IF;
77          END LOOP;
78          EXECUTE 'INSERT INTO ' || quote_ident(vertices_table) ||
79                  ' (geom_id) VALUES (' || quote_literal(geom_id) || ')';
80        END LOOP;
81END;
82$$
83LANGUAGE 'plpgsql' VOLATILE STRICT;
Note: See TracBrowser for help on using the browser.