| Crates.io | nitrite_spatial |
| lib.rs | nitrite_spatial |
| version | 0.1.0 |
| created_at | 2025-12-16 19:47:14.601717+00 |
| updated_at | 2025-12-16 19:47:14.601717+00 |
| description | Spatial indexing support for Nitrite database using R-Tree |
| homepage | |
| repository | https://github.com/nitrite/nitrite-rust |
| max_upload_size | |
| id | 1988527 |
| size | 463,431 |
Geospatial indexing and querying module for Nitrite using R-tree data structures.
use nitrite::nitrite::Nitrite;
use nitrite_spatial::SpatialModule;
let db = Nitrite::builder()
.load_module(SpatialModule)
.open_or_create(None, None)
.expect("Failed to create database");
use nitrite_spatial::spatial_index;
let collection = db.collection("locations").unwrap();
collection.create_index(vec!["location"], &spatial_index()).unwrap();
Use x and y fields to represent point coordinates:
use nitrite::doc;
let doc = doc! {
name: "Central Park",
location: {
x: (-73.968285),
y: 40.785091
}
};
collection.insert(doc).unwrap();
use nitrite_spatial::{spatial_field, Geometry};
// Create a bounding box: (min_x, min_y, max_x, max_y)
let search_box = Geometry::envelope(-74.0, 40.7, -73.9, 40.9);
// Find all points within the bounding box
let filter = spatial_field("location").within(search_box);
let cursor = collection.find(filter).unwrap();
use nitrite_spatial::{spatial_field, Point};
// Find points near a location within a radius
let center = Point::new(-73.968285, 40.785091);
let filter = spatial_field("location").near(center, 0.1);
let cursor = collection.find(filter).unwrap();
Point::new(x, y) - A single coordinateGeometry::envelope(min_x, min_y, max_x, max_y) - A bounding boxRun the R-tree benchmark to measure spatial indexing performance:
# Run all R-tree benchmarks
cargo bench -p nitrite_spatial
# Quick validation (no measurement)
cargo bench -p nitrite_spatial -- --test
Benchmark results are saved to target/criterion/ with HTML reports.
Apache License 2.0