Nitrite Spatial
Geospatial indexing and querying module for Nitrite using R-tree data structures.
Features
- Spatial Indexes - R-tree based spatial indexing
- Geometry Types - Points, envelopes (bounding boxes)
- Spatial Queries - Within, near, and k-nearest neighbor queries
Usage
Loading the Module
use Nitrite;
use SpatialModule;
let db = builder
.load_module
.open_or_create
.expect;
Creating a Spatial Index
use spatial_index;
let collection = db.collection.unwrap;
collection.create_index.unwrap;
Inserting Spatial Data
Use x and y fields to represent point coordinates:
use doc;
let doc = doc! ;
collection.insert.unwrap;
Spatial Queries
Within Query (Bounding Box)
use ;
// Create a bounding box: (min_x, min_y, max_x, max_y)
let search_box = envelope;
// Find all points within the bounding box
let filter = spatial_field.within;
let cursor = collection.find.unwrap;
Near Query
use ;
// Find points near a location within a radius
let center = new;
let filter = spatial_field.near;
let cursor = collection.find.unwrap;
Geometry Types
Point::new(x, y)- A single coordinateGeometry::envelope(min_x, min_y, max_x, max_y)- A bounding box
Benchmarks
Run the R-tree benchmark to measure spatial indexing performance:
# Run all R-tree benchmarks
# Quick validation (no measurement)
Benchmark results are saved to target/criterion/ with HTML reports.
License
Apache License 2.0