Package com.spatial4j.core.shape

Examples of com.spatial4j.core.shape.Point


  @Test
  public void testCalcBoxByDistFromPt() {
    //first test regression
    {
      double d = 6894.1 * KM_TO_DEG;
      Point pCtr = pLL(-20, 84);
      Point pTgt = pLL(-42, 15);
      assertTrue(dc().distance(pCtr, pTgt) < d);
      //since the pairwise distance is less than d, a bounding box from ctr with d should contain pTgt.
      Rectangle r = dc().calcBoxByDistFromPt(pCtr, d, ctx, null);
      assertEquals(SpatialRelation.CONTAINS,r.relate(pTgt));
      checkBBox(pCtr,d);
    }

    assertEquals("0 dist, horiz line",
        -45,dc().calcBoxByDistFromPt_yHorizAxisDEG(ctx.makePoint(-180, -45), 0, ctx),0);

    double MAXDIST = (double) 180 * DEG_TO_KM;
    checkBBox(ctx.makePoint(0,0), MAXDIST);
    checkBBox(ctx.makePoint(0,0), MAXDIST *0.999999);
    checkBBox(ctx.makePoint(0,0),0);
    checkBBox(ctx.makePoint(0,0),0.000001);
    checkBBox(ctx.makePoint(0,90),0.000001);
    checkBBox(ctx.makePoint(-32.7,-5.42),9829);
    checkBBox(ctx.makePoint(0,90-20), (double) 20 * DEG_TO_KM);
    {
      double d = 0.010;//10m
      checkBBox(ctx.makePoint(0,90- (d + 0.001) * KM_TO_DEG),d);
    }

    for (int T = 0; T < 100; T++) {
      double lat = -90 + randomDouble()*180;
      double lon = -180 + randomDouble()*360;
      Point ctr = ctx.makePoint(lon, lat);
      double dist = MAXDIST*randomDouble();
      checkBBox(ctr, dist);
    }

  }
View Full Code Here


      double deg = dc().distance(ctr, r.getMinX(), r.getMaxY() == 90 ? 90 : -90);
      double calcDistKm = deg * DEG_TO_KM;
      assertTrue(msg, calcDistKm <= distKm + EPS);
      //horizAxisLat is meaningless in this context
    } else {
      Point tPt = findClosestPointOnVertToPoint(r.getMinX(), r.getMinY(), r.getMaxY(), ctr);
      double calcDistKm = dc().distance(ctr, tPt) * DEG_TO_KM;
      assertEquals(msg, distKm, calcDistKm, EPS);
      assertEquals(msg, tPt.getY(), horizAxisLat, EPS);
    }

    //vertical
    double topDistKm = dc().distance(ctr, ctr.getX(), r.getMaxY()) * DEG_TO_KM;
    if (r.getMaxY() == 90)
View Full Code Here

    }
  }

  private void testDistCalcPointOnBearing(double distKm) {
    for(int angDEG = 0; angDEG < 360; angDEG += randomIntBetween(1,20)) {
      Point c = ctx.makePoint(
              DistanceUtils.normLonDEG(randomInt(359)),
              randomIntBetween(-90,90));

      //0 distance means same point
      Point p2 = dc().pointOnBearing(c, 0, angDEG, ctx, null);
      assertEquals(c,p2);

      p2 = dc().pointOnBearing(c, distKm * KM_TO_DEG, angDEG, ctx, null);
      double calcDistKm = dc().distance(c, p2) * DEG_TO_KM;
      assertEqualsRatio(distKm, calcDistKm);
View Full Code Here

    checkDistValueSource(ctx.makePoint(0, 4), 3.6043684f, 0.9975641f, 180f);
  }

  @Test
  public void testRecipScore() throws IOException {
    Point p100 = ctx.makePoint(2, 1);
    adoc("100", p100);
    Point p101 = ctx.makePoint(-1, 4);
    adoc("101", p101);
    adoc("103", (Shape)null);//test score for nothing
    adoc("999", ctx.makePoint(2, 1));//test deleted
    commit();
    deleteDoc("999");
View Full Code Here

      for (IndexableField f : strategy.createIndexableFields(shape)) {
        doc.add(f);
      }
      //store it too; the format is up to you
      //  (assume point in this example)
      Point pt = (Point) shape;
      doc.add(new StoredField(strategy.getFieldName(), pt.getX()+" "+pt.getY()));
    }

    return doc;
  }
View Full Code Here

      //or more simply:
      assertEquals(121.6d, doc1DistDEG * DistanceUtils.DEG_TO_KM, 0.1);
    }
    //--Match all, order by distance ascending
    {
      Point pt = ctx.makePoint(60, -50);
      ValueSource valueSource = strategy.makeDistanceValueSource(pt, DistanceUtils.DEG_TO_KM);//the distance (in km)
      Sort distSort = new Sort(valueSource.getSortField(false)).rewrite(indexSearcher);//false=asc dist
      TopDocs docs = indexSearcher.search(new MatchAllDocsQuery(), 10, distSort);
      assertDocMatchedIds(indexSearcher, docs, 4, 20, 2);
      //To get the distance, we could compute from stored values like earlier.
View Full Code Here

  @Test
  public void testPrecision() throws IOException{
    init(GeohashPrefixTree.getMaxLevelsPossible());

    Point iPt = ctx.makePoint(2.8028712999999925, 48.3708044);//lon, lat
    addDocument(newDoc("iPt", iPt));
    commit();

    Point qPt = ctx.makePoint(2.4632387000000335, 48.6003516);

    final double KM2DEG = DistanceUtils.dist2Degrees(1, DistanceUtils.EARTH_MEAN_RADIUS_KM);
    final double DEG2KM = 1 / KM2DEG;

    final double DIST = 35.75;//35.7499...
View Full Code Here

    for (Field field : fields) {
      doc.add(field)
    }
    addDocument(doc);

    Point upperleft = ctx.makePoint(-122.88, 48.54);
    Point lowerright = ctx.makePoint(-122.82, 48.62);
   
    Query query = strategy.makeQuery(new SpatialArgs(SpatialOperation.Intersects, ctx.makeRectangle(upperleft, lowerright)));
    commit();
   
    TopDocs search = indexSearcher.search(query, 10);
View Full Code Here

    return new ShapeConverter() {
      @Override
      public Shape convert(Shape shape) {
        if (shape instanceof Point && (radiusDegrees != 0.0 || plusMinus != 0.0)) {
          Point point = (Point)shape;
          double radius = radiusDegrees;
          if (plusMinus > 0.0) {
            Random random = new Random(point.hashCode());//use hashCode so it's reproducibly random
            radius += random.nextDouble() * 2 * plusMinus - plusMinus;
            radius = Math.abs(radius);//can happen if configured plusMinus > radiusDegrees
          }
          shape = spatialStrategy.getSpatialContext().makeCircle(point, radius);
        }
View Full Code Here

    assertNotNull(query);
  }

  @Test(expected = UnsupportedOperationException.class)
  public void testInvalidQueryShape() {
    Point point = ctx.makePoint(0, 0);
    SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, point);
    this.strategy.makeQuery(args);
  }
View Full Code Here

TOP

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

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.