PyShp
PyShp
is a simple, pure Python library that reads and writes shapefiles. It doesn’t perform 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 through conda
as pyshp
.
Let’s repeat the previous OGR example with PyShp
:
import shapefile shp = shapefile.Reader("point.shp") for feature in shp.shapeRecords(): ... point = feature.shape.points[0] ... rec = feature.record[0] ... print(point[0], point[1], rec) ...
We’ll see the following attributes:
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