Saturday, June 6, 2015

How to fix pyshp error reading shapefile

I had a Shapefile I was trying to read using the great pyshp library but it kept shooting out and Invalid Argument Error.

After some web searching it came down to pyshp being very picky about the Shapefile format.  The true cause I still do not know what was wrong.  My Shapefile was created using QGIS, has valid geometries and no problems identifiable in ArcGIS or QGIS.   Due to other experiences using pyshp sometimes if a field value is NULL or empty it causes some error.

The solution:

ogr2ogr  new_shapefile.shp original.shp

the new_shapefile.shp  will work using the pyshp   ShapeRecords()  function.

Possible other problems that pyshp sometimes encounters:

  1. NULL value in field
  2. '' empty in field
  3. .dbf encoding  (Latin1, UTF-8)
Anyway if you know of a cause please let me know.


No comments:

Post a Comment