def PolygonToXYZ(poly, elev=0.0):
   """Converts Polygons to list of coordinate tuples (x,y,z).

   Parameters:
   poly: shapely.Polygon
   elev: float
      Optional z level.

   Returns:
   List of polygon border coordinate tuples.
   """
   print("Converting polygon to points:")
   points = []
   # Exterior points
   x, y = poly.exterior.xy
   for p in range(1,len(x)): # Ignore first (or last) coordinate pair as it is repeated
      points.append((x[p],y[p],elev))
   print("...found",len(x),"exterior points.")
   # Interior points
   nbi = len(poly.interiors)
   print("...found", nbi, "islands.")
   for i in range(0,nbi):
      x, y = poly.interiors[i].xy
      for p in range(1,len(x)): # Ignore first (or last) coordinate pair as it is repeated
         points.append((x[p],y[p],elev))
   print("...found a total of",len(points),"shoreline points.")
   return points