- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 2D 点存储在 rtree(版本 0.8.2)中,然后使用 Python 删除它们。我知道 rtree 适用于矩形(或 3D 中的框),但我猜点是矩形的子集。
我从 rtree 中删除项目时出现奇怪的行为。下面的脚本显示了行为:
from rtree import index as rtindex
def pt2rect(pt):
return pt[0], pt[1], pt[0], pt[1]
pts = [(0.0, 0.0), (1.0, 1.0), (0.0, 1.0)]
rt = rtindex.Index()
# Add the points
[rt.add(0, pt2rect(pt)) for pt in pts]
print [r.bbox for r in list(rt.nearest((0, 0), 10, True))]
# Remove the same points
for pt in pts:
rt.delete(0, pt2rect(pt))
print pt2rect(pt), [r.bbox for r in list(rt.nearest((0, 0), 10, True))]
输出是:
True
[[0.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 1.0], [1.0, 1.0, 1.0, 1.0]] # Whole index
(0.0, 0.0, 0.0, 0.0) [[0.0, 1.0, 0.0, 1.0], [1.0, 1.0, 1.0, 1.0]] # <-- Ok
(1.0, 1.0, 1.0, 1.0) [[1.0, 1.0, 1.0, 1.0]] # <-- Wrong point deleted!
(0.0, 1.0, 0.0, 1.0) [[1.0, 1.0, 1.0, 1.0]] # <-- Ok, as it's not found.
来自文档(http://toblerity.org/rtree/class.html):
delete(id, coordinates) Deletes items from the index with the given 'id' within the specified coordinates.
Parameters:
id – long integer A long integer that is the identifier for this index entry. IDs need not be unique to be inserted into the index, and it is up to the user to ensure they are unique if this is a requirement.
coordinates – sequence or array Dimension * 2 coordinate pairs, representing the min and max coordinates in each dimension of the item to be deleted from the index. Their ordering will depend on the index’s interleaved data member. These are not the coordinates of a space containing the item, but those of the item itself. Together with the id parameter, they determine which item will be deleted. This may be an object that satisfies the numpy array protocol.
但是可以看出,在输出的第 4 行中删除了具有给定 id
但不在给定坐标内的点。
文档还明确指出,id
在插入或删除时不需要是唯一的。 (示例中重复的 0 == id
是故意的,因为我的应用程序需要重复的 id
。同一“事物”的多个点。)
还确认可以使用 xmin == xmax
和 ymin == ymax
对点进行索引。
我是不是使用了错误的库,或者 libspatialindex(Python rtree 背后的二进制库)的行为与 rtree 文档状态不同?
最佳答案
不要将重复的 id
分配给不同的对象。
它正在删除它在叶中找到的第一个具有匹配id
的对象(检查libspatialindex源代码,Leaf::deleteData
如果你不要相信我)。 坐标仅用于找到要从中删除的正确叶子。你所有的 id
都是 0
,所以它总是从叶子中删除第一个元素。后面的删除失败了,因为你的树的边界框现在是 [0.0,1.0,1.0,1.0]
,y=0.0 的点不能在这个叶子中。
尝试
[rt.add(id, [x[0], x[1], x[0], x[1]]) for id, x in enumerate(pts)]
和
for id, x in enumerate(pts):
rt.delete(id, [x[0], x[1], x[0], x[1]])
print [x.bbox for x in list(rt.nearest([0, 0], 10, True))]
请注意,rtree 模块的文档具有误导性。
Deletes items from the index with the given 'id' within the specified coordinates.
Parameters:
- id – long integer A long integer that is the identifier for this index entry. IDs need not be unique to be inserted into the index, and it is up to the user to ensure they are unique if this is a requirement.
- coordinates – sequence or array Dimension * 2 coordinate pairs, representing the min and max coordinates in each dimension of the item to be deleted from the index. Their ordering will depend on the index’s interleaved data member. These are not the coordinates of a space containing the item, but those of the item itself. Together with the id parameter, they determine which item will be deleted. This may be an object that satisfies the numpy array protocol.
(强调已添加。)
这不是说 id
不需要是唯一的删除。它说您可以插入具有相同 id
的多个条目,但它并没有说删除是可预测的。 ;-) “确定”也含糊不清。坐标用于找到正确的叶子,然后删除该叶子中第一个匹配的 id
。 (从 libspatialindex 的源代码来看)因此,id
必须是唯一的才能可靠地删除。
关于python - 在 Python 中从 rtree 中删除二维点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27660298/
我测试了 boost.geometry.index.rtree (boost 1.59 www.boost.org) 和 superliminal.RTree ( http://superlimina
我正在尝试在 python 中剪辑空间数据,但是当我运行我的代码时...... europe = gpd.clip(worldmap, europe_bound_gdf) ...我收到错误: ( Im
这是我的代码片段。我正在尝试为顶点类对象 RTreeVertex 创建一个 rtree 树。 class Entity { public: int num; public: Entity(in
我想完全理解 Java 上的二维 RTree,但我在解释中迷路了,我希望有人能告诉我它们是如何工作的。 我对他们的了解是这样的: 您从具有最大条目数 M 的节点列表开始,当您尝试获得更多值时,您必须拆
我正在尝试了解 RTree 算法的基础知识,并且正在尝试弄清楚它是如何执行搜索的,例如1 公里内的所有餐厅。我们会将所有对象存储在数据库中的矩形中,然后我们(可能)会根据我们当前的位置构建一个查询矩形
我需要构建一个 R树使用给定的数据点。我已经搜索了 R 树的实现。当给定矩形坐标作为输入时,我发现所有实现都构建了 r 树。当给定数据点本身时,我需要构建 r 树(它可以是一维的)。代码应该负责创建包
我很疑惑。考虑以下代码,稍微改编自 http://www.boost.org/doc/libs/1_57_0/libs/geometry/doc/html/geometry/spatial_index
我一直在尝试调试使用 Pythons RTree version 0.8.2 的软件包中的一些奇怪行为. 为了跟踪问题,我需要每隔几分钟序列化一次 RTree 实例,当问题发生时我可以得到一个非常准确
我正在关注 boost geometry rtree文档。我能够使用一个框执行空间查询,以检索与其相交的 rtree 元素列表。 我想知道是否有一种方法可以在 rtree 和另一个 rtree(相同类
我使用 OpenCv 进行图像分类。训练后我将模型保存到 *.yaml.gz。然后我将这个文件添加到嵌入式资源中。现在我需要从资源加载模型,但 OpenCv 只允许从文件或字符串加载。 HMODULE
我正在 heroku 上部署一个 GIS 应用程序。我在我的电脑上开发了它,当我部署它时,rtree 不见了。我无法通过 pip 安装它,因为 pip 安装有问题,正如 rtree 开发人员自己所说的
我正在尝试使用Rtree并面对这种奇怪的行为:INSERT语句在普通表中正常工作,但在rtree表中却失败了: 这个例子很好用: DROP TABLE IF EXISTS ltssoffsets; C
我想使用 Boost C++ 库找到在 rtree 中索引的所有元素,这些元素与带孔的多边形的外环相交但不完全在任何孔内。 我知道如何让元素与外环相交: // Constructing the ext
经过一些阅读后,我了解到层次结构遍历虽然可能在 boost rtree 中并未得到官方支持。我有几个不同的用例,我可以在没有层次结构遍历的情况下进行管理,但我不确定效率。因此,我正在寻求有关 boos
将新框插入 rtree 时,我想首先检查树中是否已经存在相同的框。如果是,我只想获取该值,否则我需要插入一个新值。执行此操作的最佳(即最有效)方法是什么? 我可以通过调用 nearest(box,1)
我正在尝试在我的一个项目中使用 boost::geometry 的 rtree DS,但我发现很难浏览文档。某些方法的文档很少,我找不到足够的例子。现在,我正在尝试构建示例程序,以便进一步构建它。 因
Pickling Rtree 看起来并不简单,因为它是一个 ctypes 包装器。 This comment在 SO 秒假设。 但是,在(很多)旧的@sgillies post (这个库的作者),在评
我在 5 维空间中有大约 10 K 个点。我们可以假设这些点随机分布在空间 (0,0,0,0,0) 和 (100,100,100,100,100) 中。显然,整个数据集可以很容易地驻留在内存中。 我想
Boost rtree 为某些与段查询的交集给出了错误的交集结果。在这种情况下,边界框是 y=0 处的 y 平面 10x10 正方形。我正在查询从 (2, 1, 0) 到 (2, 1, 10) 的 z
我有一个城市的简化 map ,其中有街道作为线串,地址作为点。我需要找到从每个点到任何街道线的最近路径。我有一个执行此操作的工作脚本,但它在多项式时间内运行,因为它嵌套了 for 循环。对于 150
我是一名优秀的程序员,十分优秀!