I'm trying to work with the shapefile on python, the file " donnees.shp" contains 3d points I need to extract attributes from this file but my code returns an error:

>>> import shapefile   
>>> r = shapefile.Reader("donnees.shp") 
>>> r.shapes()[0].shapeType 
... 1  
>>> r.shapes()[0].points    
...[[841001.0, 6399999.0]]
>>> r.shapes()[0].z

... Traceback (most recent call last):
File "", line 1, in 
AttributeError: _Shape instance has no attribute 'z'

what is the nature of this error? what am I missing?

  • That shape has no z value. I would think that the library you're using would have a different method to access it if it is there. What library are yo using?
    – nagytech
    Commented Aug 9, 2012 at 12:54
  • I'm using the shapefile library : pyshp.googlecode.com/svn/trunk/shapefile.py
    – A.H
    Commented Aug 9, 2012 at 13:18
  • 1
    Given that the POINTZ type's code is 11, and the code you're receiving is 1 or POINT, I would anticipate there is a problem with the shapefile. I just created a shapefile with an explicit set of Z values and had no problems accessing them with the script provided.
    – nagytech
    Commented Aug 9, 2012 at 14:56
  • Ok thant you for you answer ... I must apply the script on a 3d shapefile (shapefiles that have a z component.) to be sure that the problem provides from "donnees.shp" ... Now, do you have an example or do you know some sources where I can find that 3d shapefile? thanks
    – A.H
    Commented Aug 10, 2012 at 7:25
  • realy thank you for your help, you're right, there was a problem with the shapefile, I created a new file with z-values and it runs now !
    – user9503
    Commented Aug 13, 2012 at 10:32

1 Answer 1


The method you're using to access the values is correct according to the developer's wiki and the tests I've recently done:

import shapefile
r = shapefile.Reader("MyPolyZ")
[[-89.0, 33.0], [-90.0, 31.0], [-91.0, 30.0]]
[12, 11, 12]

To create a 'Z' enabled shapefile, just specify that you want Z values during the creation process:

enter image description here

enter image description here

Please be aware of the following procedures for editing Z values in your test cases.

  1. Edit mode
  2. Select and right click the feature to edit
  3. Select 'Edit Verticies'
  4. Click the 'Sketch Properties' button
  5. Modify the value in the Z column
  6. Save an exit edit mode

You can also use steps 1-3 above to determine if your shapefile actually has 'Z' values or not.

Once you've done that, make sure you're opening the correct shapefile with shapefile.Reader(). If in doubt, use an absolute, rather than relative, path.

(FYI, I was also able to get 'M' values to work with this process as well.

Your Answer

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

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