Ticket #320: hobu-fs.patch

File hobu-fs.patch, 4.8 kB (added by sgillies, 2 years ago)
  • rtree/wrapper.cc

    old new  
    5656 
    5757extern "C" 
    5858GISPySpatialIndex * 
    59 RtreeIndex_new(
     59RtreeIndex_new(char* filename, unsigned long nPageLength
    6060{ 
    61     return new GISPySpatialIndex; 
     61    if (!filename) 
     62        return new GISPySpatialIndex; 
     63    else 
     64    {    
     65        if (!nPageLength) nPageLength=1; 
     66        return new GISPySpatialIndex(filename, nPageLength); 
     67    } 
    6268} 
    6369 
    6470extern "C" 
     
    7480                      double *min, double *max) 
    7581{ 
    7682  /* TODO: handle possible exceptions */ 
    77   index->mRTree->insertData(0, 0, Tools::Geometry::Region(min, max, 2), id); 
     83  index->index().insertData(0, 0, Tools::Geometry::Region(min, max, 2), id); 
    7884} 
    7985 
    8086extern "C" 
     
    8894    ids = PyList_New((size_t)count); 
    8995    PyListVisitor *visitor = new PyListVisitor(ids); 
    9096    const Tools::Geometry::Region *region = new Tools::Geometry::Region(min, max, 2); 
    91      index->mRTree->intersectsWithQuery( 
     97     index->index().intersectsWithQuery( 
    9298        (*region), (*visitor) 
    9399    ); 
    94100    delete region; 
  • rtree/gispyspatialindex.cc

    old new  
    2525 
    2626using namespace SpatialIndex; 
    2727 
    28 GISPySpatialIndex::GISPySpatialIndex(
     28GISPySpatialIndex::GISPySpatialIndex(const char* pszFilename, unsigned long nPageSize
    2929{ 
    30   // for now only memory manager 
    31   mStorageManager = StorageManager::createNewMemoryStorageManager(); 
    3230 
    33   // create buffer 
     31  std::string oFilename = std::string(pszFilename); 
     32  mStorageManager = StorageManager::createNewDiskStorageManager(oFilename, nPageSize); 
    3433 
     34  Initialize(); 
     35 
     36} 
     37 
     38void GISPySpatialIndex::Initialize() 
     39{ 
    3540  unsigned int capacity = 10; 
    3641  bool writeThrough = false; 
    3742  mStorage = StorageManager::createNewRandomEvictionsBuffer(*mStorageManager, capacity, writeThrough); 
     
    4651  // create R-tree 
    4752  long indexId; 
    4853  mRTree = RTree::createNewRTree(*mStorage, fillFactor, indexCapacity, 
    49                                  leafCapacity, dimension, variant, indexId); 
     54                                 leafCapacity, dimension, variant, indexId);  
     55    
     56 
    5057} 
     58GISPySpatialIndex::GISPySpatialIndex() 
     59{ 
    5160 
     61  mStorageManager = StorageManager::createNewMemoryStorageManager(); 
     62   
     63  Initialize(); 
     64} 
     65 
    5266GISPySpatialIndex:: ~GISPySpatialIndex() 
    5367{ 
    5468  delete mRTree; 
  • rtree/wrapper.h

    old new  
    2626 
    2727typedef struct RtreeIndex_t *RtreeIndex; 
    2828 
    29 RtreeIndex RtreeIndex_new(); 
     29RtreeIndex RtreeIndex_new(char* filename, unsigned long nPagesize); 
    3030void RtreeIndex_del(RtreeIndex index); 
    3131void RtreeIndex_insertData(RtreeIndex index, long id,  
    3232        double *min, double *max); 
  • rtree/gispyspatialindex.h

    old new  
    2121*/ 
    2222 
    2323#include <Python.h> 
     24#include <string> 
    2425 
    2526namespace SpatialIndex 
    2627{ 
     
    4647 
    4748public: 
    4849  GISPySpatialIndex(); 
     50  GISPySpatialIndex(const char* pszFilename, unsigned long nPageSize); 
    4951  ~GISPySpatialIndex(); 
     52   
    5053  bool insertFeature(long id, double *min, double *max); 
    51   /*void deleteFeature(QgsFeature& f);*/ 
    5254  PyObject *intersects(double *min, double *max); 
     55  SpatialIndex::ISpatialIndex& index() {return *mRTree;} 
     56 
     57private: 
     58  void Initialize(); 
    5359  SpatialIndex::IStorageManager* mStorageManager; 
    5460  SpatialIndex::StorageManager::IBuffer* mStorage; 
    5561  SpatialIndex::ISpatialIndex* mRTree; 
  • rtree/_rtreemodule.cc

    old new  
    4242static int 
    4343Rtree_init(Rtree *self, PyObject *args, PyObject *kwds) 
    4444{ 
    45     self->index = RtreeIndex_new(); 
     45    char* filename = NULL; 
     46    unsigned long nPageLength = 0; 
     47 
     48    if (!PyArg_ParseTuple(args, "|si", &filename, (unsigned long)&nPageLength)) 
     49        return NULL; 
     50     
     51    self->index = RtreeIndex_new(filename,nPageLength); 
    4652    return 0; 
    4753} 
    4854 
  • tests/R-Tree.txt

    old new  
    1818    >>> len(hits) 
    1919    10 
    2020 
     21Instantiate indexes that are disk based 
     22 
     23    >>> index2 = Rtree("foodx",3) 
     24    >>> index3 = Rtree("foodex")