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

Revision 28, 1.8 KB (checked in by anton, 3 years ago)

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