是否可以酸洗 Rtree 空间索引?

kua*_*anb 6 python pickle r-tree

Pickling Rtree 看起来并不简单,因为它是一个 ctypes 包装器。这个评论秒了这个假设。

但是,在(更)旧的@sgillies帖子(这个库的作者)的评论部分,他建议这确实是可行的。

然而,当我在本地重新创建这些步骤时,结果表明并非如此:

>>> idx = rtree.index.Index()
>>> idx.insert(10, (1,2,3,4))
>>> list(idx.intersection((0,0,5,5)))
# [10]
>>> f = open('foo.p', 'wb')
>>> pickle.dump(idx, f)
>>> a = pickle.load( open( "foo.p", "rb" ) )
>>> a.get_bounds()
# [1.7976931348623157e+308, 1.7976931348623157e+308, -1.7976931348623157e+308, -1.7976931348623157e+308]]
>>> list(a.intersection((0,0,5,5)))
# []
Run Code Online (Sandbox Code Playgroud)

问题:是否存在我未能正确执行以启用空间索引酸洗的操作?如果空间索引是可能的,那么正确的方法是什么?

有趣的是,我能够通过酸洗过程(由 Dask.distributed 执行的酸洗)成功传递 GeoPandas.GeoDataFrame.sindex。我知道它使用 cloudpickle 或 pickle(视情况而定),但从 GeoPandas 方面来看,sindexSpatialIndex似乎只是rtree.index.Index. 我还没有更深入地了解为什么会这样,但想先在这里检查一下,看看其他人是否有洞察力。

use*_*842 0

看起来您可以将索引写入文件,因此应该可以将其存储为字符串:https://gis.stackexchange.com/questions/254781/ saving-python-rtree-spatial-index-to-文件/254785

您也可以尝试 Dill,我相信它能够“pickling”更多种类的对象,或者至少保存解释器的状态: https: //pypi.python.org/pypi/dill