Database Reference
In-Depth Information
We require a cross join of the two in order to construct the regions into groups of
points making up each Voronoi region:
vregions AS (
SELECT ST_Collect(ST_MakePoint(pts[ptindex +
1][1], pts[ptindex + 1][2]) ORDER BY ptloc ) AS
vregions
FROM regptloc CROSS JOIN arpt
GROUP BY gid
)
Finally,thesegroupsofpointscanbeconstructedintopolygons.Theeasiestwayto
handle this is with convex hulls:
SELECT ST_ConvexHull(vregions) AS the_geom FROM
vregions
The complete code is as follows:
CREATE OR REPLACE FUNCTION chp04.voronoi_fast
(inputtext text)
RETURNS text
AS $$
from pyhull.voronoi import VoronoiTess
import ast
inputpoints = ast.literal_eval(inputtext)
dummylist = ast.literal_eval('[999999999]')
v = VoronoiTess(inputpoints)
return v.vertices + dummylist + v.regions
$$ LANGUAGE plpythonu;
DROP TABLE IF EXISTS chp04.voronoi_test_points;
Search WWH ::




Custom Search