-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Put rstar creation inside trait (#206)
- Loading branch information
1 parent
6445c24
commit 46eb257
Showing
17 changed files
with
59 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ pub mod geos; | |
pub mod native; | ||
#[cfg(feature = "proj")] | ||
pub mod proj; | ||
pub mod rstar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use crate::array::*; | ||
use arrow2::types::Offset; | ||
use rstar::primitives::CachedEnvelope; | ||
|
||
/// Construct an R-Tree from a geometry array. | ||
pub trait RTree<'a> { | ||
/// The object type to store in the RTree. | ||
type RTreeObject: rstar::RTreeObject; | ||
|
||
/// Build an [`RTree`] spatial index containing this array's geometries. | ||
fn rstar_tree(&'a self) -> rstar::RTree<Self::RTreeObject>; | ||
} | ||
|
||
impl<'a> RTree<'a> for PointArray { | ||
type RTreeObject = crate::scalar::Point<'a>; | ||
|
||
fn rstar_tree(&'a self) -> rstar::RTree<Self::RTreeObject> { | ||
// Note: for points we don't memoize with CachedEnvelope | ||
rstar::RTree::bulk_load(self.iter().flatten().collect()) | ||
} | ||
} | ||
|
||
impl<'a> RTree<'a> for RectArray { | ||
type RTreeObject = crate::scalar::Rect<'a>; | ||
|
||
fn rstar_tree(&'a self) -> rstar::RTree<Self::RTreeObject> { | ||
// Note: for rects we don't memoize with CachedEnvelope | ||
rstar::RTree::bulk_load(self.iter().flatten().collect()) | ||
} | ||
} | ||
|
||
macro_rules! iter_cached_impl { | ||
($type:ty, $scalar_type:ty) => { | ||
impl<'a, O: Offset> RTree<'a> for $type { | ||
type RTreeObject = CachedEnvelope<$scalar_type>; | ||
|
||
fn rstar_tree(&'a self) -> rstar::RTree<Self::RTreeObject> { | ||
rstar::RTree::bulk_load(self.iter().flatten().map(CachedEnvelope::new).collect()) | ||
} | ||
} | ||
}; | ||
} | ||
|
||
iter_cached_impl!(LineStringArray<O>, crate::scalar::LineString<'a, O>); | ||
iter_cached_impl!(PolygonArray<O>, crate::scalar::Polygon<'a, O>); | ||
iter_cached_impl!(MultiPointArray<O>, crate::scalar::MultiPoint<'a, O>); | ||
iter_cached_impl!( | ||
MultiLineStringArray<O>, | ||
crate::scalar::MultiLineString<'a, O> | ||
); | ||
iter_cached_impl!(MultiPolygonArray<O>, crate::scalar::MultiPolygon<'a, O>); | ||
iter_cached_impl!(WKBArray<O>, crate::scalar::WKB<'a, O>); | ||
iter_cached_impl!(MixedGeometryArray<O>, crate::scalar::Geometry<'a, O>); | ||
iter_cached_impl!( | ||
GeometryCollectionArray<O>, | ||
crate::scalar::GeometryCollection<'a, O> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.