def randomSearch(self): meta = rTree.getMeta() if meta is None : return None rtree = rTree.RTree(None, None) # just a random example for now e = rTree.Entry(rTree.Rect([-91.09, 45.15],[-90.07, 46.16])) l = rtree.search(e) print "number of search results : ", len(l) , " " if len(l) > 0 : print l[0].I.boundingBoxMin, l[0].I.boundingBoxMax, l[0].nodeId print "Number of entries in tree: ", rTree.countEntries(rtree.root)
def post(self): showBulk = "invisible" msg = "No bulk loading to do" meta = rTree.getMeta() rtData = memcache.get("rtree") where = self.request.get('upTo') if meta is None or memcache.get("complete") is None: fn = "RTree.pickled.top" try : f = open("RTree.pickled") fn = "RTree.pickled" f.close() except : pass #fn = "CaStreet.ascii.10k" #"USclpoint.fnl" if rtData is not None : rtree = cPickle.loads(rtData) else : rtree = bulkRTree.insertFromPickle(fn) print "Now saving to database." i = 0 j = 0 howMany = 20 if where == "" : where = 0 else : where = int(where) upTo = min(len(rtree.root.entries), where+howMany) for current in range(where, upTo): #e in rtree.root.entries : e = rtree.root.entries[current] if (type(e.child) == str) : f = open("RTree.pickled."+str(current)) e.child = cPickle.load(f) f.close() decends = False for en in e.child.entries : if type(en.child) == str : decends = True f = open(en.child) en.child = cPickle.load(f) f.close() en.child = rtree.depthSaveTree(en.child) if decends : rtree.root.entries[current].child = e.child.save() else : rtree.root.entries[current].child = rtree.depthSaveTree(e.child) i+=1 memcache.delete("rtree") memcache.add("rtree", cPickle.dumps(rtree)) if (upTo == len(rtree.root.entries)): rtree.rootKey = rtree.root.save() rtree.save() msg = "RTree bulk loading completed." memcache.add("complete", "true") ec = rTree.countEntries(rtree.root) print ec else : perc = int(100.0/len(rtree.root.entries) * upTo) msg = "RTree bulk loading: "+str(perc)+" % completed... " js = {"upTo":str(upTo), "msg":msg} self.response.out.write(simplejson.dumps(js)) return else : print msg template_values = {'id': self.request.get('client_id'), 'token': self.request.get('server_token'), 'showBulk': showBulk,'message':msg} template = JINJA_ENVIRONMENT.get_template('index.html') self.response.out.write(template.render(template_values))