Skip to main content

Crate nitrite_spatial

Crate nitrite_spatial 

Source
Expand description

§Nitrite Spatial - Spatial Indexing for Nitrite Database

This crate provides spatial indexing capabilities for the Nitrite database, including a memory-efficient disk-based R-Tree implementation and spatial query filters.

§Features

  • Disk-Based Storage: Pages stored on disk, loaded on demand
  • LRU Cache: Frequently accessed pages kept in memory
  • Memory Efficient: Only hot data in RAM, cold data on disk
  • Persistent: Data survives process restarts
  • Thread Safe: Concurrent read/write support
  • Two-Phase Search: Fast R-tree bbox search followed by precise geometry refinement
  • Spatial Filters: Intersects, Within, Near, and GeoNear filters
  • Fluent API: Builder pattern for spatial queries

§Quick Start

use nitrite_spatial::{SpatialModule, spatial_field, Point, Geometry};
use nitrite::nitrite_builder::NitriteBuilder;
use nitrite::common::PersistentCollection;

// Register spatial module
let db = Nitrite::builder()
    .load_module(SpatialModule)
    .open_or_create(None, None)?;

// Create spatial index on a field
let collection = db.collection("places")?;
collection.create_index(vec!["location"], &nitrite_spatial::spatial_index())?;

// Query with spatial filters
let filter = spatial_field("location")
    .intersects(Geometry::point(0.0, 0.0));

let results = collection.find(filter, None)?;

§R-Tree API

use nitrite_spatial::{DiskRTree, BoundingBox, NitriteRTree};
use tempfile::NamedTempFile;

// Create a new R-Tree
let temp_file = NamedTempFile::new()?;
let tree = DiskRTree::create(temp_file.path())?;

// Add entries
tree.add(&BoundingBox::new(0.0, 0.0, 10.0, 10.0), 1)?;

// Find intersecting entries
let query = BoundingBox::new(5.0, 5.0, 15.0, 15.0);
let results = tree.find_intersecting_keys(&query)?;

Re-exports§

pub use bounding_box::BoundingBox;
pub use disk_rtree::DiskRTree;
pub use disk_rtree::RTreeStats;
pub use disk_rtree::SpatialError;
pub use disk_rtree::SpatialResult;
pub use nitrite_rtree::NitriteRTree;
pub use geometry::create_geodesic_circle;
pub use geometry::meters_to_degrees;
pub use geometry::Coordinate;
pub use geometry::GeoPoint;
pub use geometry::Geometry;
pub use geometry::Point;
pub use geometry_extended::parse_geojson;
pub use geometry_extended::parse_wkt;
pub use geometry_extended::GeometryValue;
pub use geometry_extended::LineString;
pub use geometry_extended::MultiGeometry;
pub use geometry_extended::PolygonWithHoles;
pub use filter::GeoNearFilter;
pub use filter::IntersectsFilter;
pub use filter::NearFilter;
pub use filter::SpatialFilterOps;
pub use filter::WithinFilter;
pub use fluent::SpatialFluentFilter;
pub use indexer::SpatialIndexer;
pub use filter::SPATIAL_INDEX;
pub use spatial_module::SpatialModule;
pub use fluent::spatial_field;

Modules§

bounding_box
disk_rtree
Disk-based R-Tree implementation for memory-efficient spatial indexing.
filter
Spatial filters for querying geometries in Nitrite collections.
fluent
Fluent API for creating spatial filters.
geometry
Geometry types for spatial indexing.
geometry_extended
Extended geometry types for spatial indexing.
hilbert
Hilbert curve utilities for spatial locality optimization.
index
indexer
Spatial indexer implementation for Nitrite.
nitrite_rtree
NitriteRTree trait definition for spatial indexing.
spatial_module

Functions§

spatial_index
Creates index options for a spatial index.