Shapy – A new pure-Python Shapely in the works

ImageOver the matter of the last few days, I was working on understanding the pure-Python version of Angus Johnson’s polygon Clipper library (that would be me to the right about now). As I got it working and wanted an easy way to test it I began adding more and more functionality, and before I knew it turned out to be quite solid and useful.

The package I ended up writing consiImagests of a bunch of geometrical
shape objects that the user can
create, measure, and manipulate with operations like intersect, union, distance, etc, which uses Angus’ Clipper and some of my own code in the background. This might sound a lot like the Sean Gillies’ Shapely library, and that’s fine because I modeled it directly on its geometry
types, attribute names, and methods. And hence the name Shapy
– a “lighter” pure-Python version of Shapely.

Some additional cool features are:

  • All shape types support the __geo_interface__ attribute so they can easily be sent to and used with other packages.
  • Shapes can be automatically created from any Python object that has the Image__geo_interface__ attribute.
  • And most but not least, a .view() method will visualize the shape for you, without having to think about imaging library dependencies, since Shapy comes packaged along with my other pure-Python PyDraw module. This is especially cool since you can for instance use the pure-Python PyShp shapefile reader to loop through shapes and instantly view each shape up close, since the shapes have the __geo_interface__ protocol.

Note though that Shapy is still in the works and lacks some features, but it can be used for very basic playing around with. See the docs on the Github page for more info on what’s currently supported, and available commands.

I would love contributions or suggestions on this one, since we’re dealing with quite advanced geometrical operations and vector math. Eventually it will probably need some optimization as well, but for now I just want to get it up and running with the basics.



    1. Hi Martijn 🙂 Very cool that you too had made a similar effort. I tried checking yours out to compare, but it looked like it was written (or converted) to C files via Cython. Anyway, I’m assuming then that you have some vector/geometry background or interest, so would be great if you want to add or improve some stuff. Specifically, among other things, I want to make the basic line2line shortest distance algorithm in the module (I already have point2line), which I think involves vectors and dot/crossproducts.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s