Database Reference
In-Depth Information
0.5]]
v.regions
returns:[[2, 0, 1], [4, 0, 2], [3, 0, 1], [4,
0, 3], [4, 2, 1, 3]]
Inordertousepyhull,weonlyneedtoimportthelibraryinsidea plpythonu func-
tion and call the functions available to us. This will require that PostgreSQL's PL /
Python-PythonProceduralLanguagebeinstalled.Thelanguagealsorequiresaddi-
tiontoourcurrentdatabase.See http://www.postgresql.org/docs/current/interactive/
plpython.html for more details.
CREATE EXTENSION plpythonu;
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;
Thisfunctionwilltaketextfromaquery,use ast.literal_eval tochangeourtext
intoalistinpreparationforpyhull,andthenpassthatlisttothe VoronoiTess func-
tion,returningthevertices-and-regionsofourVoronoicalculation.Notethevariable
dummylist aswell.Thisisaquickanddirtydelimiterthatwewillusetodetermine
which portion of the returning list comprises vertices and which comprises regions.
Search WWH ::




Custom Search