PyShp

PyShp is a simple, pure Python library that reads and writes shapefiles. It doesn't do any geometry operations and only uses Python's standard library. It's contained in a single file that's easy to move around, squeeze onto small embedded platforms, and modify. It is also compatible with Python 3. It also implements __geo_interface__. The PyShp module is available on PyPI.

Let's repeat the previous OGR example with PyShp:

>>> import shapefile
>>> shp = shapefile.Reader("point")
>>> for feature in shp.shapeRecords():
...     point = feature.shape.points[0]
...     rec = feature.record[0]
...     print point[0], point[1], rec
...
1.0 1.0 First
3.0 1.0 Second
4.0 3.0 Third
2.0 2.0 Fourth
0.0 0.0 Appended

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.