2 回答

TA貢獻(xiàn)1831條經(jīng)驗(yàn) 獲得超9個(gè)贊
我不知道你的具體要求,但最快獲得一般結(jié)果應(yīng)該是這樣的:
width = int(shape.bounds[2] - shape.bounds[0])
height = int(shape.bounds[3] - shape.bounds[1])
points = MultiPoint( [(x,y) for x in range(width) for y in range(height)] )
zeroes = points.difference( shape )
ones = points.intersection( shape )

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊
這可以回答我的問(wèn)題,但我想知道是否有更快的方法。
data = []
width = int(shape.bounds[2] - shape.bounds[0])
height = int(shape.bounds[3] - shape.bounds[1])
for y in range(0,height):
row = []
for x in range(0,width):
val = 1 if shape.convex_hull.contains(Point(x,y)) else 0
row.append(val)
data.append(row)
添加回答
舉報(bào)