Пример #1
0
 def testInsertSame(self):
     tree = RTree()
     rect = G.rect()
     xs = [TstO(rect) for i in range(11)]
     for x in xs:
         tree.insert(x, x.rect)
         self.invariants(tree)
Пример #2
0
 def add_transformation(self, transform_matrix):
     """Adds a transformation to all tiles"""
     self.rtree = RTree()
     for single_tile in self.single_tiles:
         single_tile.add_transformation(transform_matrix)
         bbox = single_tile.get_bbox()
         # pyrtree uses the (x_min, y_min, x_max, y_max) notation
         self.rtree.insert(single_tile,
                           Rect(bbox[0], bbox[2], bbox[1], bbox[3]))
Пример #3
0
 def __init__(self, single_tiles, blend_type="NO_BLENDING"):
     """Receives a number of image paths, and for each a transformation matrix"""
     self.blend_type = self.BLEND_TYPE[blend_type]
     self.single_tiles = single_tiles
     # Create an RTree of the bounding boxes of the tiles
     self.rtree = RTree()
     for t in self.single_tiles:
         bbox = t.get_bbox()
         # pyrtree uses the (x_min, y_min, x_max, y_max) notation
         self.rtree.insert(t, Rect(bbox[0], bbox[2], bbox[1], bbox[3]))
Пример #4
0
def newTree():
    xs = [
        RectWrapper(r, idx)
        for idx, r in enumerate(take(RECT_COUNT, rgen.rect, MAX_LENGTH))
    ]
    tree = RTree()
    for x in xs:
        tree.insert(x, x.rect)

    return tree, xs
Пример #5
0
    def testDegenerateContainer(self):
        """ Tests that an r-tree still works like a container even with highly overlapping rects. """
        xs = [TstO(r) for r in take(1000, G.rect, 20.0)]
        tree = RTree()
        for x in xs:
            tree.insert(x, x.rect)
            self.invariants(tree)

        ws = [
            x.leaf_obj() for x in tree.walk(lambda x, y: True) if x.is_leaf()
        ]
        for x in xs:
            self.assertTrue(x in ws)
Пример #6
0
    def testPointQuery(self):
        xs = [TstO(r) for r in take(1000, G.rect, 0.01)]
        tree = RTree()
        for x in xs:
            tree.insert(x, x.rect)
            self.invariants(tree)

        for x in xs:
            qp = G.pointInside(x.rect)
            self.assertTrue(x.rect.does_containpoint(qp))
            op = G.pointOutside(x.rect)
            rs = list([r.leaf_obj() for r in tree.query_point(qp)])
            self.assertTrue(x in rs, "Not in results of len %d :(" % (len(rs)))
            rrs = list([r.leaf_obj() for r in tree.query_point(op)])
            self.assertFalse(x in rrs)
Пример #7
0
    def testRectQuery(self):
        xs = [TstO(r) for r in take(1000, G.rect, 0.01)]
        rt = RTree()
        for x in xs:
            rt.insert(x, x.rect)
            self.invariants(rt)

        for x in xs:
            qrect = G.intersectingWith(x.rect)
            orect = G.disjointWith(x.rect)
            self.assertTrue(qrect.does_intersect(x.rect))
            p = G.pointInside(x.rect)
            res = list([ro.leaf_obj() for ro in rt.query_point(p)])
            self.invariants(rt)
            self.assertTrue(x in res)
            res2 = list([r.leaf_obj() for r in rt.query_rect(qrect)])
            self.assertTrue(x in res2)
            rres = list([r.leaf_obj() for r in rt.query_rect(orect)])
            self.assertFalse(x in rres)
Пример #8
0
    def testContainer(self):
        """ Test container-like behaviour. """
        xs = [TstO(r) for r in take(100, G.rect, 0.1)]
        tree = RTree()
        for x in xs:
            tree.insert(x, x.rect)
            self.invariants(tree)

        ws = [
            x.leaf_obj() for x in tree.walk(lambda x, y: True) if x.is_leaf()
        ]
        self.invariants(tree)
        rrs = collections.defaultdict(int)

        for w in ws:
            rrs[w] = rrs[w] + 1

        for x in xs:
            self.assertEquals(rrs[x], 1)
Пример #9
0
def predefinedTree():
    xs = []
    tree = RTree()
    rid = 0
    for row in range(DIMENSION):
        for col in range(DIMENSION):
            x1 = 10 * row
            y1 = 10 * col
            x2 = x1 + 5
            y2 = y1 + 5
            rectangle = rgen.rect_from_coords(x1, y1, x2, y2)
            xs.append(RectWrapper(rectangle, rid))
            rid += 1


#    for x in xs:
#        tree.insert(x, x.rect)

    return tree, xs
Пример #10
0
 def testCons(self):
     n = RTree()
Пример #11
0
with r trees;
change all the things to rect
change the circle to rect
tree construction
querying
'''

#print "\n"
#print "\n"
#print "\n"
#print "\n"
for x123 in pointrtree:

    print x123

t = RTree()
i = 0
# ax = fig.add_axes([0,0,1,1])
'''
insertion is done
'''
#print "tag 10 is :)"
#print pointrtree[0]
#print "aaa"
for rectangepoints in pointrtree:
    x1 = rectangepoints[0][0]
    y1 = rectangepoints[0][1]
    x2 = rectangepoints[1][0]
    y2 = rectangepoints[1][1]
    # #print x1
    # wi=x2-x1
Пример #12
0
from pyrtree import Rect, RTree

DATA_SIZE = 100

# PyRTree Insert and Search Test. This PyRTree is query only index.

obj = []
for x in range(DATA_SIZE):
    # Create objects with rectangles for objs, Rect(0, 0, 1, 1), Rect(1, 1, 2, 2); name obj0, obj1, ...
    obj.append([Rect(0 + x, 0 + x, 1 + x, 1 + x), 'obj' + x.__str__()])

rtree = RTree() # tree creation

# pyrtree uses the Rect (x_min, y_min, x_max, y_max) notation
for x in range(DATA_SIZE):
    rtree.insert(obj[x], obj[x][0]) # element insertion with a given box

# Query the tree
rect_res = rtree.query_rect(Rect(1, 1, 4, 4) )

# Traverse the query result
for rtree_node in rect_res:
    if not rtree_node.is_leaf():
        continue
    t = rtree_node.leaf_obj()
    print(t[0].x, t[0].y, t[0].xx, t[0].yy, t[1])

# Get the internal nodes which are at the deepest level of the tree. Each internal contains a number of leaf nodes
for nodes in rtree.get_last_level():
    print(nodes)