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.
6 Answers
The pyshp library should be good.
4 Comments
pip install pyshpparts 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.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
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)GDAL includes the OGR library which supports shapefile I/O. However, the installation process for this package in Windows is not very straightforward.
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
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
The problem with the shapefile library is that the package not abled to access the details in the file