Class S2PrefixTree
- java.lang.Object
-
- org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree
-
- org.apache.lucene.spatial.prefix.tree.S2PrefixTree
-
public class S2PrefixTree extends SpatialPrefixTree
Spatial prefix tree for S2 Geometry. Shape factories for the givenSpatialContextmust implement the interfaceS2ShapeFactory.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.
- WARNING: This API is experimental and might change in incompatible ways in the next release.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classS2PrefixTree.FactoryFactory for creatingS2PrefixTreeinstances with useful defaults
-
Field Summary
Fields Modifier and Type Field Description protected intarityprotected S2ShapeFactorys2ShapeFactory-
Fields inherited from class org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree
ctx, maxLevels
-
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description doublegetDistanceForLevel(int level)Given a cell having the specified level, returns the distance from opposite corners.intgetLevelForDistance(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 intgetMaxLevels(int arity)Get max levels for this spatial tree.CellIteratorgetTreeCellIterator(org.locationtech.spatial4j.shape.Shape shape, int detailLevel)Gets the intersecting cells for the specified shape, without exceeding detail level.CellgetWorldCell()Returns the level 0 cell which encompasses all spatial data.CellreadCell(BytesRef term, Cell scratch)This creates a new Cell (or re-usingscratchif provided), initialized to the state as read by the bytes.-
Methods inherited from class org.apache.lucene.spatial.prefix.tree.SpatialPrefixTree
getMaxLevels, getSpatialContext, toString
-
-
-
-
Field Detail
-
s2ShapeFactory
protected final S2ShapeFactory s2ShapeFactory
-
arity
protected final int arity
-
-
Constructor Detail
-
S2PrefixTree
public S2PrefixTree(org.locationtech.spatial4j.context.SpatialContext ctx, int maxLevels)Creates a S2 spatial tree with arity 1.- Parameters:
ctx- The provided spatial context. The shape factor of the spatial context must implementS2ShapeFactorymaxLevels- The provided maximum level for this tree.
-
S2PrefixTree
public S2PrefixTree(org.locationtech.spatial4j.context.SpatialContext ctx, int maxLevels, int arity)Creates a S2 spatial tree with provided arity.- Parameters:
ctx- The provided spatial context. The shape factor of the spatial context must implementS2ShapeFactorymaxLevels- The provided maximum level for this tree.arity- The arity of the tree.
-
-
Method Detail
-
getMaxLevels
public static int getMaxLevels(int arity)
Get max levels for this spatial tree.- Parameters:
arity- The arity of the tree.- Returns:
- The maximum number of levels by the provided arity.
-
getLevelForDistance
public int getLevelForDistance(double dist)
Description copied from class:SpatialPrefixTreeReturns the level of the largest grid in which its longest side is less than or equal to the provided distance (in degrees). Consequentlydistacts 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.- Specified by:
getLevelForDistancein classSpatialPrefixTree- Parameters:
dist->= 0- Returns:
- level [1 to maxLevels]
-
getDistanceForLevel
public double getDistanceForLevel(int level)
Description copied from class:SpatialPrefixTreeGiven a cell having the specified level, returns the distance from opposite corners. Since this might vary depending on where the cell is, this method may over-estimate.- Specified by:
getDistanceForLevelin classSpatialPrefixTree- Parameters:
level- [1 to maxLevels]- Returns:
> 0
-
getWorldCell
public Cell getWorldCell()
Description copied from class:SpatialPrefixTreeReturns the level 0 cell which encompasses all spatial data. Equivalent toSpatialPrefixTree.readCell(BytesRef,Cell)with no bytes.- Specified by:
getWorldCellin classSpatialPrefixTree
-
readCell
public Cell readCell(BytesRef term, Cell scratch)
Description copied from class:SpatialPrefixTreeThis creates a new Cell (or re-usingscratchif provided), initialized to the state as read by the bytes. Warning: An implementation may refer to the same byte array (no copy). IfCell.setLeaf()is subsequently called, it would then modify these bytes.- Specified by:
readCellin classSpatialPrefixTree
-
getTreeCellIterator
public CellIterator getTreeCellIterator(org.locationtech.spatial4j.shape.Shape shape, int detailLevel)
Description copied from class:SpatialPrefixTreeGets the intersecting cells for the specified shape, without exceeding detail level. If a cell is within the query shape then it's marked as a leaf and none of its children are added. For cells at detailLevel, they are marked as leaves too, unless it's a point.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.
- Overrides:
getTreeCellIteratorin classSpatialPrefixTree- Parameters:
shape- the shape; possibly null but the caller should liberally callremove()if so.detailLevel- the maximum detail level to get cells for- Returns:
- the matching cells
-
-