Skip to content

Commit 5e470f2

Browse files
committed
chore: added geo Point and MultiPoint support
1 parent 867e3f1 commit 5e470f2

File tree

12 files changed

+433
-95
lines changed

12 files changed

+433
-95
lines changed

Cargo.lock

Lines changed: 196 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ keywords = ["quadbin", "quadkey", "spatial", "spatial-index"]
1313
categories = ["data-structures", "science::geo"]
1414

1515
[dependencies]
16+
geo = "0.30.0"
1617

1718
[dev-dependencies]
1819
approx = "0.5.1"

src/cells.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::Direction;
22
use crate::constants::*;
33
use crate::errors;
44
use crate::errors::*;
5-
use crate::tiles::*;
5+
use crate::tiles::Tile;
66
use crate::utils::*;
77
use core::{fmt, num::NonZeroU64};
88

@@ -328,7 +328,7 @@ fn point_to_cell(lat: f64, lng: f64, res: u8) -> Result<Cell, QuadbinError> {
328328
let lng = clip_longitude(lng);
329329
let lat = clip_latitude(lat);
330330

331-
let tile = Tile::from_point(lat, lng, res);
331+
let tile = Tile::from_point(lat, lng, res)?;
332332

333333
tile.to_cell()
334334
}

src/geo.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::Cell;
2+
use crate::errors::*;
3+
use geo::{MultiPoint, Point};
4+
5+
/// Support for [geo].
6+
impl Cell {
7+
/// Get Quadbin cell index from [geo::Point].
8+
///
9+
/// Similar to [Cell::from_point], but requires a [geo::Point] for input.
10+
pub fn from_geopoint(point: Point, res: u8) -> Result<Self, QuadbinError> {
11+
Cell::from_point(point.y(), point.x(), res)
12+
}
13+
14+
/// Get Quadbin cell index from [geo::MultiPoint]
15+
///
16+
/// The output may contain duplicate indexes in case of overlapping
17+
/// input geometries.
18+
pub fn from_multipoint(
19+
multipoint: MultiPoint,
20+
res: u8,
21+
) -> impl Iterator<Item = Result<Self, QuadbinError>> {
22+
multipoint
23+
.into_iter()
24+
.map(move |point| Cell::from_geopoint(point, res))
25+
}
26+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Quadbin cell itself
44
mod cells;
5+
mod geo;
56
pub use crate::cells::Cell;
67

78
// Direction struct

0 commit comments

Comments
 (0)