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.
-
1Future questions of this sort might benefit from the [GIS Stack Exchange](http://gis.stackexchange.com/). – Brad Koch Jul 31 '13 at 18:40
-
Or on http://softwarerecs.stackexchange.com/ – Mawg says reinstate Monica Sep 21 '16 at 12:12
6 Answers
The pyshp library should be good.

- 1,448
- 15
- 24

- 126,773
- 69
- 172
- 181
-
Am I just supposed to download the shapefile.py ? How do I install this package using pip? – Zameer Manji Dec 05 '10 at 06:01
-
1
-
1FYI, polygons with holes [are not supported](https://code.google.com/p/pyshp/issues/detail?id=32). Don't use this library if you'll need any more than basic polygon support. – Brad Koch Jul 31 '13 at 21:04
-
2@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. – Jim Pivarski Oct 21 '14 at 18:55
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.

- 89
- 1
-
1-1, I'd install it from the package index instead of copying the source files manually. – Brad Koch Jul 31 '13 at 20:07
-
2..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." – elrobis Mar 10 '16 at 17:38
-
1I 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) – Mawg says reinstate Monica Sep 21 '16 at 12:15
GDAL includes the OGR library which supports shapefile I/O. However, the installation process for this package in Windows is not very straightforward.

- 1
- 1

- 3,168
- 1
- 21
- 19
-
If you have Anaconda: `conda install gdal`. If not go to [conda.io](https://conda.io/miniconda.html) and get. It's the missing package manager for Windows (also works on Mac/Linux/Power8). – hobs Oct 01 '18 at 16:51
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.
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/

- 19,267
- 19
- 110
- 137

- 143
- 1
- 2
- 8
The problem with the shapefile library is that the package not abled to access the details in the file

- 1
- 1
-
This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/33405041) – Simas Joneliunas Dec 17 '22 at 06:26