title: From Voronoi tessellation to Shapely polygons
body: <p>from a set of points I built the Voronoi tessellation using <a href="http://docs.scipy.org/doc/scipy-dev/reference/generated/scipy.spatial.Voronoi.html" rel="noreferrer">scipy</a>:</p>
  
  <pre><code>from scipy.spatial import Voronoi
  vor = Voronoi(points)
  </code></pre>
  
  <p>Now I would like to build a <a href="http://toblerity.org/shapely/manual.html#polygons" rel="noreferrer">Polygon in Shapely</a> from the regions the Voronoi algorithm created. The problem is that the Polygon class requires a list of counter-clockwise vertices. Although I know how to <a href="https://stackoverflow.com/questions/1709283/how-can-i-sort-a-coordinate-list-for-a-rectangle-counterclockwise">order these vertices</a>, I can't solve the problem because often this is my result:</p>
  
  <p><img src="https://i.stack.imgur.com/ljM0l.png" alt="enter image description here"></p>
  
  <p>(overlapping polygon). This is the code (ONE RANDOM EXAMPLE):</p>
  
  <pre><code>def order_vertices(l):
      mlat = sum(x[0] for x in l) / len(l)
      mlng = sum(x[1] for x in l) / len(l)
  
      # https://stackoverflow.com/questions/1709283/how-can-i-sort-a-coordinate-list-for-a-rectangle-counterclockwise
      def algo(x):
          return (math.atan2(x[0] - mlat, x[1] - mlng) + 2 * math.pi) % 2*math.pi
  
      l.sort(key=algo)
      return l
  
  a = np.asarray(order_vertices([(9.258054711746084, 45.486245994138976),
   (9.239284166975443, 45.46805963143515),
   (9.271640747003861, 45.48987234571072),
   (9.25828782103321, 45.44377372506324),
   (9.253993275176263, 45.44484395950612),
   (9.250114174032936, 45.48417979682819)]))
  plt.plot(a[:,0], a[:,1])
  </code></pre>
  
  <p>How can I solve this problem? </p>