def test_4d_rtree(): """Testing the rtree ctypes wrapper""" tree = rtree.RTreeCreateTree(-1, 0, 4) for i in range(10): # Allocate the boundary rect = rtree.RTreeAllocRect(tree) rtree.RTreeSetRect4D(rect, tree, float(i - 2), float(i + 2), float(i - 2), float(i + 2), float(i - 2), float(i + 2), float(i - 2), float(i + 2)) rtree.RTreeInsertRect(rect, i + 1, tree) rect = rtree.RTreeAllocRect(tree) rtree.RTreeSetRect4D(rect, tree, 2.0, 7.0, 2.0, 7.0, 2.0, 7.0, 2.0, 7.0) list_ = gis.ilist() num = vector.RTreeSearch2(tree, rect, byref(list_)) rtree.RTreeFreeRect(rect) # print rectangle ids print("Number of overlapping rectangles", num) for i in range(list_.n_values): print("id", list_.value[i]) rtree.RTreeDestroyTree(tree)
def test_3d_rtree(): """Testing the rtree ctypes wrapper""" tree = rtree.RTreeCreateTree(-1, 0, 3) for i in xrange(10): rect = rtree.RTreeAllocRect(tree) rtree.RTreeSetRect3D(rect, tree, float(i - 2), float(i + 2), float(i - 2), float(i + 2), float(i - 2), float(i + 2)) rtree.RTreeInsertRect(rect, i + 1, tree) print i + 1 rtree.RTreePrintRect(rect, 1, tree) rect = rtree.RTreeAllocRect(tree) rtree.RTreeSetRect3D(rect, tree, 2.0, 7.0, 2.0, 7.0, 2.0, 7.0) print "Select" rtree.RTreePrintRect(rect, 1, tree) list_ = gis.ilist() num = vector.RTreeSearch2(tree, rect, byref(list_)) rtree.RTreeFreeRect(rect) # print rectangle ids print "Number of overlapping rectangles", num for i in xrange(list_.n_values): print "id", list_.value[i] rtree.RTreeDestroyTree(tree)
def _build_rtree(self, maps, spatial=None): """Build and return the 1-4 dimensional R*-Tree :param spatial: This indicates if the spatial topology is created as well: spatial can be None (no spatial topology), "2D" using west, east, south, north or "3D" using west, east, south, north, bottom, top """ dim = 1 if spatial == "2D": dim = 3 if spatial == "3D": dim = 4 tree = rtree.RTreeCreateTree(-1, 0, dim) for i in range(len(maps)): rect = self._map_to_rect(tree, maps[i], spatial) rtree.RTreeInsertRect(rect, i + 1, tree) return tree