pgr_alphaShape
— Core function for alpha shape computation.
Returns a table with (x, y) rows that describe the vertices of an alpha shape.
table() pgr_alphaShape(text sql [, float8 alpha]);
sql: |
SELECT id, x, y FROM vertex_table
|
||||||
---|---|---|---|---|---|---|---|
alpha: | (optional) |
Returns a vertex record for each row:
x: | x-coordinate |
---|---|
y: | y-coordinate |
If a result includes multiple outer/inner rings, return those with separator row (x=NULL and y=NULL).
History
PgRouting’s alpha shape implementation has no way to control the order of the output points, so the actual output might different for the same input data. The first query, has the output ordered, he second query shows an example usage:
Example: the (ordered) results
SELECT * FROM pgr_alphaShape(
'SELECT id::integer, ST_X(the_geom)::float AS x, ST_Y(the_geom)::float AS y
FROM edge_table_vertices_pgr') ORDER BY x, y;
x | y
-----+-----
0 | 2
0.5 | 3.5
2 | 0
2 | 4
3.5 | 4
4 | 1
4 | 2
4 | 3
(8 rows)
Example: calculating the area
Steps:
- Calculates the alpha shape - the
ORDER BY
clause is not used.- constructs a polygon
- and computes the area
SELECT round(ST_Area(ST_MakePolygon(ST_AddPoint(foo.openline, ST_StartPoint(foo.openline))))::numeric, 2) AS st_area
FROM (
SELECT ST_MakeLine(points ORDER BY id) AS openline
FROM (
SELECT ST_MakePoint(x, y) AS points, row_number() over() AS id
FROM pgr_alphaShape(
'SELECT id::integer, ST_X(the_geom)::float AS x, ST_Y(the_geom)::float AS y
FROM edge_table_vertices_pgr')
) AS a
) AS foo;
st_area
---------
11.75
(1 row)
The queries use the Sample Data network.