5

I am trying to create a Multipatch Shapefile in the shape of a cube. I am using pyshp library and could create one face as a 3D Polygon as described in the wiki of pyshp (Creating 3D Polygons). However, I am not able to create a multipatch geometry, probably because I do not use the right order of coordinates or something like that. Here is my Code using the coordinate order described by esri (Link, doc Page 35):

w = shapefile.Writer(shapeType=shapefile.MULTIPATCH)
w.poly(parts=[[[0,0,0] , [0,0,1] , [0,1,1] , [0,0,0]] , [[0,0,0] , [1,0,0] , [1,1,0] , [0,0,0]],
        [[0,1,0] , [0,1,1] , [0,0,0] , [0,1,0]] , [[0,0,0] , [0,1,1] , [0,0,1] ,[0,0,0]],
        [[1,1,0] , [0,1,1] , [0,1,0] ,[1,1,0]], [[1,1,0] , [1,1,1] , [0,1,1]] ,
        [[1,0,0] , [1,1,1] , [1,1,0] ,[1,0,0]], [[1,0,0] , [1,0,1] , [1,1,1]] ,
        [[0,0,0] , [0,0,1] , [1,0,0] ,[0,0,0]], [[1,0,0] , [0,0,1] , [1,0,1]] ,
        [[0,0,1] , [0,1,1] , [1,1,1] ,[0,0,1]], [[0,0,1] , [1,1,1] , [1,0,1]]], shapeType=31)
w.field("NAME")
w.record("PolyZTest")
w.save("shapefiles/test/MyPolyS")

What am I doing wrong? Is the usage of poly() wrong?

1 Answer 1

4

You're close - just a few minor issues.

Multipatch shapefiles need a specialized type for each part which can be:

VALUE  PART TYPE
0      Triangle Strip
1      Triangle Fan
2      Outer Ring
3      Inner Ring
4      First Ring
5      Ring

In pyshp, this is defined in your parts array using the array "partTypes"

All polygons must move in clockwise order which I didn't double-check in your example. I created my own coordinates to be sure and used the rest of your code verbatim to create a working cube:

import shapefile

w = shapefile.Writer(shapeType=shapefile.MULTIPATCH)
w.poly(parts=[
[[0,0,0], [0,1,0], [0,1,1], [0,0,1], [0,0,0]],
[[0,0,0], [0,0,1], [1,0,1], [1,0,0], [0,0,0]],
[[1,1,0], [1,1,1], [0,1,1], [0,1,0], [1,1,0]],
[[1,0,0], [1,0,1], [1,1,1], [1,1,0], [1,0,0]],
[[0,0,1], [0,1,1], [1,1,1], [1,0,1], [0,0,1]],
[[0,0,0], [0,1,0], [1,1,0], [1,0,0], [0,0,0]]
], 
        partTypes=[5,5,5,5,5,5],
        shapeType=31)
w.field("NAME")
w.record("PolyZTest")
w.save("MyPolyS")

Here is what the above output looks like in Esri ArcScence:

enter image description here

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.