Package com.spatial4j.core.shape

Examples of com.spatial4j.core.shape.Shape


  public Filter makeFilter(SpatialArgs args) {
    final SpatialOperation op = args.getOperation();
    if (op != SpatialOperation.Intersects)
      throw new UnsupportedSpatialOperation(op);

    Shape shape = args.getShape();

    int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));

    return new IntersectsPrefixTreeFilter(
        shape, getFieldName(), grid, detailLevel, prefixGridScanLevel,
View Full Code Here


  public Filter makeFilter(SpatialArgs args) {
    final SpatialOperation op = args.getOperation();
    if (op != SpatialOperation.Intersects)
      throw new UnsupportedSpatialOperation(op);

    Shape shape = args.getShape();
    int detailLevel = grid.getLevelForDistance(args.resolveDistErr(ctx, distErrPct));
    List<Node> cells = grid.getNodes(shape, detailLevel,
        false,//no parents
        true);//simplify
    BytesRef[] terms = new BytesRef[cells.size()];
View Full Code Here

        int termLevel = scanCell.getLevel();
        if (termLevel > scanDetailLevel)
          continue;
        if (termLevel == scanDetailLevel || scanCell.isLeaf()) {
          Shape cShape;
          //if this cell represents a point, use the cell center vs the box
          // (points never have isLeaf())
          if (termLevel == grid.getMaxLevels() && !scanCell.isLeaf())
            cShape = scanCell.getCenter();
          else
View Full Code Here

      SmallDocSet leafDocs = getLeafDocs(cell, acceptContains);

      // Get the AND of all child results (into combinedSubResults)
      SmallDocSet combinedSubResults = null;
      //   Optimization: use null subCellsFilter when we know cell is within the query shape.
      Shape subCellsFilter = queryShape;
      if (cell.getLevel() != 0 && ((cell.getShapeRel() == null || cell.getShapeRel() == SpatialRelation.WITHIN))) {
        subCellsFilter = null;
        assert cell.getShape().relate(queryShape) == SpatialRelation.WITHIN;
      }
      Collection <Cell> subCells = cell.getSubCells(subCellsFilter);
View Full Code Here

        return CONTAINS;
      return r;
    }

    private boolean cornerContainsNonGeo(double x, double y) {
      Shape pt = ctx2D.makePoint(x, y);
      return shape1_2D.relate(pt).intersects() || shape2_2D.relate(pt).intersects();
    }
View Full Code Here

  @Test
  public void testShapePair() {
    ctx = SpatialContext.GEO;
    setupCtx2D(ctx);

    Shape leftShape = new ShapePair(ctx.makeRectangle(-74, -56, -8, 1), ctx.makeRectangle(-180, 134, -90, 90), true);
    Shape queryShape = ctx.makeRectangle(-180, 180, -90, 90);
    assertEquals(SpatialRelation.WITHIN, leftShape.relate(queryShape));
  }
View Full Code Here

    Map<String, Shape> indexedShapesGS = new LinkedHashMap<>();//grid snapped
    final int numIndexedShapes = randomIntBetween(1, 6);
    boolean indexedAtLeastOneShapePair = false;
    for (int i = 0; i < numIndexedShapes; i++) {
      String id = "" + i;
      Shape indexedShape;
      int R = random().nextInt(12);
      if (R == 0) {//1 in 12
        indexedShape = null;
      } else if (R == 1) {//1 in 12
        indexedShape = randomPoint();//just one point
      } else if (R <= 4) {//3 in 12
        //comprised of more than one shape
        indexedShape = randomShapePairRect(biasContains);
        indexedAtLeastOneShapePair = true;
      } else {
        indexedShape = randomRectangle();//just one rect
      }

      indexedShapes.put(id, indexedShape);
      indexedShapesGS.put(id, gridSnap(indexedShape));

      adoc(id, indexedShape);

      if (random().nextInt(10) == 0)
        commit();//intermediate commit, produces extra segments

    }
    //delete some documents randomly
    Iterator<String> idIter = indexedShapes.keySet().iterator();
    while (idIter.hasNext()) {
      String id = idIter.next();
      if (random().nextInt(10) == 0) {
        deleteDoc(id);
        idIter.remove();
        indexedShapesGS.remove(id);
      }
    }

    commit();

    //Main query loop:
    final int numQueryShapes = atLeast(20);
    for (int i = 0; i < numQueryShapes; i++) {
      int scanLevel = randomInt(grid.getMaxLevels());
      ((RecursivePrefixTreeStrategy) strategy).setPrefixGridScanLevel(scanLevel);

      final Shape queryShape;
      switch (randomInt(10)) {
        case 0: queryShape = randomPoint(); break;
// LUCENE-5549
//TODO debug: -Dtests.method=testWithin -Dtests.multiplier=3 -Dtests.seed=5F5294CE2E075A3E:AAD2F0F79288CA64
//        case 1:case 2:case 3:
//          if (!indexedAtLeastOneShapePair) { // avoids ShapePair.relate(ShapePair), which isn't reliable
//            queryShape = randomShapePairRect(!biasContains);//invert biasContains for query side
//            break;
//          }
        default: queryShape = randomRectangle();
      }
      final Shape queryShapeGS = gridSnap(queryShape);

      final boolean opIsDisjoint = operation == SpatialOperation.IsDisjointTo;

      //Generate truth via brute force:
      // We ensure true-positive matches (if the predicate on the raw shapes match
      //  then the search should find those same matches).
      // approximations, false-positive matches
      Set<String> expectedIds = new LinkedHashSet<>();//true-positives
      Set<String> secondaryIds = new LinkedHashSet<>();//false-positives (unless disjoint)
      for (Map.Entry<String, Shape> entry : indexedShapes.entrySet()) {
        String id = entry.getKey();
        Shape indexedShapeCompare = entry.getValue();
        if (indexedShapeCompare == null)
          continue;
        Shape queryShapeCompare = queryShape;

        if (operation.evaluate(indexedShapeCompare, queryShapeCompare)) {
          expectedIds.add(id);
          if (opIsDisjoint) {
            //if no longer intersect after buffering them, for disjoint, remember this
View Full Code Here

    Map<String, Shape> indexedShapes = new LinkedHashMap<String, Shape>();
    Map<String, Shape> indexedShapesGS = new LinkedHashMap<String, Shape>();
    final int numIndexedShapes = randomIntBetween(1, 6);
    for (int i = 0; i < numIndexedShapes; i++) {
      String id = "" + i;
      Shape indexedShape;
      Shape indexedShapeGS; //(grid-snapped)
      int R = random().nextInt(12);
      if (R == 0) {//1 in 12
        indexedShape = null; //no shape for this doc
        indexedShapeGS = null;
      } else if (R % 3 == 0) {//4-1 in 12
        //comprised of more than one shape
        Rectangle shape1 = randomRectangle();
        Rectangle shape2 = randomRectangle();
        indexedShape = new ShapePair(shape1, shape2, biasContains);
        indexedShapeGS = new ShapePair(gridSnap(shape1), gridSnap(shape2), biasContains);
      } else {
        //just one shape
        indexedShape = randomRectangle();
        indexedShapeGS = gridSnap(indexedShape);
      }
      indexedShapes.put(id, indexedShape);
      indexedShapesGS.put(id, indexedShapeGS);

      adoc(id, indexedShape);

      if (random().nextInt(10) == 0)
        commit();//intermediate commit, produces extra segments

    }
    Iterator<String> idIter = indexedShapes.keySet().iterator();
    while (idIter.hasNext()) {
      String id = idIter.next();
      if (random().nextInt(10) == 0) {
        deleteDoc(id);
        idIter.remove();
        indexedShapesGS.remove(id);
      }
    }

    commit();

    final int numQueryShapes = atLeast(20);
    for (int i = 0; i < numQueryShapes; i++) {
      int scanLevel = randomInt(grid.getMaxLevels());
      ((RecursivePrefixTreeStrategy) strategy).setPrefixGridScanLevel(scanLevel);
      final Shape queryShape = randomRectangle();

      final boolean DISJOINT = operation.equals(SpatialOperation.IsDisjointTo);

      //Generate truth via brute force:
      // We really try to ensure true-positive matches (if the predicate on the raw shapes match
      //  then the search should find those same matches).
      // approximations, false-positive matches
      Set <String> expectedIds = new LinkedHashSet<String>();//true-positives
      Set<String> secondaryIds = new LinkedHashSet<String>();//false-positives (unless disjoint)
      for (Map.Entry<String, Shape> entry : indexedShapes.entrySet()) {
        Shape indexedShapeCompare = entry.getValue();
        if (indexedShapeCompare == null)
          continue;
        Shape queryShapeCompare = queryShape;
        String id = entry.getKey();
        if (operation.evaluate(indexedShapeCompare, queryShapeCompare)) {
          expectedIds.add(id);
          if (DISJOINT) {
            //if no longer intersect after buffering them, for disjoint, remember this
View Full Code Here

      SmallDocSet leafDocs = getLeafDocs(cell, acceptContains);

      // Get the AND of all child results (into combinedSubResults)
      SmallDocSet combinedSubResults = null;
      //   Optimization: use null subCellsFilter when we know cell is within the query shape.
      Shape subCellsFilter = queryShape;
      if (cell.getLevel() != 0 && ((cell.getShapeRel() == null || cell.getShapeRel() == SpatialRelation.WITHIN))) {
        subCellsFilter = null;
        assert cell.getShape().relate(queryShape) == SpatialRelation.WITHIN;
      }
      Collection <Cell> subCells = cell.getSubCells(subCellsFilter);
View Full Code Here

          pair);
      toAdd.setValue(p, Double.parseDouble(o.getLiteralLexicalForm()));
      pairValues.add(toAdd);

    } else if (defn.isWKTPredicate(p) && SpatialValueUtil.isWKTLiteral(o.getLiteral())) {
      @SuppressWarnings("deprecation")
            Shape shape = SpatialQuery.ctx.readShape(o.getLiteralLexicalForm());
      indexer.add(x, shape);
    }
  }
View Full Code Here

TOP

Related Classes of com.spatial4j.core.shape.Shape

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.