def test_1d_rtree():
    """Testing the rtree ctypes wrapper"""

    tree = rtree.RTreeCreateTree(-1, 0, 1)

    for i in range(10):

        rect = rtree.RTreeAllocRect(tree)
        rtree.RTreeSetRect1D(rect, tree, float(i - 2), float(i + 2))
        rtree.RTreeInsertRect(rect, i + 1, tree)

    rect = rtree.RTreeAllocRect(tree)
    rtree.RTreeSetRect1D(rect, tree, 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 _map_to_rect(self, tree, map_, spatial=None):
        """Use the spatio-temporal extent of a map to create and
           return a RTree rectangle

           :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
        """
        rect = rtree.RTreeAllocRect(tree)

        start, end = map_.get_temporal_extent_as_tuple()

        if not end:
            end = start

        if map_.is_time_absolute():
            start = time_delta_to_relative_time_seconds(start - self._timeref)
            end = time_delta_to_relative_time_seconds(end - self._timeref)

        if spatial is None:
            rtree.RTreeSetRect1D(rect, tree, float(start), float(end))
        elif spatial == "2D":
            north, south, east, west, top, bottom = map_.get_spatial_extent_as_tuple()
            rtree.RTreeSetRect3D(rect, tree, west, east, south, north,
                                 float(start), float(end))
        elif spatial == "3D":
            north, south, east, west, top, bottom = map_.get_spatial_extent_as_tuple()
            rtree.RTreeSetRect4D(rect, tree, west, east, south, north,
                                 bottom, top, float(start), float(end))

        return rect