20

Are there any libraries that I can use to read a shp/shx/dbf/sbx set of files? I mainly need to extract some polygons but something that lets me extract any data that I want would be awesome.

2

6 Answers 6

30

The pyshp library should be good.

Sign up to request clarification or add additional context in comments.

4 Comments

Am I just supposed to download the shapefile.py ? How do I install this package using pip?
Via pip: pip install pyshp
FYI, polygons with holes are not supported. Don't use this library if you'll need any more than basic polygon support.
@BradKock: Either this has changed or you missed the parts member of the _Shape class. It tells you at which index each polygon begins. You have to use these indexes to splice the points by hand, which is not ideal, but it's doable--- the information isn't lost.
8

To use the Python Shapefile Library download shapefile.py: http://code.google.com/p/pyshp/source/browse/trunk/shapefile.py

Place it in your working directory or in your Python site-packages directory and you are ready to go.

Just type "import shapefile" in your interpreter or python script and follow usage examples and documentation at the PyShp project on Google Code.

3 Comments

-1, I'd install it from the package index instead of copying the source files manually.
..the developer of the library in question was downvoted for his advice on including and importing said library in one's Python environment. As for me, +1 because "This answer is useful."
I had major problems trying to install on Windows. In the end, I copied the single file shapefile.py to the same direcotry as my Python script and all was well. You should install - if you can - but copying works (as a last resort)
6

GDAL includes the OGR library which supports shapefile I/O. However, the installation process for this package in Windows is not very straightforward.

1 Comment

If you have Anaconda: conda install gdal. If not go to conda.io and get. It's the missing package manager for Windows (also works on Mac/Linux/Power8).
6

Also PySAL could be of some help. Reads shape files:

import pysal
shp = pysal.open('YOUR_FILE.shp')

And plenty of others geo related formats.

Comments

3

Shapelib is also a good choice; it has c, c++, c# and python interface: http://shapelib.maptools.org/

and pyshapelib here: http://ftp.intevation.de/users/bh/pyshapelib/

Comments

0

The problem with the shapefile library is that the package not abled to access the details in the file

1 Comment

This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.