forked from georust/geozero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kdbush.rs
34 lines (31 loc) · 828 Bytes
/
kdbush.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use geozero::error::Result;
use geozero::geojson::GeoJsonReader;
use geozero::GeozeroDatasource;
use kdbush::*;
use std::fs::File;
struct PointIndex {
pos: usize,
index: KDBush,
}
impl geozero::GeomProcessor for PointIndex {
fn xy(&mut self, x: f64, y: f64, _idx: usize) -> Result<()> {
self.index.add_point(self.pos, x, y);
self.pos += 1;
Ok(())
}
}
#[test]
fn create() -> Result<()> {
let mut f = File::open("tests/data/places.json")?;
let mut reader = GeoJsonReader(&mut f);
let mut points = PointIndex {
pos: 0,
index: KDBush::new(1249, DEFAULT_NODE_SIZE),
};
reader.process_geom(&mut points)?;
points.index.build_index();
let mut cnt = 0;
points.index.within(8.53, 47.37, 5.0, |_id| cnt += 1);
assert_eq!(cnt, 22);
Ok(())
}