The shapefile specification allows for three types of 3-dimensional shapefiles:
PointZ - a 3D point shapefile, PolylineZ - a 3D line shapefile, and PolygonZ - a 3D polygon shapefile.
The most important thing to remember is to explicitly set the shape type of each record to the correct shape type or it will default to a 2-dimensional shape. Eventually the library will automatically detect the elevation type.
Here is a brief example of creating a PolygonZ shapefile:
import shapefile w = shapefile.Writer(shapeType=shapefile.POLYGONZ) # OR you can type # w = shapefile.Writer(shapeType=15) w.poly([[[-89.0, 33, 12], [-90, 31, 11], [-91, 30, 12]]], shapeType=15) w.field("NAME") w.record("PolyZTest") w.save("MyPolyZ")
When you read 3D shapefiles the elevation values will be stored separately:
>>>import shapefile >>>r = shapefile.Reader("MyPolyZ") >>>r.shapes().points [[-89.0, 33.0], [-90.0, 31.0], [-91.0, 30.0]] >>>r.shapes().z [12, 11, 12]
So remember: explicitly set the shapetype for each shape you add to ensure the z values are maintained. And know that the z values are stored in the "z" property of each shape instead of being integrated with the x,y value lists.