示例#1
0
  @Test
  public void testLineBBox() {
    double lat = 40.0 + (5.0 * RandomUtils.nextDouble());
    double lon = 40.0 + (5.0 * RandomUtils.nextDouble());
    Geodetic2DPoint pt1 =
        new Geodetic2DPoint(new Longitude(lon, Angle.DEGREES), new Latitude(lat, Angle.DEGREES));
    Geodetic2DBounds bbox = new Geodetic2DBounds(pt1);
    try {
      // single point bbox - line requires at least 2 points
      new Line(bbox);
      fail("Expected to throw Exception");
    } catch (IllegalArgumentException iae) {
      // expected
    }
    try {
      new LinearRing(bbox); // ring requires at least 4 points
      fail("Expected to throw Exception");
    } catch (IllegalArgumentException iae) {
      // expected
    }

    Geodetic2DPoint pt2 =
        new Geodetic2DPoint(new Longitude(lon + 10, Angle.DEGREES), pt1.getLatitude());
    bbox = new Geodetic2DBounds(pt1, pt2);
    Line line = new Line(bbox);
    assertEquals(2, line.getNumPoints());
    try {
      // 2-point line bbox - ring requires at least 4 points
      new LinearRing(bbox);
      fail("Expected to throw Exception");
    } catch (IllegalArgumentException iae) {
      // expected
    }

    Geodetic2DPoint pt3 =
        new Geodetic2DPoint(pt1.getLongitude(), new Latitude(lat + 10, Angle.DEGREES));
    bbox = new Geodetic2DBounds(pt1, pt3);
    line = new Line(bbox);
    assertEquals(2, line.getNumPoints());
    try {
      // 2-point line bbox - ring requires at least 4 points
      new LinearRing(bbox);
      fail("Expected to throw Exception");
    } catch (IllegalArgumentException iae) {
      // expected
    }

    Geodetic2DPoint pt4 = new Geodetic2DPoint(pt2.getLongitude(), pt3.getLatitude());
    line = new Line(new Geodetic2DBounds(pt1, pt4));
    assertEquals(5, line.getNumPoints());
  }
示例#2
0
  @Test
  public void testPointLineCreation() {
    List<Point> pts = createPoints();

    // construct MultiPoint
    MultiPoint mp = new MultiPoint(pts);
    assertEquals(pts.size(), mp.getNumParts());
    assertEquals(pts.size(), mp.getNumPoints());
    assertFalse(mp.is3D());

    // construct Line
    Line line = new Line(new ArrayList<Point>(pts));
    assertEquals(1, line.getNumParts());
    assertEquals(pts.size(), line.getNumPoints());
    assertFalse(line.is3D());

    Iterator<Point> it1 = line.iterator();
    Iterator<Point> it2 = mp.iterator();
    while (it1.hasNext() && it2.hasNext()) {
      assertEquals(it1.next(), it2.next());
    }
    assertFalse(it1.hasNext());
    assertFalse(it2.hasNext());

    List<Point> linePts = line.getPoints();
    List<Point> multiPts = mp.getPoints();
    assertEquals(linePts.size(), multiPts.size());
    for (int i = 0; i < linePts.size(); i++) {
      assertEquals(linePts.get(i), multiPts.get(i));
    }

    assertEquals(mp.getCenter(), line.getCenter());
  }