Using Shapely to handle geometries
Shapely is a Python package for the analysis of planar features. It uses functions from the GEOS library and a port of the Java Topology Suite (JTS).
It has mainly the same classes and functions as OGR while dealing with geometries. Although it's not a replacement for OGR, it has a more pythonic and a very intuitive interface, it is better optimized, and it has a well-developed documentation.
To make things clear, Shapely is intended to analyze geometries and only geometries. It does not handle features' attributes, neither is it capable of reading and writing geospatial files.
For a direct comparison of Shapely and OGR, we are going to rewrite the previous examples:
Add the following lines to the
wkt_experiments.py
file (you can keep or remove the previous code, it's up to you):from shapely.geometry import Polygon print('Examples with Shapely') polygon1 = Polygon([(1, 1), (1, 9), (8, 9), (8, 1), (1, 1)]) print(polygon1.__class__) print(polygon1.area) polygon2...