FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pgrouting/sql/alpha_shape/alpha_shape.sql at master · gisdevelope/pgrouting · GitHub
gisdevelope
/
pgrouting
Public
forked from
pgRouting/pgrouting
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
pgrouting
/
sql
/
alpha_shape
/
alpha_shape.sql
Copy path
More file actions
More file actions
Latest commit
History
History
History
100 lines (86 loc) · 2.83 KB
Breadcrumbs
pgrouting
/
sql
/
alpha_shape
/
alpha_shape.sql
Copy path
File metadata and controls
100 lines (86 loc) · 2.83 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
PGR-GNU*****************************************************************
Copyright (c) 2015 Celia Virginia Vergara Castillo
Copyright (c) 2006-2007 Anton A. Patrushev, Orkney, Inc.
Copyright (c) 2005 Sylvain Pasche,
Mail: project@pgrouting.org
------
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU
*/
/*
-----------------------------------------------------------------------
-- Core function for alpha shape computation.
-- The sql should return vertex ids and x,y values. Return ordered
-- vertex ids.
-----------------------------------------------------------------------
*/
CREATE OR REPLACE
FUNCTION
pgr_alphashape
(sql
text
, alpha float8 DEFAULT
0
, OUT x float8, OUT y float8)
RETURNS SETOF record
AS
'
${MODULE_PATHNAME}
'
,
'
alphashape
'
LANGUAGE c VOLATILE;
/*
----------------------------------------------------------
-- Draws an alpha shape around given set of points.
-- ** This should be rewritten as an aggregate. **
----------------------------------------------------------
*/
CREATE OR REPLACE
FUNCTION
pgr_pointsAsPolygon
(query
varchar
, alpha float8 DEFAULT
0
)
RETURNS geometry
AS
$$
DECLARE
r record;
geoms geometry[];
vertex_result record;
i
int
;
n
int
;
spos
int
;
q
text
;
x float8[];
y float8[];
BEGIN
geoms :
=
array[]::geometry[];
i :
=
1
;
FOR vertex_result
IN
EXECUTE
'
SELECT x, y FROM pgr_alphashape(
'
'
'
||
query
||
'
'
'
,
'
||
alpha
||
'
)
'
LOOP
x[i]
=
vertex_result
.
x
;
y[i]
=
vertex_result
.
y
;
i :
=
i
+
1
;
END LOOP;
n :
=
i;
IF n
=
1
THEN
RAISE NOTICE
'
n = 1
'
;
RETURN
NULL
;
END IF;
spos :
=
1
;
q :
=
'
SELECT ST_GeometryFromText(
'
'
POLYGON((
'
;
FOR i
IN
1
..n LOOP
IF x[i] IS
NULL
AND
y[i] IS
NULL
THEN
q :
=
q
||
'
,
'
||
x[spos]
||
'
'
||
y[spos]
||
'
))
'
'
,0) AS geom;
'
;
EXECUTE q INTO r;
geoms :
=
geoms
||
array[
r
.
geom
];
q :
=
'
'
;
ELSE
IF q
=
'
'
THEN
spos :
=
i;
q :
=
'
SELECT ST_GeometryFromText(
'
'
POLYGON((
'
;
END IF;
IF i
=
spos THEN
q :
=
q
||
x[spos]
||
'
'
||
y[spos];
ELSE
q :
=
q
||
'
,
'
||
x[i]
||
'
'
||
y[i];
END IF;
END IF;
END LOOP;
RETURN ST_BuildArea(ST_Collect(geoms));
END;
$$
LANGUAGE
'
plpgsql
'
VOLATILE STRICT;
Back
|
FazBrowse Home
|
New Git URL