Polygon is a Python package that handles polygonal shapes in 2D. It contains Python bindings for gpc, the excellent General Polygon Clipping Library by Alan Murta and some extensions written in C and pure Python. With Polygon you may handle complex polygonal shapes in Python in a very intuitive way. Polygons are simple Python objects, clipping operations are bound to standard operators like +, -, |, & and ^. TriStrips can be constructed from Polygons with a single statement. Functions to compute the area, center point, convex hull, point containment and much more are included.
Points can be organized in tuples or lists. NumPy arrays are also supported but Polygon can be compiled without support for it.
This package was already used to process shapes with more than one million points!
- License: LGPL (not for gpc itself, see below!)
- Status: Should be almost stable now, but there may be memory leaks. Malformed files and illegal contours may crash the library and your running Python interpreter! Use Polygon at your own risk or don’t use it at all!
- gpc-Homepage: http://www.cs.man.ac.uk/~toby/alan/software/
gpc is included in Polygon, you don’t need to download it separately. I made two small changes to gpc:
- fixed warnings regarding a printf format string and
- made GPC_EPSILON adjustable, this may slow down the clipping a little bit.
The author of gpc (Alan Murta) is not responsible for this distribution! The wrapping and extension code is free software, but the core gpc library is free for non-commercial usage only. The author says:
GPC is free for non-commercial use only. We invite non-commercial users to make a voluntary donation towards the upkeep of GPC. If you wish to use GPC in support of a commercial product, you must obtain an official GPC Commercial Use Licence from The University of Manchester.
Please respect this statement and contact the author (see gpc homepage) if you wish to use this software in commercial projects!
Download, Documentation & Examples
The package can be downloaded from the Python Package Index PyPI:
The development files as well as documentation and examples are hosted at bitbucket. There are two different projects: