2

Short version: is there any stable/reliable way to serialize/de-serialize a Boost.Geometry rtree ?

Longer version: The rtree implementation in Boost.Geometry has experimental support for serialization/de-serialization, but the support is unstable, it sometimes throws exceptions during de-serialization. I don't even know whether it corrupts the tree data silently.

I have implemented a simple but very slow hack: serialize all the tree nodes (instead of the tree as a whole), and rebuild the tree during de-serialization. I want something faster.

user416983
  • 974
  • 3
  • 18
  • 28

1 Answers1

0

You can use the packing-constructor which affords bulk-loading.

See http://www.boost.org/doc/libs/1_62_0/libs/geometry/doc/html/geometry/reference/spatial_indexes/boost__geometry__index__rtree/rtree_iterator__iterator_.html *

namespace  bgi  =  boost::geometry::index; 
typedef  std::pair<Box,  int>  Value; 
typedef  bgi::rtree<  Value,  bgi::linear<32>  >  RTree; 

std::vector<Value>  values; 
/*fill the values container*/ 

RTree  rt; 
rt.insert(values.begin(),  values.end()); 

If your iterators are input iterators you can avoid having a temporary copy at all (values container doesn't need to be a container).

sehe
  • 374,641
  • 47
  • 450
  • 633
  • I don't quite understand the boost introduction page. Since packing is a creation algorithm, and linear/quadratic/rstar are balancing algorithms, I should get 6 different r-trees, but the diagrams only show 4 trees. Does that mean packing can only be implemented on linearly balanced trees ? – user416983 Oct 27 '16 at 05:14
  • 2
    There is only one packing algorithm implemented at the moment. So if you create the R-tree using packing algorithm always the same structure is created no matter which balancing algorithm was picked. But when you add or remove a value to/from this R-tree then choosen balancing algorithm is used. – Adam Wulkiewicz Dec 15 '16 at 23:48
  • Hi there. I attempted this solution and I didn't get any improvement on runtime. I am using boost::geometry::model::d2 to build the boxes, may this be the issue? – gudé Aug 08 '22 at 14:24