如何在R树中获取边界

-1 投票
2 回答
707 浏览
提问于 2025-04-18 04:45

我有一个叫做 rtree 的东西,它里面包含了一些点,也就是说,左边的值等于右边的值,顶部的值等于底部的值:

...
idx = index.Index()
....
*print list(idx.nearest((rand_point[0], rand_point[1], rand_point[0], rand_point[1])))
...
left, bottom, right, top = (newpoint[0], newpoint[1], newpoint[0], newpoint[1])
idx.insert(i, (left, bottom, right, top))
...

在这些点的地方,其实有一些很长的代码,这段代码定义了'point'、'newpoint'、'i',还有其他在循环中的内容。标记为 * 的那一行返回的结果大概是这样的:

[0L]
[0L]
[2L]
[2L]
[1L]
[4L]
[6L]
[5L].....

问题是,如何根据这个输出得到一个点,也就是 (左边, 底部, 右边, 顶部) 的值呢?

2 个回答

0

我找到了一个解决办法:

    nearest_gen = idx.nearest((rand[0], rand[1], rand[0], rand[1]), objects=True)
    nearest_list = list(idx.nearest((rand[0], rand[1], rand[0], rand[1])))
    for j in nearest_gen:
        if j.id == nearest_list[0]:
            j.object
            print ['%.10f' % t for t in j.bbox]
0

使用

idx.nearest(.... objects="raw")

或者

idx.nearest(.... objects=True)

如果你想要的是实际的对象,而不仅仅是它们的ID。

撰写回答