How to use the rtree.index.Property function in Rtree

To help you get started, we’ve selected a few Rtree examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mikemccand / luceneutil / src / python / IndexOSM.py View on Github external
count = 0
    while True:
      line = f.readline()
      if len(line) == 0:
        break
      id, lat, lon = line.strip().split(',')
      lat = float(lat)
      lon = float(lon)
      count += 1
      if count % 1000000 == 0:
        print('%d...' % count)
      yield int(id), (lat, lon, lat, lon), None
    

t0 = time.time()
p = rtree.index.Property()
p.filename = 'theindex'
p.overwrite = True
p.storage = rtree.index.RT_Disk
p.dimension = 2

# 17.5 sec
#p.variant = rtree.index.RT_Star
#p.fill_factor = 0.4

# 17.4 sec:
#p.variant = rtree.index.RT_Quadratic
#p.fill_factor = 0.4

# 17.5 sec:
#p.variant = rtree.index.RT_Linear
#p.fill_factor = 0.4
github sci-wms / sci-wms / wms / models / datasets / sgrid.py View on Github external
with self.dataset() as nc:
            sg = load_grid(nc)

            def rtree_generator_function():
                c = 0
                centers = np.dstack((sg.center_lon, sg.center_lat))
                for i, axis in enumerate(centers):
                    for j, (x, y) in enumerate(axis):
                        c += 1
                        yield (c, (x, y, x, y), (i, j))

            logger.info("Building Faces (centers) Rtree Topology Cache for {0}".format(self.name))
            _, temp_file = tempfile.mkstemp(suffix='.face')
            start = time.time()
            p = index.Property()
            p.filename = str(temp_file)
            p.overwrite = True
            p.storage   = index.RT_Disk
            p.dimension = 2
            idx = index.Index(p.filename,
                              rtree_generator_function(),
                              properties=p,
                              overwrite=True,
                              interleaved=True)
            idx.close()

            logger.info("Built Faces (centers) Rtree Topology Cache in {0} seconds.".format(time.time() - start))
            shutil.move('{}.dat'.format(temp_file), self.face_tree_data_file)
            shutil.move('{}.idx'.format(temp_file), self.face_tree_index_file)
github mikedh / trimesh / raytracing.py View on Github external
def create_tree(vertices, faces):
    p = rtree.Property()
    p.dimension = 3
    tree      = rtree.Index(properties=p)
    triangles = vertices[[faces]]

    for triangle_index, triangle in enumerate(triangles):
        triangle_bounds = np.append(np.min(triangle, axis=0), 
                                    np.max(triangle, axis=0))
        tree.insert(triangle_index, triangle_bounds)
    return triangles, tree
github aaronbot3000 / hp7550-things / src / draw_indexed.py View on Github external
def prepare_rtree(dot_list):
  p = rindex.Property()
  p.leaf_capacity = 1000
  p.variant = rindex.RT_Star
  p.fill_factor = 0.02
  
  def points():
    for index in range(len(dot_list)):
      dot = dot_list[index]
      yield (index, dot_to_box(dot), None)

  rtree = rindex.Index(points(), properties=p)
  return rtree
github aaronbot3000 / hp7550-things / src / lib / plotter.py View on Github external
def _PrepareRtree(shape_list):
  p = rindex.Property()
  p.leaf_capacity = 1000
  p.variant = rindex.RT_Star
  p.fill_factor = 0.02

  def Points():
    for shape_id in range(1, len(shape_list)):
      shape = shape_list[shape_id]
      for box in shape.BoxesForRtree(shape_id):
        yield box

  rtree = rindex.Index(Points(), properties=p)
  return rtree
github sci-wms / sci-wms / wms / models / datasets / ugrid.py View on Github external
def make_rtree(self):

        with self.dataset() as nc:
            ug = UGrid.from_nc_dataset(nc=nc)

            def rtree_faces_generator_function():
                for face_idx, node_list in enumerate(ug.faces):
                    nodes = ug.nodes[node_list]
                    xmin, ymin = np.min(nodes, 0)
                    xmax, ymax = np.max(nodes, 0)
                    yield (face_idx, (xmin, ymin, xmax, ymax), face_idx)

            logger.info("Building Faces Rtree Topology Cache for {0}".format(self.name))
            start = time.time()
            _, face_temp_file = tempfile.mkstemp(suffix='.face')
            pf = index.Property()
            pf.filename = str(face_temp_file)
            pf.overwrite = True
            pf.storage   = index.RT_Disk
            pf.dimension = 2
            idx = index.Index(pf.filename,
                              rtree_faces_generator_function(),
                              properties=pf,
                              interleaved=True,
                              overwrite=True)
            idx.close()
            logger.info("Built Faces Rtree Topology Cache in {0} seconds.".format(time.time() - start))
            shutil.move('{}.dat'.format(face_temp_file), self.face_tree_data_file)
            shutil.move('{}.idx'.format(face_temp_file), self.face_tree_index_file)

            def rtree_nodes_generator_function():
                for node_index, (x, y) in enumerate(ug.nodes):
github motion-planning / rrt-algorithms / src / search_space / search_space.py View on Github external
"""
        Initialize Search Space
        :param dimension_lengths: range of each dimension
        :param O: list of obstacles
        """
        # sanity check
        if len(dimension_lengths) < 2:
            raise Exception("Must have at least 2 dimensions")
        self.dimensions = len(dimension_lengths)  # number of dimensions
        # sanity checks
        if any(len(i) != 2 for i in dimension_lengths):
            raise Exception("Dimensions can only have a start and end")
        if any(i[0] >= i[1] for i in dimension_lengths):
            raise Exception("Dimension start must be less than dimension end")
        self.dimension_lengths = dimension_lengths  # length of each dimension
        p = index.Property()
        p.dimension = self.dimensions
        # r-tree representation of obstacles
        # sanity check
        if any(len(o) / 2 != len(dimension_lengths) for o in O):
            raise Exception("Obstacle has incorrect dimension definition")
        if any(o[i] >= o[int(i + len(o) / 2)] for o in O for i in range(int(len(o) / 2))):
            raise Exception("Obstacle start must be less than obstacle end")
        if O is None:
            self.obs = index.Index(interleaved=True, properties=p)
        else:
            self.obs = index.Index(obstacle_generator(O), interleaved=True, properties=p)
github SEL-Columbia / networkplanner / np / lib / network / __init__.py View on Github external
if(self._useIndex):
            # These structures need to be updated for each 
            # segment we add to network.

            # Keep index of segments so we don't need to marshal them 
            # in/out of rtree.
            self._segments = {}
            self._idsBySegment = {}

            # Lookup table for subnets by segment coordinates. 
            # (need to update subnet lookups as they merge)
            self._subnetLookupBySegment = {}
            # rtree spatial index for intersection test speedup
            # setup properties first
            p = index.Property()
            p.index_capacity = 10
            p.leaf_capacity = 10
            p.near_minimum_overlap_factor = 3
            self._spatialIndex = index.Index(properties=p)
github su2code / SU2 / SU2_PY / FSI / FSIInterface.py View on Github external
def RBFMeshMapping_A(self, solidInterfaceBuffRcv_X, solidInterfaceBuffRcv_Y, solidInterfaceBuffRcv_Z, iProc, rad):
        """
        Description
        """

        if self.have_MPI == True:
          myid = self.comm.Get_rank()
        else:
          myid = 0

        # --- Instantiate the spatial indexing ---
	prop_index = index.Property()
	prop_index.dimension = self.nDim
	SolidSpatialTree = index.Index(properties=prop_index)
        
        nSolidNodes = solidInterfaceBuffRcv_X.shape[0]

        for jVertex in range(nSolidNodes):
          posX = solidInterfaceBuffRcv_X[jVertex]
          posY = solidInterfaceBuffRcv_Y[jVertex]
          posZ = solidInterfaceBuffRcv_Z[jVertex]
	  if self.nDim == 2 :
	    SolidSpatialTree.add(jVertex, (posX, posY))
   	  else :
	    SolidSpatialTree.add(jVertex, (posX, posY, posZ))

        for iVertexSolid in range(self.nLocalSolidInterfaceNodes):
          posX = self.localSolidInterface_array_X[iVertexSolid]