【发布时间】:2017-09-27 21:39:32
【问题描述】:
Pickling Rtree 看起来并不简单,因为它是一个 ctypes 包装器。 This comment 秒了这个假设。
但是,在一个(很多)老的@sgillies post(这个库的作者)中,在 cmets 部分,他认为这确实是可行的。
然而,当我在本地重新创建这些步骤时,结果表明并非如此:
>>> 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)))
# []
问题: 是否存在我未能正确执行的操作以启用空间索引的酸洗?如果空间索引是可能的,那么正确的方法是什么?
有趣的是,我能够通过酸洗过程(由 Dask.distributed 执行酸洗)成功传递 GeoPandas.GeoDataFrame.sindex。我知道它使用 cloudpickle 或 pickle(视情况而定),但从 GeoPandas 方面来看,sindex's SpatialIndex class 似乎只是rtree.index.Index 的包装。我还没有更深入地了解为什么会这样,但想先在这里查看其他人是否有见解。
【问题讨论】: