public class S2PrefixTree extends SpatialPrefixTree
SpatialContext
must implement the interface S2ShapeFactory
.
The tree can be configured on how it divided itself by providing an arity. The default arity is 1
which divided every sub-cell in 4 (except the first level that is always divided by 6) . Arity 2
divides sub-cells in 16 and arity 3 in 64 sub-cells.Modifier and Type | Class and Description |
---|---|
protected static class |
S2PrefixTree.Factory
Factory for creating
S2PrefixTree instances with useful defaults |
Modifier and Type | Field and Description |
---|---|
protected int |
arity |
protected S2ShapeFactory |
s2ShapeFactory |
ctx, maxLevels
Constructor and Description |
---|
S2PrefixTree(org.locationtech.spatial4j.context.SpatialContext ctx,
int maxLevels)
Creates a S2 spatial tree with arity 1.
|
S2PrefixTree(org.locationtech.spatial4j.context.SpatialContext ctx,
int maxLevels,
int arity)
Creates a S2 spatial tree with provided arity.
|
Modifier and Type | Method and Description |
---|---|
double |
getDistanceForLevel(int level)
Given a cell having the specified level, returns the distance from opposite
corners.
|
int |
getLevelForDistance(double dist)
Returns the level of the largest grid in which its longest side is less
than or equal to the provided distance (in degrees).
|
static int |
getMaxLevels(int arity)
Get max levels for this spatial tree.
|
CellIterator |
getTreeCellIterator(org.locationtech.spatial4j.shape.Shape shape,
int detailLevel)
Gets the intersecting cells for the specified shape, without exceeding
detail level.
|
Cell |
getWorldCell()
Returns the level 0 cell which encompasses all spatial data.
|
Cell |
readCell(BytesRef term,
Cell scratch)
This creates a new Cell (or re-using
scratch if provided), initialized to the state as read
by the bytes. |
getMaxLevels, getSpatialContext, toString
protected final S2ShapeFactory s2ShapeFactory
protected final int arity
public S2PrefixTree(org.locationtech.spatial4j.context.SpatialContext ctx, int maxLevels)
ctx
- The provided spatial context. The shape factor of the spatial context
must implement S2ShapeFactory
maxLevels
- The provided maximum level for this tree.public S2PrefixTree(org.locationtech.spatial4j.context.SpatialContext ctx, int maxLevels, int arity)
ctx
- The provided spatial context. The shape factor of the spatial context
must implement S2ShapeFactory
maxLevels
- The provided maximum level for this tree.arity
- The arity of the tree.public static int getMaxLevels(int arity)
arity
- The arity of the tree.public int getLevelForDistance(double dist)
SpatialPrefixTree
dist
acts as an error epsilon declaring the amount of detail needed in the
grid, such that you can get a grid with just the right amount of
precision.getLevelForDistance
in class SpatialPrefixTree
dist
- >= 0
public double getDistanceForLevel(int level)
SpatialPrefixTree
getDistanceForLevel
in class SpatialPrefixTree
level
- [1 to maxLevels]> 0
public Cell getWorldCell()
SpatialPrefixTree
SpatialPrefixTree.readCell(BytesRef,Cell)
with no bytes.getWorldCell
in class SpatialPrefixTree
public Cell readCell(BytesRef term, Cell scratch)
SpatialPrefixTree
scratch
if provided), initialized to the state as read
by the bytes.
Warning: An implementation may refer to the same byte array (no copy). If Cell.setLeaf()
is
subsequently called, it would then modify these bytes.readCell
in class SpatialPrefixTree
public CellIterator getTreeCellIterator(org.locationtech.spatial4j.shape.Shape shape, int detailLevel)
SpatialPrefixTree
IMPORTANT: Cells returned from the iterator can be re-used for cells at the same level. So you can't simply iterate to subsequent cells and still refer to the former cell nor the bytes returned from the former cell, unless you know the former cell is a parent.
getTreeCellIterator
in class SpatialPrefixTree
shape
- the shape; possibly null but the caller should liberally call
remove()
if so.detailLevel
- the maximum detail level to get cells forCopyright © 2000-2019 Apache Software Foundation. All Rights Reserved.