I have a few points, and a lot of linestrings, and I want to find all combinations of linestring & point within X metres. But I can't find suitable crates for this.
For example rstar crate implements an R-Tree index. But it works only with one type: if the tree is made of (geo) Points, it can't run methods against LineStrings (see the example in Rust Explorer that doesn't compile).
Is there any way to use rstar or a working crate for this?
The only way around I see is to make a bounding box from the LineString and call RTree::locate_in_envelope
, and then calculate the distance from points to the linestring manually.
/*
[dependencies]
geo = '0.23'
rstar = '0.9'
*/
use rstar::RTree;
use geo::geometry::{LineString, Point, Coordinate};
use geo::line_string;
fn main() {
let mut rt = RTree::bulk_load(vec![Point(Coordinate::from((0.1, 0.1))), Point(Coordinate::from((10.0, 10.0)))]);
let l = line_string![(x: 10.0, y: 0.0), (x: 10.0, y: 20.0)];
println!("{:?}", rt.nearest_neighbor(&l));
}
With a bit more research, I found crate spatial-join
, but it's been unmaintained for 2 years. It doesn't compile with the newest geo
crate.
Looking into its implementation, it's using the same R-Tree, so probably with some work, I can re-implement this.