从一组点我使用scipy构建了 Voronoi 镶嵌:
from scipy.spatial import Voronoi
vor = Voronoi(points)
现在我想从 Voronoi 算法创建的区域中构建一个Shapely 多边形。问题是 Polygon 类需要一个逆时针顶点列表。虽然我知道如何对这些顶点进行排序,但我无法解决问题,因为通常这是我的结果:
(重叠多边形)。这是代码(一个随机示例):
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])
我怎么解决这个问题?