rslearn.utils.rtree_index¶
rtree_index ¶
RtreeIndex spatial index implementation.
RtreeIndex ¶
Bases: SpatialIndex
An index of spatiotemporal geometries backed by an rtree index.
Both in-memory and on-disk options are supported.
Source code in rslearn/utils/rtree_index.py
insert ¶
Insert a box into the index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
box
|
tuple[float, float, float, float]
|
the bounding box of this item (minx, miny, maxx, maxy) |
required |
data
|
Any
|
arbitrary object |
required |
Source code in rslearn/utils/rtree_index.py
query ¶
Query the index for objects intersecting a box.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
box
|
tuple[float, float, float, float]
|
the bounding box query (minx, miny, maxx, maxy) |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
a list of objects in the index intersecting the box |
Source code in rslearn/utils/rtree_index.py
delete_partially_created_local_files ¶
Delete partially created .dat and .idx files.
Source code in rslearn/utils/rtree_index.py
get_cached_rtree ¶
get_cached_rtree(cache_dir: UPath, build_fn: Callable[[RtreeIndex], None]) -> RtreeIndex
Returns an RtreeIndex cached in cache_dir, creating it if needed.
The .dat and .idx files are cached in cache_dir. Since RtreeIndex expects local filesystem, it is copied to a local temporary directory if needed (it is not needed if the cache_dir is already on local filesystem). If the index doesn't exist yet, then it is created using build_fn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cache_dir
|
UPath
|
directory to cache the index files. |
required |
build_fn
|
Callable[[RtreeIndex], None]
|
function to build the index in case it doesn't exist yet. |
required |
Returns:
| Type | Description |
|---|---|
RtreeIndex
|
the RtreeIndex. |