python shapely: retrieve the x,y,z value of a LinearRing
Question: I`m trying to plot a LinearRing that shows the difference of the crossover of
two Polygons:

    
    
    import mpl_toolkits.mplot3d as a3
    import matplotlib.pyplot as plt
    from shapely.geometry import Polygon
    fig = plt.figure()
    ax = Axes3D(fig)
    
    poly1 = Polygon([(220.0, 780, 500), (840, 780, 500), (840, 180, 500), (220.0, 180, 500)])
    poly2 = Polygon ([(320.0, 380, 500), (740, 380, 500), (740, 180, 500), (320.0, 180, 500)])
    
    dif = poly1.difference(poly2) 
    

I`d like to plot dif, however, when using:

    
    
    top1 = a3.art3d.Poly3DCollection([dif],alpha=0.6) 
    

I get an erros saying "TypeError: 'Polygon' object is not iterable"

I therefore try to get the x,y,z coordinates of dif and plot them, but I`ve
only managed to get the x,y ones. For the sake of testing, I currently feed-in
the Z value manualy:

    
    
    z= [500,500,500,500,500,500,500,500] 
    x,y = a.exterior.xy
    
    zipped = list(zip (x,y,z))
    top1 = a3.art3d.Poly3DCollection([zipped],alpha=0.6)   
    top1.set_color('wheat')
    top1.set_edgecolor('k')        
    ax.add_collection3d(top1)
    
    ax.set_xlim(0, 1000)
    ax.set_ylim(0, 1000)
    ax.set_zlim(0, 1000)
    plt.show()    
    

I then get the plot I am after, but I`m looking for an easier way to plot dif.


Answer: With the `exterior` attribute you are using, you can get the coords:

    
    
    top1 = a3.art3d.Poly3DCollection([dif.exterior.coords],alpha=0.6)
    

Beware, with this code and also with your solution, you are loosing the
interior rings of the polygon, if there are any.

Notice that `coords` returns an iterable, if you want a list you must create
it (`list(dif.exterior.coords)`).

For a polygon with interior rings, you could handle it as in this example:

    
    
    poly = Point(0,0).buffer(500)
    poly = Polygon([ (x, y, 500) for x, y in poly.exterior.coords ])
    spoly = Point(0,0).buffer(200)
    spoly = Polygon([ (x, y, 500) for x, y in spoly.exterior.coords ])
    poly = poly.difference(spoly)
    
    all_coords = [p.coords for p in poly.interiors]
    all_coords.append(poly.exterior.coords)
    top1 = a3.art3d.Poly3DCollection(all_coords,alpha=0.6)
    

IMHO, using shapely with 3D polygons is misleading, since shapely only handles
2D polygons, and will bring you problems if you spread the 3D part all over
the code that uses Shapely. Besides, someone reading the code could think you
are actually doing 3D math when you are not. Perhaps you can isolate all 2D
computation with shapely, and after that add it the 3D part.

