【发布时间】:2017-02-18 10:03:25
【问题描述】:
我正在尝试根据它们接触的条件创建多边形区域。在我的示例中,我有一个示例数据集,其中包含需要组合在一起的 382 个多边形(但完整的数据集包含 6355 个多边形)。 (我会展示一张图片,但我没有足够的声誉来做到这一点..)
我虽然想做这种蛮力,但当然这需要很长时间,而且不是很理想。
def groupBuildings(blds):
# blds is a list with shapely polygons
groups = []
for bld in blds:
group = []
group.append(bld)
for other in blds:
for any in group:
if any != other and any.intersects(other):
group.append(other)
groups.append(group)
return groups
我了解了区域增长并认为这是一个可能的解决方案,但性能仍然很糟糕。我通过以下方式实现了这一点:
def groupBuildings(blds):
# blds is a list with shapely polygons
others = blds
groups = []
while blds != []:
done = []
group = []
first = blds.pop(0)
done.append(first)
group.append(first)
for other in others:
if (other in blds) and first.touches(other):
group.append(other)
blds.remove(other)
return groups
但我认为这里的问题是我没有任何最近的邻居,所以我仍然必须对每个建筑物进行两次迭代。
所以我的问题是:最近的邻居对区域增长至关重要吗?还是有其他有效的方法?
【问题讨论】:
标签: python polygon region shapely