Package com.spatial4j.core.shape

Examples of com.spatial4j.core.shape.Shape


  @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


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

  @Test
  public void testMultiLineStringShape() throws ParseException {
    Shape s = ctx.makeCollection(Arrays.asList(
       ctx.makeLineString(Arrays.asList(
            ctx.makePoint(10, 10), ctx.makePoint(20, 20), ctx.makePoint(10, 40))),
        ctx.makeLineString(Arrays.asList(
            ctx.makePoint(40, 40), ctx.makePoint(30, 30), ctx.makePoint(40, 20), ctx.makePoint(30, 10)))
    ));
View Full Code Here

    assertParses("MULTILINESTRING M EMPTY", ctx.makeCollection(Collections.EMPTY_LIST));
  }

  @Test
  public void testGeomCollection() throws ParseException {
    Shape s1 = ctx.makeCollection(Arrays.asList(ctx.makePoint(1, 2)));
    Shape s2 = ctx.makeCollection(
        Arrays.asList(ctx.makeRectangle(1, 2, 3, 4),
            ctx.makePoint(-1, -2)) );
    assertParses("GEOMETRYCOLLECTION (POINT (1 2) )", s1);
    assertParses("GEOMETRYCOLLECTION ( ENVELOPE(1,2,4,3), POINT(-1 -2)) ", s2);
View Full Code Here

    return (T) ctx.readShape( buff );
  }

  @Test
  public void testPoint() throws IOException {
    Shape s = ctx.readShape("10 20");
    assertEquals(ctx.makePoint(10,20),s);
    assertEquals(s,writeThenRead(s));
    assertEquals(s,ctx.readShape("20,10"));//check comma for y,x format
    assertEquals(s,ctx.readShape("20, 10"));//test space
    assertFalse(s.hasArea());
  }
View Full Code Here

    assertFalse(s.hasArea());
  }

  @Test
  public void testRectangle() throws IOException {
    Shape s = ctx.readShape("-10 -20 10 20");
    assertEquals(ctx.makeRectangle(-10, 10, -20, 20),s);
    assertEquals(s,writeThenRead(s));
    assertTrue(s.hasArea());
  }
View Full Code Here

    assertTrue(s.hasArea());
  }

  @Test
  public void testCircle() throws IOException {
    Shape s = ctx.readShape("Circle(1.23 4.56 distance=7.89)");
    assertEquals(ctx.makeCircle(1.23, 4.56, 7.89),s);
    assertEquals(s,writeThenRead(s));
    assertEquals(s,ctx.readShape("CIRCLE( 4.56,1.23 d=7.89 )")); // use lat,lon and use 'd' abbreviation
    assertTrue(s.hasArea());
  }
View Full Code Here

    final double DEP = 0.5;//distErrPct

    //the result is the diagonal distance from the center to the closest corner,
    // times distErrPct

    Shape superwide = ctx.makeRectangle(-180, 180, 0, 0);
    //0 distErrPct means 0 distance always
    assertEquals(0, SpatialArgs.calcDistanceFromErrPct(superwide, 0, ctx), 0);
    assertEquals(180 * DEP, SpatialArgs.calcDistanceFromErrPct(superwide, DEP, ctx), 0);

    Shape supertall = ctx.makeRectangle(0, 0, -90, 90);
    assertEquals(90 * DEP, SpatialArgs.calcDistanceFromErrPct(supertall, DEP, ctx), 0);

    Shape upperhalf = ctx.makeRectangle(-180, 180, 0, 90);
    assertEquals(45 * DEP, SpatialArgs.calcDistanceFromErrPct(upperhalf, DEP, ctx), 0.0001);

    Shape midCircle = ctx.makeCircle(0, 0, 45);
    assertEquals(60 * DEP, SpatialArgs.calcDistanceFromErrPct(midCircle, DEP, ctx), 0.0001);
  }
View Full Code Here

    commit();
    deleteDoc("999");
    commit();

    double dist = ctx.getDistCalc().distance(p100, p101);
    Shape queryShape = ctx.makeCircle(2.01, 0.99, dist);
    checkValueSource(strategy.makeRecipDistanceValueSource(queryShape),
        new float[]{1.00f, 0.10f, 0f}, 0.09f);
  }
View Full Code Here

  }

  private void _checkHits(boolean bbox, Point pt, double distKM, int assertNumFound, int... assertIds) {
    SpatialOperation op = SpatialOperation.Intersects;
    double distDEG = DistanceUtils.dist2Degrees(distKM, DistanceUtils.EARTH_MEAN_RADIUS_KM);
    Shape shape = ctx.makeCircle(pt, distDEG);
    if (bbox)
      shape = shape.getBoundingBox();

    SpatialArgs args = new SpatialArgs(op,shape);
    //args.setDistPrecision(0.025);
    Query query;
    if (random().nextBoolean()) {
View Full Code Here

    assertTrue(34*distMult < DIST);
    checkHits(q(qPt, 34 * KM2DEG, distErrPct), 0, null);
  }

  private SpatialArgs q(Point pt, double distDEG, double distErrPct) {
    Shape shape = ctx.makeCircle(pt, distDEG);
    SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects,shape);
    args.setDistErrPct(distErrPct);
    return args;
  }
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.