Skip to main content

SpatialIndex

Struct SpatialIndex 

Source
pub struct SpatialIndex<T> { /* private fields */ }
Expand description

Spatial index for efficient geographic queries.

Uses an R-tree data structure for O(log n) query performance.

Implementations§

Source§

impl<T: Clone> SpatialIndex<T>

Source

pub fn new() -> Self

Create an empty spatial index.

Source

pub fn from_iter<I, F>(iter: I, location_fn: F) -> Self
where I: IntoIterator<Item = T>, F: Fn(&T) -> &Location,

Create a spatial index from items with a location extractor.

Source

pub fn insert(&mut self, item: T, location: &Location)

Insert an item into the index.

Source

pub fn query_bbox( &self, min_lat: f64, min_lon: f64, max_lat: f64, max_lon: f64, ) -> Vec<&T>

Query items within a bounding box.

§Arguments
  • min_lat - Minimum latitude
  • min_lon - Minimum longitude
  • max_lat - Maximum latitude
  • max_lon - Maximum longitude
Source

pub fn query_bounds(&self, bounds: &GeoBounds) -> Vec<&T>

Query items within geographic bounds.

Source

pub fn query_radius(&self, lat: f64, lon: f64, radius_degrees: f64) -> Vec<&T>

Query items within a radius of a point.

Note: This uses Euclidean distance in degrees. For accurate great-circle distance, use query_radius_meters.

Source

pub fn query_radius_meters( &self, lat: f64, lon: f64, radius_meters: f64, ) -> Vec<&T>

Query items within a radius in meters.

Uses the Haversine formula for accurate great-circle distance.

Source

pub fn nearest(&self, lat: f64, lon: f64, k: usize) -> Vec<&T>

Find the k nearest neighbors to a point.

Source

pub fn nearest_one(&self, lat: f64, lon: f64) -> Option<&T>

Find the single nearest item to a point.

Source

pub fn len(&self) -> usize

Returns the number of indexed items.

Source

pub fn is_empty(&self) -> bool

Returns true if the index is empty.

Source

pub fn items(&self) -> &[T]

Get all items in the index.

Trait Implementations§

Source§

impl<T: Debug> Debug for SpatialIndex<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Clone> Default for SpatialIndex<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for SpatialIndex<T>

§

impl<T> RefUnwindSafe for SpatialIndex<T>
where T: RefUnwindSafe,

§

impl<T> Send for SpatialIndex<T>
where T: Send,

§

impl<T> Sync for SpatialIndex<T>
where T: Sync,

§

impl<T> Unpin for SpatialIndex<T>
where T: Unpin,

§

impl<T> UnwindSafe for SpatialIndex<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.