Database Reference
In-Depth Information
Using external scripts to embed other
libraries in order to calculate a Voronoi
diagram - advanced
While the previous recipe works fine for typical cases, faster approaches are avail-
able. Rather than functions built into Python, we can leverage Python libraries that
arewrappersforcompiledC++code,resultinginanorder-of-magnitudeimprovement
inspeed.Thepricewepayiswritingafunctiontoembedthefasterfunctionality.This
price is a one-time cost of thought and consideration and well worth the pay off for
faster computation that will be, in some cases, orders-of-magnitude faster than our
native Python function.
Inaddition,thepatternwewillbeusing,thatis,passingdatafromPostGIStoanex-
ternalpackageandreturninginformationfromthatpackage,isusefulfordoingavari-
ety of processing that is not available in PostGIS or PostgreSQL natively, but may
otherwisebeavailableinanexternallibraryorprogram.Inotherwords,oncePostGIS
hasanativeVoronoifunction,wecanreusethispatterntosolveotherproblemswith
similar libraries.
Thisrecipeisagoodexampleofhowfunctionalitycanbeimportedfromexternallib-
rariestomatchthefunctionalityavailableinPostGIS,evenacomplicatedfunctionality
such as geometry processing.
Getting ready
The external library we will be using is called pyhull, a Python wrapper to a library
called QHull, which allows us to perform a variety of convex geometry calculations.
We will take advantage of QHull/pyhull to do Voronoi calculations.
Download the appropriate pyhull for your operating system from ht-
tp://pypi.python.org/pypi/pyhull/ .
On Mac OS X, installation is straightforward. On the command line, navigate to the
directory where the pyhull egg is downloaded and enter the following command:
Search WWH ::




Custom Search