I am not sure if I have discovered a regression, or if I have not enough sleep. While I manage to create shapefiles with point geometries with pyshp, line and polygon features don't show up in QGIS. In ArcMap, however, they show up as expected.

Steps to reproduce

  1. Get pyshp (version 1.1.7)
  2. Execute one or both of these example scripts, taken directly from the pyshp documentation:


    import shapefile
    w = shapefile.Writer(shapefile.POLYGON)


    import shapefile
    w = shapefile.Writer(shapefile.POLYLINE)
    w.record(FIRST_FLD='First', SECOND_FLD='Line')
  3. Open the resulting shapefile in an empty QGIS session (tested in 1.7.3, 1.8.0 and 1.9.0 Alpha)

Expected result
A polygon or a line in the map window (at least after a "zoom to layer extent").

What I get
An empty map.

Did I miss something?


After contacting the package author, version 1.1.9 was mentioned on the homepage. After an upgrade, the issue vanished. That's good customer support!

1 Answer 1


I don't use pyshp since if you have OGR/GDAL and Shapely there's no need for it. However, I was curious so I repeated your test (refering to the documentation to be sure of the syntax - I was worried because the polygon was not closed, but that is what the author specifies on the website exactly as you have it). I got the same result as you. I don't think that it is QGIS because I ran ogrinfo on the test polygon and I get the following result:

Layer name: polygon
Geometry: Polygon
Feature Count: 1
Extent: (1.000000, 1.000000) - (5.000000, 5.000000)
Layer SRS WKT:
FIRST_FLD: String (40.0)
SECOND_FLD: String (40.0)
ERROR 1: Corrupted .shp file : shape 0 : panPartStart[0] = 6, nVertices = 6
  FIRST_FLD (String) = First
  SECOND_FLD (String) = Polygon

Note the error! Pyshp appears to create corrupt polygons, which is why you can't see anything. Please note that not all implementations of the shapefile specification are correct. I'd dispense with pyshp in favour of OGR/GDAL.

I took the next logical step and closed the polygon by repeating the first vertex as the last, but that didn't help. Ogr still reports it as corrupt. I'm just going to stick with OGR/GDAL and Shapely!

  • Thanks for reproducing the issue and the diagnostics. I opened an issue on the project's homepage: code.google.com/p/pyshp/issues/detail?id=56
    – ojdo
    Aug 8, 2013 at 15:06
  • 1
    and got an answer within 30 minutes: version 1.1.9 (now mentioned on the project homepage) fixes this issue already!
    – ojdo
    Aug 8, 2013 at 15:31
  • 1
    Impressive :) It's good they've updated the home page! Aug 8, 2013 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.