Crates.io | geoprox-core |
lib.rs | geoprox-core |
version | 0.5.0 |
source | src |
created_at | 2024-08-01 04:21:55.918062 |
updated_at | 2024-08-23 20:50:54.030052 |
description | Core library for Geoprox, provides geospatial indexing and search functionalities |
homepage | |
repository | https://github.com/ezrasingh/geoprox |
max_upload_size | |
id | 1321600 |
size | 58,385 |
Geoprox Core is the foundational Rust crate for the Geoprox project, providing robust geospatial indexing and sharding capabilities. It includes two primary modules:
index
: Manages in-memory storage and retrieval of geospatial data to ensure quick access and efficient querying.shard
: Handles the partitioning and indexing of geospatial information, optimizing data distribution and retrieval across large datasets.These modules are built to handle various use cases, such as food delivery services and real-time inventory tracking.
Looking for an API implementation? See,
geoprox-server
for the HTTP API version of this service andcontrib/client-sdk
for HTTP client libraries.
The shard
module implements the GeoShard
data structure, which facilitates geographical sharding of datasets and enables efficient range queries.
Key features include:
use geoprox_core::shard::GeoShard;
let mut shard = GeoShard::default();
// ? create an index to store driver coordinates
shard.create_index("drivers").unwrap();
// ? place drivers into index
let ttl = std::time::Duration::from_secs(10);
shard.insert_key(
"drivers", "alice",
[36.2049, 138.253],
Some(ttl)
).unwrap();
shard.insert_key(
"drivers", "bob",
[36.2047, 138.2528],
None
).unwrap();
// ? search drivers near Japan
let nearby: LatLngCoord = [36.2048, 138.2529];
let within: f64 = 50.0; // 50km radius
let count = 100; // return up to 100 results
let sorted = true; // sort results by distance
let res = shard.query_range("drivers", nearby, within, Some(count), Some(sorted));
println!("found: {:#?}", res.unwrap());
The index
module implements the SpatialIndex
data structure, enabling efficient placement and searching of resources based on their geohash-encoded locations.
Key features include:
use geoprox_core::index::SpatialIndex;
let mut geo_index = SpatialIndex::default();
// ? place object keys into index
geo_index.insert("alice", "s00j8n0");
geo_index.insert("bob", "s00j8n1");
// ? search index for objects near New York
let nearby: LatLngCoord = [40.7128, 74.006];
let within: f64 = 200.0; // 200km radius
let count = 100; // return up to 100 results
let sorted = true; // sort results by distance
let search_depth = 6; // search precision (higher means more precise)
let res = geo_index.search(nearby, within, count, sorted, depth).unwrap();
println!("found: {:#?}", res);
assert_eq!(res.len(), 2);
res.iter().for_each(|neighbor| {
assert!(neighbor.distance <= within);
});
Contributions are welcome! Please see the contributing guidelines for more information.
This project is licensed under the Apache 2.0 or MIT License (your choice).