地理丹斯的方式去除儿童几何形状
我有一个巨大的形状多边形对象列表,其中有很多可能的几何形状,它们可能会落在彼此之间。
我正在尝试找到仅保留父/包含形状的最有效方法,并且需要删除任何子形状。
我尝试过的方法是:
方法 1:采用 n 方方法查找任何多边形是否约束在任何其他多边形中,它是从列表中删除的候选者。但考虑到我有 600 万个形状,这是非常糟糕的性能。
方法2:创建所有多边形中心的空间树(KDE树或球树),然后为每个多边形的中心找到大约5000个最近的多边形,并检查它们中是否有任何一个落在该中心的多边形中,如果有则将其标记为孩子。对所有多边形执行此操作,然后删除所有子多边形。这种方法有效,但对我来说似乎不太干净,而且数字 5000 是硬编码的,假设没有多边形具有超过 5000 个子多边形(实际上就是这种情况)。但我对这个低于标准的代码并不满意。
向所有 GeoPandas 人员提问:
问:一定有更好的方法通过进行某种空间连接并轻松找到所有子多边形来删除子多边形。请分享一些例子。
I have huge list shapely polygon objects, which has lots of possible geometries, which might fall between each other.
I am trying to find most efficient way of keeping only parent/containing shapes and need to get rid of any child shapes.
The ways, which I have tried are:
Approach 1: Do n-square way of finding if any polygon is contrained in any other polygon, it is candidate for deleting from the list. But this is very bad performance given I have 6 million shapes.
Approach 2: Create a spatial tree(KDE tree or ball tree) of all the polygon centers and then find maybe 5000 nearest polygon for each polygon's center and check if any of them fall in the center's polygon, if any mark it as child. Do this for all the polygons and later drop all the child polygons. This approach works, but it seems not clean to me and also, number 5000 is hard coded assuming no polygon have more than 5000 child polygons(which practically is the case). but I am not satisfied with this sub-par code.
Quations to all the GeoPandas people:
Q: There must be a better way drop children polygons by doing some sort of spatial join and finding all the child polygons easily. Please share some examples.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的环境中有 pygeos 并且所有内容都是最新的,您可以使用带有
contains_properly
谓词的空间索引来完全过滤其他几何图形中的几何图形。请参阅玩具示例:结果为您提供所有父母和所有孩子的整数索引。不返回不是父/子的几何图形。
Assuming you have pygeos in your environment and everything up to date, you can use spatial index with
contains_properly
predicate to filter geometries fully within other geometries. See the toy example:The result gives you integer indices for all parents and all children. Geometries that are not parent/children are not returned.