use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project elasticsearch by elastic.
the class GeoUtilsTests method testPrefixTreeCellSizes.
public void testPrefixTreeCellSizes() {
assertThat(GeoUtils.EARTH_SEMI_MAJOR_AXIS, equalTo(DistanceUtils.EARTH_EQUATORIAL_RADIUS_KM * 1000));
assertThat(GeoUtils.quadTreeCellWidth(0), lessThanOrEqualTo(GeoUtils.EARTH_EQUATOR));
SpatialContext spatialContext = new SpatialContext(true);
GeohashPrefixTree geohashPrefixTree = new GeohashPrefixTree(spatialContext, GeohashPrefixTree.getMaxLevelsPossible() / 2);
Cell gNode = geohashPrefixTree.getWorldCell();
for (int i = 0; i < geohashPrefixTree.getMaxLevels(); i++) {
double width = GeoUtils.geoHashCellWidth(i);
double height = GeoUtils.geoHashCellHeight(i);
double size = GeoUtils.geoHashCellSize(i);
double degrees = 360.0 * width / GeoUtils.EARTH_EQUATOR;
int level = GeoUtils.quadTreeLevelsForPrecision(size);
assertThat(GeoUtils.quadTreeCellWidth(level), lessThanOrEqualTo(width));
assertThat(GeoUtils.quadTreeCellHeight(level), lessThanOrEqualTo(height));
assertThat(GeoUtils.geoHashLevelsForPrecision(size), equalTo(geohashPrefixTree.getLevelForDistance(degrees)));
assertThat("width at level " + i, gNode.getShape().getBoundingBox().getWidth(), equalTo(360.d * width / GeoUtils.EARTH_EQUATOR));
assertThat("height at level " + i, gNode.getShape().getBoundingBox().getHeight(), equalTo(180.d * height / GeoUtils.EARTH_POLAR_DISTANCE));
gNode = gNode.getNextLevelCells(null).next();
}
QuadPrefixTree quadPrefixTree = new QuadPrefixTree(spatialContext);
Cell qNode = quadPrefixTree.getWorldCell();
for (int i = 0; i < quadPrefixTree.getMaxLevels(); i++) {
double degrees = 360.0 / (1L << i);
double width = GeoUtils.quadTreeCellWidth(i);
double height = GeoUtils.quadTreeCellHeight(i);
double size = GeoUtils.quadTreeCellSize(i);
int level = GeoUtils.quadTreeLevelsForPrecision(size);
assertThat(GeoUtils.quadTreeCellWidth(level), lessThanOrEqualTo(width));
assertThat(GeoUtils.quadTreeCellHeight(level), lessThanOrEqualTo(height));
assertThat(GeoUtils.quadTreeLevelsForPrecision(size), equalTo(quadPrefixTree.getLevelForDistance(degrees)));
assertThat("width at level " + i, qNode.getShape().getBoundingBox().getWidth(), equalTo(360.d * width / GeoUtils.EARTH_EQUATOR));
assertThat("height at level " + i, qNode.getShape().getBoundingBox().getHeight(), equalTo(180.d * height / GeoUtils.EARTH_POLAR_DISTANCE));
qNode = qNode.getNextLevelCells(null).next();
}
}
use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.
the class CompositeStrategyTest method setupQuadGrid.
private void setupQuadGrid(int maxLevels) {
//non-geospatial makes this test a little easier (in gridSnap), and using boundary values 2^X raises
// the prospect of edge conditions we want to test, plus makes for simpler numbers (no decimals).
SpatialContextFactory factory = new SpatialContextFactory();
factory.geo = false;
factory.worldBounds = new RectangleImpl(0, 256, -128, 128, null);
this.ctx = factory.newSpatialContext();
//A fairly shallow grid
if (maxLevels == -1)
//max 64k cells (4^8), also 256*256
maxLevels = randomIntBetween(1, 8);
this.grid = new QuadPrefixTree(ctx, maxLevels);
this.rptStrategy = newRPT();
}
use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.
the class PortedSolr3Test method parameters.
@ParametersFactory(argumentFormatting = "strategy=%s")
public static Iterable<Object[]> parameters() {
List<Object[]> ctorArgs = new ArrayList<>();
SpatialContext ctx = SpatialContext.GEO;
SpatialPrefixTree grid;
SpatialStrategy strategy;
grid = new GeohashPrefixTree(ctx, 12);
strategy = new RecursivePrefixTreeStrategy(grid, "recursive_geohash");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
grid = new QuadPrefixTree(ctx, 25);
strategy = new RecursivePrefixTreeStrategy(grid, "recursive_quad");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
grid = new GeohashPrefixTree(ctx, 12);
strategy = new TermQueryPrefixTreeStrategy(grid, "termquery_geohash");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
strategy = PointVectorStrategy.newInstance(ctx, "pointvector");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
strategy = PointVectorStrategy.newInstance(ctx, "pointvector_legacy");
ctorArgs.add(new Object[] { strategy.getFieldName(), strategy });
return ctorArgs;
}
use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.
the class QueryEqualsHashCodeTest method testEqualsHashCode.
@Test
public void testEqualsHashCode() {
switch(//0-3
random().nextInt(4)) {
case 0:
predicate = SpatialOperation.Contains;
break;
case 1:
predicate = SpatialOperation.IsWithin;
break;
default:
predicate = SpatialOperation.Intersects;
break;
}
final SpatialPrefixTree gridQuad = new QuadPrefixTree(ctx, 10);
final SpatialPrefixTree gridGeohash = new GeohashPrefixTree(ctx, 10);
Collection<SpatialStrategy> strategies = new ArrayList<>();
RecursivePrefixTreeStrategy recursive_geohash = new RecursivePrefixTreeStrategy(gridGeohash, "recursive_geohash");
strategies.add(recursive_geohash);
strategies.add(new TermQueryPrefixTreeStrategy(gridQuad, "termquery_quad"));
strategies.add(PointVectorStrategy.newInstance(ctx, "pointvector"));
strategies.add(BBoxStrategy.newInstance(ctx, "bbox"));
final SerializedDVStrategy serialized = new SerializedDVStrategy(ctx, "serialized");
strategies.add(serialized);
strategies.add(new CompositeSpatialStrategy("composite", recursive_geohash, serialized));
for (SpatialStrategy strategy : strategies) {
testEqualsHashcode(strategy);
}
}
use of org.apache.lucene.spatial.prefix.tree.QuadPrefixTree in project lucene-solr by apache.
the class HeatmapFacetCounterTest method testLucene7291Dateline.
@Test
public void testLucene7291Dateline() throws IOException {
// only 2, and we wind up with some big leaf cells
grid = new QuadPrefixTree(ctx, 2);
strategy = new RecursivePrefixTreeStrategy(grid, getTestClass().getSimpleName());
adoc("0", ctx.makeRectangle(-102, -83, 43, 52));
commit();
// HM crosses dateline
validateHeatmapResultLoop(ctx.makeRectangle(179, -179, 62, 63), 2, 100);
}
Aggregations