Exemplo n.º 1
0
  @Test
  public void testLinerRing() {
    Point pt = getRandomPoint();
    Geodetic2DBounds bbox = new Geodetic2DBounds(pt.asGeodetic2DPoint());
    bbox.grow(500);
    // System.out.println(bbox);
    LinearRing ring1 = new LinearRing(bbox);

    // create second linear ring centered at north/east edge of the first
    // so it intersects
    bbox = new Geodetic2DBounds(pt.asGeodetic2DPoint());
    bbox.grow(50);
    System.out.println(bbox);
    LinearRing ring2 = new LinearRing(bbox);
    assertTrue(ring1.intersects(ring2));
    assertTrue(ring2.intersects(ring1));

    // create third linear ring at other side of the hemisphere so it cannot intersect
    bbox =
        new Geodetic2DBounds(
            new Geodetic2DPoint(
                new Longitude(-bbox.getEastLon().inRadians()),
                new Latitude(-bbox.getNorthLat().inRadians())));
    bbox.grow(10);
    // System.out.println(bbox);
    LinearRing ring3 = new LinearRing(bbox);
    assertFalse(ring1.intersects(ring3));
    assertFalse(ring1.contains(ring3));
  }
Exemplo n.º 2
0
  @Test
  public void testRegionAtPole() {
    List<Point> pts = new ArrayList<Point>(5);

    // 3km box that closely matches google earth lat/lon grids lines
    // ctr=(65� 0' 0" E, 89� 54' 18" S) -89.905 65.0
    // bbox=(60� 0' 0" E, 89� 54' 36" S) .. (70� 0' 0" E, 89� 54' 0" S)
    final Point firstPt = new Point(-89.90, 70.0);
    pts.add(firstPt);
    pts.add(new Point(-89.90, 60.0));
    pts.add(new Point(-89.91, 60.0));
    pts.add(new Point(-89.91, 70.0));
    pts.add(firstPt);

    Line line = new Line(pts);
    Geodetic2DPoint cp = line.getCenter();
    // System.out.println("Fctr=" + cp + " " + cp.getLatitudeAsDegrees() + " " +
    // cp.getLongitudeAsDegrees());

    LinearRing ring = new LinearRing(pts, true);
    assertEquals(cp, ring.getCenter());

    final Geodetic2DBounds bbox = line.getBoundingBox();
    assertTrue(bbox != null && bbox.contains(cp));

    // System.out.println("bbox=" + bbox);
    assertTrue(
        bbox.getNorthLat().inDegrees()
            > bbox.getSouthLat().inDegrees()); // north=-89.90 south=-89.91
    assertTrue(
        bbox.getWestLon().inDegrees() < bbox.getEastLon().inDegrees()); // west=60.0 east=70.0 degs

    Geodetic2DBounds bounds = new Geodetic2DBounds(bbox);
    bounds.grow(100); // grow 100 bbox meters larger
    assertTrue(bounds.contains(bbox));
    for (Point pt : pts) {
      assertTrue(bounds.contains(pt.asGeodetic2DPoint()));
    }

    // create a bounding box from 1-km MGRS grid that intersects the region
    MGRS mgrs = new MGRS(new MGRS(cp).toString(2)); // BAN0904
    bounds = mgrs.getBoundingBox();
    assertTrue(bounds.intersects(bbox));
    assertTrue(bbox.intersects(bounds));
  }