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]}]
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. |
---|
Force a flush of the index to storage. Renders index inaccessible.
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
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) )
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)
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.
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