Database Reference
In-Depth Information
CREATE TABLE chp04.voronoi_test AS
SELECT * FROM
voronoi('chp04.voronoi_test_points_u',
'the_geom') AS (id integer, the_geom geometry);
ButthereisasmallbuginourcodethatreturnssomepolygonsthatarenotVoronoi.
We'llpatchthisbytestingtomakesurethatwehaveonepointperpolygonandonly
return the polygons with one point.
First,wewillcreateanindexforourpointsandourVoronoiusingthefollowingfunc-
tion:
CREATE INDEX
chp04_voronoi_test_points_u_the_geom_idx ON
chp04.voronoi_test_points_u USING
gist(the_geom);
CREATE INDEX chp04_voronoi_test_the_geom_idx ON
chp04.voronoi_test USING gist(the_geom);
Finally, we can return just the Voronoi polygons that intersect with a single point.
CREATE TABLE chp04.voronoi_test_points_u_clean
AS
WITH voronoi AS (
SELECT COUNT(*), v.the_geom
FROM chp04.voronoi_test v,
chp04.voronoi_test_points_u p
WHERE ST_Intersects(v.the_geom, p.the_geom)
GROUP BY v.the_geom
)
SELECT the_geom FROM voronoi WHERE count = 1;
And we will get a nice Voronoi diagram as follows:
Search WWH ::




Custom Search