Esempio n. 1
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());
  }
Esempio 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));
  }
Esempio n. 3
0
  @Test
  public void testClippedAtDateLine() {
    // create outline of Fiji islands which wrap international date line
    List<Point> pts = new ArrayList<Point>();
    final Point firstPt = new Point(-16.68226928264316, 179.900033693558);
    pts.add(firstPt);
    pts.add(new Point(-16.68226928264316, -180));
    pts.add(new Point(-17.01144405215603, -180));
    pts.add(new Point(-17.01144405215603, 179.900033693558));
    pts.add(firstPt);
    Line line = new Line(pts);
    assertTrue(line.clippedAtDateLine());

    // (179� 57' 0" E, 16� 50' 49" S)
    Geodetic2DPoint cp = line.getCenter();
    // System.out.println("Fctr=" + cp.getLatitudeAsDegrees() + " " + cp.getLongitudeAsDegrees());
    assertEquals(-16.846856667399592, cp.getLatitudeAsDegrees(), EPSILON);
    assertEquals(179.950016846779, cp.getLongitudeAsDegrees(), EPSILON);

    LinearRing ring = new LinearRing(pts, true);
    assertTrue(ring.clippedAtDateLine());
    assertEquals(cp, ring.getCenter());
  }
Esempio n. 4
0
  @Test
  public void testAtPoles() {
    // create outline of antarctica
    List<Point> pts = new ArrayList<Point>(5);
    final Point firstPt = new Point(-64.2378603202, -57.1573913081);
    pts.add(firstPt);
    pts.add(new Point(-70.2956070281, 26.0747738693));
    pts.add(new Point(-66.346745474, 129.2349114494));
    pts.add(new Point(-72.8459462179, -125.7310989568));
    pts.add(firstPt);
    Line line = new Line(pts);

    Geodetic2DPoint cp = line.getCenter();
    // (1� 45' 7" E, 68� 32' 31" S) -68.54190326905 1.7519062462999895
    // System.out.println("Fctr=" + cp + " " + cp.getLatitudeAsDegrees() + " " +
    // cp.getLongitudeAsDegrees());

    Geodetic2DBounds bbox = line.getBoundingBox();
    // bbox=(125� 43' 52" W, 72� 50' 45" S) .. (129� 14' 6" E, 64� 14' 16" S)
    assertTrue(bbox != null && bbox.contains(cp));

    // LinearRing ring = new LinearRing(pts, true); // -> Error: LinearRing cannot self-intersect
    // assertEquals(cp, ring.getCenter());
  }