Package com.spatial4j.core.shape

Examples of com.spatial4j.core.shape.Point


      @Override
      public double doubleVal(int doc) {
        Shape shape = (Shape) shapeValues.objectVal(doc);
        if (shape == null || shape.isEmpty())
          return nullValue;
        Point pt = shape.getCenter();
        return distCalc.distance(queryPoint, pt) * multiplier;
      }

      @Override
      public Explanation explain(int doc) {
View Full Code Here


    }
    Rectangle bbox = shape.getBoundingBox();
    //Compute the distance from the center to a corner.  Because the distance
    // to a bottom corner vs a top corner can vary in a geospatial scenario,
    // take the closest one (greater precision).
    Point ctr = bbox.getCenter();
    double y = (ctr.getY() >= 0 ? bbox.getMaxY() : bbox.getMinY());
    double diagonalDist = ctx.getDistCalc().distance(ctr, bbox.getMaxX(), y);
    return diagonalDist * distErrPct;
  }
View Full Code Here

   */
  @Test
  public void testDecodePreciseLongitudeLatitude() {
    String hash = GeohashUtils.encodeLatLon(52.3738007, 4.8909347);

    Point point = GeohashUtils.decode(hash,ctx);

    assertEquals(52.3738007, point.getY(), 0.00001D);
    assertEquals(4.8909347, point.getX(), 0.00001D);
  }
View Full Code Here

   */
  @Test
  public void testDecodeImpreciseLongitudeLatitude() {
    String hash = GeohashUtils.encodeLatLon(84.6, 10.5);

    Point point = GeohashUtils.decode(hash, ctx);

    assertEquals(84.6, point.getY(), 0.00001D);
    assertEquals(10.5, point.getX(), 0.00001D);
  }
View Full Code Here

   */
  @Test
  public void testDecodeEncode() {
    String geoHash = "u173zq37x014";
    assertEquals(geoHash, GeohashUtils.encodeLatLon(52.3738007, 4.8909347));
    Point point = GeohashUtils.decode(geoHash,ctx);
    assertEquals(52.37380061d, point.getY(), 0.000001d);
    assertEquals(4.8909343d, point.getX(), 0.000001d);

    assertEquals(geoHash, GeohashUtils.encodeLatLon(point.getY(), point.getX()));

    geoHash = "u173";
    point = GeohashUtils.decode("u173",ctx);
    geoHash = GeohashUtils.encodeLatLon(point.getY(), point.getX());
    final Point point2 = GeohashUtils.decode(geoHash, ctx);
    assertEquals(point.getY(), point2.getY(), 0.000001d);
    assertEquals(point.getX(), point2.getX(), 0.000001d);
  }
View Full Code Here

    assertParses(" POINT (100 90) ", ctx.makePoint(100, 90));//trimmed
    assertParses("point (100 90)", ctx.makePoint(100, 90));//case indifferent
    assertParses("POINT ( 100 90 )", ctx.makePoint(100, 90));//inner spaces
    assertParses("POINT(100 90)", ctx.makePoint(100, 90));
    assertParses("POINT (-45 90 )", ctx.makePoint(-45, 90));
    Point expected = ctx.makePoint(-45.3, 80.4);
    assertParses("POINT (-45.3 80.4 )", expected);
    assertParses("POINT (-45.3 +80.4 )", expected);
    assertParses("POINT (-45.3 8.04e1 )", expected);

    assertParses("POINT EMPTY", ctx.makePoint(Double.NaN, Double.NaN));
View Full Code Here

    assertFails("ENVELOPE (10 30 45 25)");
  }

  @Test
  public void testLineStringShape() throws ParseException {
    Point p1 = ctx.makePoint(1, 10);
    Point p2 = ctx.makePoint(2, 20);
    Point p3 = ctx.makePoint(3, 30);
    Shape ls = ctx.makeLineString(Arrays.asList(p1, p2, p3));
    assertParses("LINESTRING (1 10, 2 20, 3 30)", ls);

    assertParses("LINESTRING EMPTY", ctx.makeLineString(Collections.<Point>emptyList()));
  }
View Full Code Here

  }

  @Test
  public void testSomeDistances() {
    //See to verify: from http://www.movable-type.co.uk/scripts/latlong.html
    Point ctr = pLL(0,100);
    assertEquals(11100, dc().distance(ctr, pLL(10, 0)) * DEG_TO_KM, 3);
    double deg = dc().distance(ctr, pLL(10, -160));
    assertEquals(11100, deg * DEG_TO_KM, 3);

    assertEquals(314.40338, dc().distance(pLL(1, 2), pLL(3, 4)) * DEG_TO_KM, EPS);
View Full Code Here

    DistanceCalculator haversine = new GeodesicSphereDistCalc.Haversine();
    DistanceCalculator lawOfCos = new GeodesicSphereDistCalc.LawOfCosines();

    final int TRIES = 100000 * (int)multiplier();
    for (int i = 0; i < TRIES; i++) {
      Point p1 = randomGeoPoint();
      Point p2 = randomGeoPointFrom(p1);
      double distV = vincenty.distance(p1, p2);

      //Haversine: accurate to a centimeter if on same side of globe,
      // otherwise possibly 1m apart (antipodal)
      double havV = haversine.distance(p1, p2);
View Full Code Here

      distDEG = randomDouble() * 0.001 / Math.pow(10, 10-which);
    } else {
      distDEG = randomDouble()*180;
    }
    double bearingDEG = randomDouble() * 360;
    Point p2RAD = DistanceUtils.pointOnBearingRAD(DistanceUtils.toRadians(p1.getY()), DistanceUtils.toRadians(p1.getX()),
            DistanceUtils.toRadians(distDEG), DistanceUtils.toRadians(bearingDEG), ctx, null);
    p2RAD.reset(DistanceUtils.toDegrees(p2RAD.getX()), DistanceUtils.toDegrees(p2RAD.getY()));
    return p2RAD;//now it's in degrees
  }
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.