Shapely

Shapely was mentioned in the WKT section for import and export ability. But its true purpose is a generic geometry library. Shapely is a high-level, pythonic interface to the GEOS library for geometric operations. In fact, Shapely intentionally avoids reading or writing files. It relies completely on data import and export and maintains focus on geometry manipulation.

Let's do a quick Shapely demonstration in which we'll define a single WKT polygon and then import it into Shapely. Then we'll measure the area. Our computational geometry will consist of buffering that polygon by a measure of 5 which will return a new, bigger polygon for which we'll measure the area:

>>> from shapely import wkt, geometry >>> wktPoly = "POLYGON((0 0,4 0,4 4,0 ...

Get Learning Geospatial Analysis with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.