Masthead

Shapefile.py

Introduction

Shapefile.py is an Open Source module for reading and writing Esri-format shapefiles. Shapefile.py is interesting both because it is very easy to use and an example of how to read and write binary files with Python.

Getting Shapefile.py has become a bit complicated:

  1. If you search for "shapefile.py", you'll probably end up at the GitHub repository for Shapefile.py
  2. If you end up on the "Code" page, you can actually copy and paste the code into a file and save it as "shapefile.py".
  3. You can also click on "pyshp" in the "GeospatialPython/pyshp" link and then click on "Clone or download"
  4. If you select "Download ZIP" you'll obtain a zip file that includes "shapefile.py", some documentation, and some samples.
  5. Note that the "pyshp" web page contains the documentation to get started with shapefile.py.

Shapefile.py is much easier to use than the "cursors" provided by ArcGIS but Shapefile.py does not provide the ability to filter shapefiles by attributes. There is minimal documentation available for Shapefile.py but a good tutorial is available under "Additional Resources" below.

Shapefile.py is also interesting because it is a Python-only, single-file, library. You can just download it and put it in the same folder as your Python scripts to execute it.

Additional Resources

shapefile.py

 

© Copyright 2018 HSU - All rights reserved.