Skip to content

Commit c8ba5f1

Browse files
committed
try prepared geometries
1 parent 60bc592 commit c8ba5f1

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ xz2 = "0.1"
2828
ndarray = { version = "0.15", features = [ "rayon" ] }
2929
wkb = "0.7.1"
3030
rstar = "0.12.0"
31+
static_cell = "2.1.0"
3132

3233
[dev-dependencies]
3334
rayon = "1"
@@ -46,3 +47,5 @@ default = [ ]
4647
[profile.release]
4748
debug = true
4849

50+
[patch.crates-io]
51+
geo = { git = "https://github.com/georust/geo", branch = "mkirk/prepared-geom" }

src/shapes.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ use std::io;
44
use std::path::Path;
55
use std::{borrow::Borrow, convert::TryInto};
66

7-
use geo::{point, Contains, Geometry, MultiPolygon, Point, Polygon};
7+
use geo::{point, Contains, Geometry, MultiPolygon, Point, Polygon, PreparedGeometry, Relate};
88
use numpy::{PyArray, PyReadonlyArrayDyn};
99
use rstar::{PointDistance, RTree, RTreeObject, AABB};
10+
use static_cell::StaticCell;
1011

1112
pub static GSHHS_F: &str = "gshhs_f_-180.000000E-90.000000N180.000000E90.000000N.wkb.xz";
13+
static POLYS: StaticCell<Vec<Polygon>> = StaticCell::new();
1214

1315
#[pyclass]
1416
#[derive(Clone)]
@@ -17,7 +19,7 @@ pub struct Gshhg {
1719
}
1820

1921
#[derive(Clone)]
20-
struct PolW(Polygon);
22+
struct PolW(PreparedGeometry<'static>);
2123

2224
impl RTreeObject for PolW {
2325
type Envelope = AABB<Point<f64>>;
@@ -33,7 +35,7 @@ impl PointDistance for PolW {
3335
}
3436

3537
fn contains_point(&self, point: &Point<f64>) -> bool {
36-
self.0.contains(point)
38+
self.0.relate(point).is_contains()
3739
}
3840

3941
fn distance_2_if_less_or_equal(&self, _point: &Point<f64>, _max_distance: f64) -> Option<f64> {
@@ -45,7 +47,8 @@ impl Gshhg {
4547
pub fn from_geom(geom: Geometry) -> io::Result<Gshhg> {
4648
let geom: MultiPolygon = geom.try_into().unwrap();
4749
assert!(geom.0.len() > 10);
48-
let geoms = geom.0.into_iter().map(|p| PolW(p)).collect();
50+
POLYS.init(geom.into_iter().collect());
51+
let geoms = POLYS.into_iter().map(|p| PolW(PreparedGeometry::from(p))).collect();
4952

5053
let geom = RTree::bulk_load(geoms);
5154
Ok(Gshhg { geom })

0 commit comments

Comments
 (0)