An R-Tree, MVR-Tree, or TPR-Tree indexing object
Creates a new index
Parameters: |
|
---|
Warning
The coordinate ordering for all functions are sensitive the the index’s interleaved data member. If interleaved is False, the coordinates must be in the form [xmin, xmax, ymin, ymax, ..., ..., kmin, kmax]. If interleaved is True, the coordinates must be in the form [xmin, ymin, ..., kmin, xmax, ymax, ..., kmax].
A basic example
>>> from rtree import index
>>> p = index.Property()
>>> idx = index.Index(properties=p)
>>> idx
<rtree.index.Index object at 0x...>
Insert an item into the index:
>>> idx.insert(4321, (34.3776829412, 26.7375853734, 49.3776829412, 41.7375853734), obj=42)
Query:
>>> hits = idx.intersection((0, 0, 60, 60), objects=True)
>>> for i in hits:
... if i.id == 4321:
... i.object
... i.bbox
42
[34.3776829412, 26.737585373400002, 49.3776829412, 41.737585373400002]
Using custom serializers
>>> import simplejson
>>> class JSONIndex(index.Index):
... dumps = staticmethod(simplejson.dumps)
... loads = staticmethod(simplejson.loads)
>>> json_idx = JSONIndex()
>>> json_idx.insert(1, (0, 1, 0, 1), {"nums": [23, 45], "letters": "abcd"})
>>> list(json_idx.nearest((0, 0), 1, objects="raw"))
[{'letters': 'abcd', 'nums': [23, 45]}]
Inserts an item into the index with the given coordinates.
Parameters: |
|
---|
The following example inserts an entry into the index with id 4321, and the object it stores with that id is the number 42. The coordinate ordering in this instance is the default (interleaved=True) ordering:
>>> from rtree import index
>>> idx = index.Index()
>>> idx.insert(4321, (34.3776829412, 26.7375853734, 49.3776829412, 41.7375853734), obj=42)
Return ids or objects in the index that intersect the given coordinates.
Parameters: |
|
---|
The following example queries the index for any objects any objects that were stored in the index intersect the bounds given in the coordinates:
>>> from rtree import index
>>> idx = index.Index()
>>> idx.insert(4321, (34.3776829412, 26.7375853734, 49.3776829412, 41.7375853734), obj=42)
>>> hits = list(idx.intersection((0, 0, 60, 60), objects=True))
>>> [(item.object, item.bbox) for item in hits if item.id == 4321]
[(42, [34.3776829412, 26.737585373400002, 49.3776829412, 41.737585373400002])]
If the rtree.index.Item wrapper is not used, it is faster to request the ‘raw’ objects:
>>> list(idx.intersection((0, 0, 60, 60), objects="raw"))
[42]
Returns the k-nearest objects to the given coordinates.
Parameters: |
|
---|
Example of finding the three items nearest to this one:
>>> from rtree import index
>>> idx = index.Index()
>>> idx.insert(4321, (34.37, 26.73, 49.37, 41.73), obj=42)
>>> hits = idx.nearest((0, 0, 10, 10), 3, objects=True)
Deletes items from the index with the given 'id' within the specified coordinates.
Parameters: |
|
---|
Example:
>>> from rtree import index
>>> idx = index.Index()
>>> idx.delete(4321, (34.3776829412, 26.7375853734, 49.3776829412, 41.7375853734) )
Returns the bounds of the index
Parameters: | coordinate_interleaved – If True, the coordinates are turned in the form [xmin, ymin, ..., kmin, xmax, ymax, ..., kmax], otherwise they are returned as [xmin, xmax, ymin, ymax, ..., ..., kmin, kmax]. If not specified, the interleaved member of the index is used, which defaults to True. |
---|
Return number of objects that intersect the given coordinates.
Parameters: | coordinates – sequence or array This may be an object that satisfies the numpy array protocol, providing the index’s dimension * 2 coordinate pairs representing the mink and maxk coordinates in each dimension defining the bounds of the query window. |
---|
The following example queries the index for any objects any objects that were stored in the index intersect the bounds given in the coordinates:
>>> from rtree import index
>>> idx = index.Index()
>>> idx.insert(4321, (34.3776829412, 26.7375853734, 49.3776829412, 41.7375853734), obj=42)
>>> idx.count((0, 0, 60, 60))
1
Force a flush of the index to storage. Renders index inaccessible.
dumps(obj, protocol=0) – Return a string containing an object in pickle format.
See the Pickler docstring for the meaning of optional argument proto.
loads(string) – Load a pickle from the given string
An index property object is a container that contains a number of settable index properties. Many of these properties must be set at index creation times, while others can be used to adjust performance or behavior.
Buffering capacity
Callbacks for custom storage
Size of callbacks for custom storage
Extension for .dat file
Index dimension. Must be greater than 0, though a dimension of 1 might have undefined behavior.
Index filename for disk storage
Index node fill factor before branching
Extension for .idx file
Index capacity
First node index id
Index pool capacity
Leaf capacity
Overlap factor for MVRTrees
Overwrite existing index files
The pagesize when disk storage is used. It is ideal to ensure that your index entries fit within a single page for best performance.
Point pool capacity
Region pool capacity
Reinsert factor
Split distribution factor
Index storage. One of RT_Disk, RT_Memory or RT_Custom. If a filename is passed as the first parameter to :class:index.Index, RT_Disk is assumed. If a CustomStorage instance is passed, RT_Custom is assumed. Otherwise, RT_Memory is the default.
Uses tight bounding rectangles
TPR horizon
Index type. Valid index type values are RT_RTree, RT_MVTree, or RT_TPRTree. Only RT_RTree (the default) is practically supported at this time.
Index variant. Valid index variant values are RT_Linear, RT_Quadratic, and RT_Star
Write through caching
A container for index entries
There should be no reason to instantiate these yourself. Items are created automatically when you call rtree.index.Index.intersection() (or other index querying methods) with objects=True given the parameters of the function.
Returns the bounding box of the index entry