Pickling Rtree does not appear straightforward as it is a ctypes wrapper. This comment on SO seconds that assumption.
But, in a (much) older @sgillies post (the author of this lib), in the comments section, he suggests that it is indeed doable.
Yet, when I recreate these steps locally, the results suggest otherwise:
>>> 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)))
# []
Question: Is there an operation I am failing to perform correctly to enable pickling of the spatial index? If spatial indexing is possible, what would be the correct way to go about it?
Anecdotally, I was able to pass a GeoPandas.GeoDataFrame.sindex successfully through a pickling process (pickling performed by Dask.distributed). I'm aware it uses cloudpickle or pickle (dep. on situation) but from the GeoPandas side, sindex
's SpatialIndex
class seems to simply be a wrapper around rtree.index.Index
. I have yet to more deeply dive into understanding why this was the case, but wanted to check here first to see if others had insight.