Package com.spatial4j.core.shape

Examples of com.spatial4j.core.shape.Point


    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


    checkDistValueSource("4,0", 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
    commit();

    double dist = ctx.getDistCalc().distance(p100, p101);
View Full Code Here

  //     shape = ctx.makeRectangle(shape.getCenter(), shape.getCenter());
  //   return super.newDoc(id, shape);
  // }

  void checkDistValueSource(String ptStr, float... distances) throws IOException {
    Point pt = (Point) ctx.readShape(ptStr);
    float multiplier = random().nextFloat() * 100f;
    float[] dists2 = Arrays.copyOf(distances, distances.length);
    for (int i = 0; i < dists2.length; i++) {
      dists2[i] *= multiplier;
    }
View Full Code Here

    _checkHits(true, ptStr, distKM, assertNumFound, assertIds);
  }

  private void _checkHits(boolean bbox, String ptStr, double distKM, int assertNumFound, int... assertIds) {
    SpatialOperation op = SpatialOperation.Intersects;
    Point pt = (Point) ctx.readShape(ptStr);
    double distDEG = DistanceUtils.dist2Degrees(distKM, DistanceUtils.EARTH_MEAN_RADIUS_KM);
    Shape shape = ctx.makeCircle(pt, distDEG);
    if (bbox)
      shape = shape.getBoundingBox();
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

      assertDocMatchedIds(indexSearcher, docs, 2);
      //Now, lets get the distance for the 1st doc via computing from stored point value:
      // (this computation is usually not redundant)
      Document doc1 = indexSearcher.doc(docs.scoreDocs[0].doc);
      String doc1Str = doc1.getField(strategy.getFieldName()).stringValue();
      Point doc1Point = (Point) ctx.readShape(doc1Str);
      double doc1DistDEG = ctx.getDistCalc().distance(args.getShape().getCenter(), doc1Point);
      assertEquals(121.6d, DistanceUtils.degrees2Dist(doc1DistDEG, DistanceUtils.EARTH_MEAN_RADIUS_KM), 0.1);
    }
    //--Match all, order by distance ascending
    {
      Point pt = ctx.makePoint(60, -50);
      double degToKm = DistanceUtils.degrees2Dist(1, DistanceUtils.EARTH_MEAN_RADIUS_KM);
      ValueSource valueSource = strategy.makeDistanceValueSource(pt, degToKm);//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);
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

        List<Point> points = new ArrayList<Point>();
        for(int i = 0; i < 20; i++) {
          //Note that this will not result in randomly distributed points in the
          // circle, they will be concentrated towards the center a little. But
          // it's good enough.
          Point pt = ctx.getDistCalc().pointOnBearing(clusterCenter,
              random().nextDouble() * radiusDeg, random().nextInt() * 360, ctx, null);
          pt = alignGeohash(pt);
          points.add(pt);
          addDocument(newDoc("" + i, pt));
        }
        commit();

        //3. Use some query centers. Each is twice the cluster's radius away.
        for(int ri = 0; ri < 4; ri++) {
          Point queryCenter = ctx.getDistCalc().pointOnBearing(clusterCenter,
              radiusDeg*2, random().nextInt(360), ctx, null);
          queryCenter = alignGeohash(queryCenter);
          //4.1 Query a small box getting nothing
          checkHits(q(queryCenter, radiusDeg - smallRadius/2), 0, null);
          //4.2 Query a large box enclosing the cluster, getting everything
          checkHits(q(queryCenter, radiusDeg*3 + smallRadius/2), points.size(), null);
          //4.3 Query a medium box getting some (calculate the correct solution and verify)
          double queryDist = radiusDeg * 2;

          //Find matching points.  Put into int[] of doc ids which is the same thing as the index into points list.
          int[] ids = new int[points.size()];
          int ids_sz = 0;
          for (int i = 0; i < points.size(); i++) {
            Point point = points.get(i);
            if (ctx.getDistCalc().distance(queryCenter, point) <= queryDist)
              ids[ids_sz++] = i;
          }
          ids = Arrays.copyOf(ids, ids_sz);
          //assert ids_sz > 0 (can't because randomness keeps us from being able to)
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

  @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

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.