删除重复的几何图形 [英] Removing Duplicate Geometries

查看:193
本文介绍了删除重复的几何图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个格式为python的多边形列表。
从该列表中,我只想提取唯一的多边形,删除重复项。



如何以更快的方式执行此操作? (我的列表包含数千个多边形)

  from shapely.geometry import Polygon 

lists = [[ (1,1),(2,2),(3,3),(4,4)],[(6,6),(7,7),(8,8),(9,9)] ,[(1,1),(2,2),(3,3),(4,4)]]
polys = [列表中项目的多边形(项目)] ##给出条件

用于poly中的多元化:

test = [p中的poly(poly)]多边形中的##]返回true或false
print test


[真,假,真]
[假,真,假]
[真,假,真]
pre>

预期结果是:
$ b $ pre $ [[(1, 1),(2,2),(3,3),(4,4)],[(6,6),(7,7),(8,8),(9,9)]]


解决方案

您可以创建一个存储唯一多边形的列表,然后对于列表中的每个多边形,循环存储在外部列表中的多边形,并且如果它们中没有一个与新列表相交,则将其添加到列表中,您可以使用 any() 函数。



示例 -

  from shapely.geometry import Polygon 

lists = [[(1,1),(2,2),(3 ,3),(4,4)],[(6,6),(7,7),(8,8),(9,9)],[(1,1),(2,2), (3,3),(4,4)]]
polys = [列表中项目的多边形(项目)] ##给出条件
uniqpolies = []
polys:

(如果没有的话)(p。intersects(poly)for p in uniqpolies):
uniqpolies.append(poly)

文档

a> -


如果iterable的任何元素为真,则返回 True 。如果迭代为空,则返回 False



I have one list of polygons in the format of shapely python. From that list I wan to extract only unique polygons removing the duplicates.

How to do it in a faster way? (My list contains thousands of polygons)

from shapely.geometry import Polygon

lists = [[(1,1),(2,2),(3,3),(4,4)], [(6,6),(7,7),(8,8),(9,9)], [(1,1),(2,2),(3,3),(4,4)]]
polys = [Polygon(item) for item in lists] ##This is given condition

for poly in polys:

    test = [p.intersects(poly) for p in polys] ##Return true or false
    print test


[True, False, True]
[False, True, False]
[True, False, True]

The expected result is:

[[(1,1),(2,2),(3,3),(4,4)], [(6,6),(7,7),(8,8),(9,9)]]

解决方案

You can create a list that stores the unique polygons , and then for each polygon in your list, loop over the polygons stored in the outer list, and if none of them intersect the new one, add this to the list , you can use any() function for that.

Example -

from shapely.geometry import Polygon

lists = [[(1,1),(2,2),(3,3),(4,4)], [(6,6),(7,7),(8,8),(9,9)], [(1,1),(2,2),(3,3),(4,4)]]
polys = [Polygon(item) for item in lists] ##This is given condition
uniqpolies = []
for poly in polys:

    if not any(p.intersects(poly) for p in uniqpolies):
        uniqpolies.append(poly)

From documentation -

Return True if any element of the iterable is true. If the iterable is empty, return False.

这篇关于删除重复的几何图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆