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(self, mapsA, mapsB=None, spatial=None): """Build the spatio-temporal topology structure between one or two unordered lists of abstract dataset objects This method builds the temporal or spatio-temporal topology from mapsA to mapsB and vice verse. The spatio-temporal topology structure of each map will be reset and rebuild for mapsA and mapsB. After building the temporal or spatio-temporal topology the modified map objects of mapsA can be accessed in the same way as a dictionary using there id. The implemented iterator assures the chronological iteration over the mapsA. :param mapsA: A list of abstract_dataset objects with initiated spatio-temporal extent :param mapsB: An optional list of abstract_dataset objects with initiated spatio-temporal extent :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 """ identical = False if mapsA == mapsB: identical = True if mapsB is None: mapsB = mapsA identical = True for map_ in mapsA: map_.reset_topology() if not identical: for map_ in mapsB: map_.reset_topology() tree = self. _build_rtree(mapsA, spatial) list_ = gis.G_new_ilist() for j in range(len(mapsB)): rect = self._map_to_rect(tree, mapsB[j], spatial) vector.RTreeSearch2(tree, rect, list_) rtree.RTreeFreeRect(rect) for k in range(list_.contents.n_values): i = list_.contents.value[k] - 1 # Get the temporal relationship relation = mapsB[j].temporal_relation(mapsA[i]) A = mapsA[i] B = mapsB[j] set_temoral_relationship(A, B, relation) if spatial is not None: relation = mapsB[j].spatial_relation(mapsA[i]) set_spatial_relationship(A, B, relation) self._build_internal_iteratable(mapsA, spatial) if not identical and mapsB is not None: self._build_iteratable(mapsB, spatial) gis.G_free_ilist(list_) rtree.RTreeDestroyTree(tree)