示例#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));
  }
示例#2
0
 private static List<Point> createPoints() {
   Point cp = getRandomPoint();
   List<Point> pts = new ArrayList<Point>(5);
   for (int i = 0; i < 5; i++) {
     Point pt = getRingPoint(cp, i, 5, .3, .4);
     assertEquals(1, pt.getNumParts());
     assertEquals(1, pt.getNumPoints());
     assertEquals(pt.asGeodetic2DPoint(), pt.getCenter());
     pts.add(pt);
   }
   return pts;
 }
示例#3
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));
  }
示例#4
0
 protected static Point getRingPoint(Point cp, int n, int total, double size, double min) {
   double lat = cp.getCenter().getLatitudeAsDegrees();
   double lon = cp.getCenter().getLongitudeAsDegrees();
   double theta = Math.toRadians(360.0 * n / total);
   double magnitude = min + RandomUtils.nextDouble() * size;
   double dy = magnitude * Math.sin(theta);
   double dx = magnitude * Math.cos(theta);
   return new Point(lat + dy, lon + dx);
 }
示例#5
0
  @Test
  public void testCircle() {
    Point pt = getRandomPoint();
    Circle c = new Circle(pt.getCenter(), 10000.0);
    assertEquals(pt.asGeodetic2DPoint(), c.getCenter());
    assertFalse(c.is3D());
    Geodetic2DBounds bounds = c.getBoundingBox();
    Assert.assertNotNull(bounds);

    pt = new Point(random3dGeoPoint());
    c = new Circle(pt.getCenter(), 10000.0);
    assertEquals(pt.asGeodetic2DPoint(), c.getCenter());
    assertTrue(c.is3D());
    bounds = c.getBoundingBox();
    assertTrue(bounds instanceof Geodetic3DBounds);
    assertTrue(bounds.contains(pt.asGeodetic2DPoint()));
  }
示例#6
0
 @Test
 public void testNullPointCompare() {
   Point pt = getRandomPoint();
   Point other = null;
   assertFalse(pt.equals(other));
 }