sphere-knn 0.1.0

fast nearest-neighbor lookups on a sphere. This is useful if, for example, you have a database of geographic points (latitude, longitude) and want to swiftly look up which of those points are near a given latitude, longitude pair.
Documentation
  • Coverage
  • 14.29%
    3 out of 21 items documented0 out of 1 items with examples
  • Size
  • Source code size: 22.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 421.0 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 17s Average build duration of successful builds.
  • all releases: 17s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • nrakochy/sphere-knn
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • nrakochy

Written in rust, this a port of sphere-knn, an api that provides fast nearest-neighbor lookups on a sphere. This is useful if, for example, you have a database of geographic points (latitude, longitude) and want to swiftly look up which of those points are near a given latitude, longitude pair.

Rust Usage

For an example of how to use, you can peruse the api example or run it from the cli

cd crates/sphere-knn/examples && cargo run --example api 

The library needs to know how to find the latitude / longitude keys on your object, so you will need to implement SphereKnnGetters on your data object.

use sphere_knn::{run, Opts, SphereKnnGetters};


impl<'name> SphereKnnGetters for ExampleStruct<'name> {
    fn get_lat(&self) -> f64 {
        return self.latitude;
    }
    fn get_lng(&self) -> f64 {
        return self.longitude;
    }
}

Once defined, you initialize the library with a vector of data, the result of which is an invocable function

let find_nearest_fn = sphere_knn::run(data);

This holds the vector-as-a-tree and allows for nearest neighborhood lookup on subsequent usage


let hartford = ExampleStruct {
        latitude: 41.76,
        longitude: -72.67,
        name: "hartford",
};

let result = find_nearest_fn(
    hartford.get_lat(),
    hartford.get_lng(),
    Opts {
        max_distance_threshold_meters: Some(200_000.0),
        number_results: Some(1 as usize),
    },
);