private Query getQuery(Function inner, Context context) { RefLiteralPair innerPair = new RefLiteralPair(inner); if (!innerPair.isValid()) { return null; } GeoPointFieldMapper mapper = getGeoPointFieldMapper( innerPair.reference().info().ident().columnIdent().fqn(), context.mapperService); Shape shape = (Shape) innerPair.input().value(); Geometry geometry = JtsSpatialContext.GEO.getGeometryFrom(shape); IndexGeoPointFieldData fieldData = context.fieldDataService.getForField(mapper); Filter filter; if (geometry.isRectangle()) { Rectangle boundingBox = shape.getBoundingBox(); filter = new InMemoryGeoBoundingBoxFilter( new GeoPoint(boundingBox.getMaxY(), boundingBox.getMinX()), new GeoPoint(boundingBox.getMinY(), boundingBox.getMaxX()), fieldData); } else { Coordinate[] coordinates = geometry.getCoordinates(); GeoPoint[] points = new GeoPoint[coordinates.length]; for (int i = 0; i < coordinates.length; i++) { Coordinate coordinate = coordinates[i]; points[i] = new GeoPoint(coordinate.y, coordinate.x); } filter = new GeoPolygonFilter(fieldData, points); } return new FilteredQuery( Queries.newMatchAllQuery(), context.indexCache.filter().cache(filter)); }
@Test public void testCellTraverse() { trie = new GeohashPrefixTree(ctx, 4); Cell prevC = null; Cell c = trie.getWorldCell(); assertEquals(0, c.getLevel()); assertEquals(ctx.getWorldBounds(), c.getShape()); while (c.getLevel() < trie.getMaxLevels()) { prevC = c; List<Cell> subCells = new ArrayList<>(); CellIterator subCellsIter = c.getNextLevelCells(null); while (subCellsIter.hasNext()) { subCells.add(subCellsIter.next()); } c = subCells.get(random().nextInt(subCells.size() - 1)); assertEquals(prevC.getLevel() + 1, c.getLevel()); Rectangle prevNShape = (Rectangle) prevC.getShape(); Shape s = c.getShape(); Rectangle sbox = s.getBoundingBox(); assertTrue(prevNShape.getWidth() > sbox.getWidth()); assertTrue(prevNShape.getHeight() > sbox.getHeight()); } }
@Override protected Rectangle computeBoundingBox(Collection<? extends Shape> shapes, SpatialContext ctx) { Rectangle retBox = shapes.iterator().next().getBoundingBox(); for (Shape geom : shapes) { retBox = expandBBox(retBox, geom.getBoundingBox()); } return retBox; }