root/branches/debug/extra/driving_distance/sql/routing_dd_wrappers.sql

Revision 128, 2.0 KB (checked in by anton, 3 years ago)

Debugging branch added

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-- BEGIN;
21----------------------------------------------------------
22-- Draws an alpha shape around given set of points.
23--
24-- Last changes: 14.02.2008
25----------------------------------------------------------
26CREATE OR REPLACE FUNCTION points_as_polygon(query varchar)
27       RETURNS SETOF GEOMS AS
28$$
29DECLARE
30     r record;
31     path_result record;                                             
32     i int;                                                         
33     q text;
34     x float8[];
35     y float8[];
36     geom geoms;
37     id integer;
38BEGIN
39       
40     id :=0;
41                                                                             
42     i := 1;                                                                 
43     q := 'select 1 as gid, GeometryFromText(''POLYGON((';
44     
45     FOR path_result IN EXECUTE 'select x, y from alphashape('''||
46         query || ''')' LOOP
47         x[i] = path_result.x;
48         y[i] = path_result.y;
49         i := i+1;
50     END LOOP;
51
52     q := q || x[1] || ' ' || y[1];
53     i := 2;
54
55     WHILE x[i] IS NOT NULL LOOP
56         q := q || ', ' || x[i] || ' ' || y[i];
57         i := i + 1;
58     END LOOP;
59
60    q := q || ', ' || x[1] || ' ' || y[1];
61    q := q || '))'',-1) as the_geom';
62
63    FOR r in EXECUTE q LOOP
64         geom.gid=r.gid;
65         geom.the_geom=r.the_geom;
66         id := id+1;
67         geom.id       := id;
68         RETURN NEXT geom;
69    END LOOP;
70
71    RETURN;
72END;
73$$
74
75LANGUAGE 'plpgsql' VOLATILE STRICT;
76
77-- COMMIT;
Note: See TracBrowser for help on using the browser.