(重新)使用spatialindex库加载R Tree

时间:2012-11-06 14:36:15

标签: c++ r-tree libspatialindex

我使用spatialindex(http://libspatialindex.github.com/)库批量加载R Tree:

string baseName = "streets";
size_t capacity = 10 * 1024 * 1024;
bool bWriteThrough = false;
indexIdentifier = 0;

IStorageManager *disk = StorageManager::createNewDiskStorageManager(baseName, 512);
fileInMem = StorageManager
   ::createNewRandomEvictionsBuffer(*disk, capacity, bWriteThrough);

// bulkLoads my tree
bulkLoadRTree();

cout << "tree info:" << endl;
cout << *tree << endl;

delete disk;

以下是有关构建树的信息输出:

    Dimension: 2 
    Fill factor: 0.7 
    Index capacity: 100 
    Leaf capacity: 100 
    Tight MBRs: enabled 
    Near minimum overlap factor: 32 
    Reinsert factor: 0.3 
    Split distribution factor: 0.4 
    Utilization: 69% 
    Reads: 1 
    Writes: 35980 
    Hits: 0 
    Misses: 0 
    Tree height: 4 
    Number of data: 2482376 
    Number of nodes: 35979 
    Level 0 pages: 35463 
    Level 1 pages: 507 
    Level 2 pages: 8 
    Level 3 pages: 1 
    Splits: 0 
    Adjustments: 0 
    Query results: 0 

现在我正在尝试加载我保存在磁盘中的内容:

IStorageManager *ldisk = StorageManager::loadDiskStorageManager(baseName);
SpatialIndex::StorageManager::IBuffer* fileLoadBuffer = StorageManager
    ::createNewRandomEvictionsBuffer(*ldisk, capacity, bWriteThrough);

id_type id = 1;
tree = RTree::loadRTree(*fileLoadBuffer, id);
cout << *tree << endl;

并且树只有一个节点(树的输出是:)

    Dimension: 2
    Fill factor: 0.7
    Index capacity: 100
    Leaf capacity: 100
    Tight MBRs: enabled
    Near minimum overlap factor: 32
    Reinsert factor: 0.3
    Split distribution factor: 0.4
    Utilization: 0%
    Reads: 0
    Writes: 0
    Hits: 0
    Misses: 0
    Tree height: 1
    Number of data: 0
    Number of nodes: 1
    Level 0 pages: 1
    Splits: 0
    Adjustments: 0
    Query results: 0

我做错了什么?为什么我不从磁盘加载整个树?

2 个答案:

答案 0 :(得分:1)

您是否可能同步您对光盘的更改?

另外,通常会在磁盘上实现树,而在第一次访问时完全读取它。所以在这一点上,它无法报告准确的统计数据。

或者您的bulkLoadRTree不使用fileInMem

答案 1 :(得分:0)

必须删除fileInMem,以便将页面进一步发送回磁盘并进一步发送回delete *磁盘。需要在删除磁盘之前添加此行:

delete fileInMem