This code was implemented some years ago when I found the native PostGIS voronoi function to be too slow on my data. At that time this custom function was way faster than the PostGIS one on larger datasets. I have done any comparisons on newer PostGIS versions, so things may have changed since then.
Also - this code solved my problems - it may not work for you. Use it on your own responsibility :-)
Function returns set of geometry_dump as known from PostGIS function st_dump.
If the second param is null the voronoi cells along the edge of the diagram will be unbounded. These are not returned by the function.
If the second param is not null, the bbox of the points is expanded by this value and four points added at the corners of the expanded bbox. this ensures that the original points are all enclosed in finite cells.
SET client_min_messages TO DEBUG;
SELECT * FROM septima.voronoi('MULTIPOINT ( 2 0, 2 3, 0 2, 2 0 )' :: geometry, 100);
SELECT path[1], st_astext(geom ::geometry(polygon)) FROM
(SELECT * FROM septima.voronoi('MULTIPOINT ( 2 0, 2 3, 0 2, 2 0 )' :: geometry, 100)) as foo;
Input must be one single geometry. Calculating voronoi for a set of point records can be done by using st_collect
.
--CREATE TABLE test_voronoi AS
SELECT path[1], geom ::geometry(polygon,25832)
FROM septima.voronoi(
(
SELECT st_collect(geom) as mpoint
FROM adresses
WHERE municipalitycode = '0101'
)
)