首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shapely STRtree太慢了吗?

Shapely STRtree太慢了吗?
EN

Stack Overflow用户
提问于 2020-04-04 16:03:40
回答 1查看 480关注 0票数 0

我需要将几十万个节点映射到它们最近的邻居,作为几万个其他节点的集合。当然,我会使用空间索引来加速这个过程。我以前通过生成较小节点集的Voronoi镶嵌,并使用MySQL空间查询来确定第一个集的哪些节点落入与第二个集的节点相关联的区域中,从而能够非常快速地做到这一点。它能够在短短几分钟内运行。从那以后,我离开了MySQL环境,想用python完成整个过程。我转向shapely包提供的流行的STRtree空间索引。然而,我发现这个索引非常慢。我尝试使用具有节点集的最近几何查询以及具有Voronoi区域的几何相交查询,但仅获得每秒51.787个匹配节点的速度,这将需要大约4.5h来运行我处理的每组节点。为什么shapely这么慢?还是我用错了?

以下是一些代码片段:

代码语言:javascript
复制
class Network:

    ...

    def load_network(self, planspath):
        log.info('Fetching temperatures.')
        temperatures = self.fetch_temperatures()
        log.info('Fetching centroids.')
        centroids = self.fetch_centroids()
        log.info('Fetching links.')
        links = self.fetch_links()

        Centroid.steps = len(next(iter(temperatures.values())))

        log.info('Building spatial index (strtree) from centroids.')
        points = []
        for centroid in centroids.values():
            uuid = centroid[0]
            self.centroids[uuid] = Centroid(temperatures[centroid[1]])
            point = loads(centroid[2])
            setattr(point, 'id', uuid)
            points.append(point)
        tree = STRtree(points)

        log.info('Mapping links to centroids.')
        for link in links:
            node = loads(link[4])
            point = tree.nearest(node)
            self.links[link[0]] = Link(link[1], link[2], self.centroids[point.id])

        log.info('Loading network routes from output plans file.')
        self.routes = self.fetch_routes(planspath)
EN

回答 1

Stack Overflow用户

发布于 2021-03-02 10:13:23

糟糕的性能是Shapely中的一个bug造成的。已提交修复程序,并将在下一个版本中提供。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61025297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档