예제 #1
0
  @Test
  public void testMultiLine() {
    List<Line> lines = new ArrayList<Line>();
    List<Point> pts = new ArrayList<Point>();
    for (int i = 0; i < 10; i++) {
      pts.add(new Point(i * .01 + 0.1, i * .01 + 0.1, true)); // sets 0.0 elevation
    }
    Line line = new Line(pts);
    line.setTessellate(false);
    line.setAltitudeMode(AltitudeModeEnumType.clampToGround);
    lines.add(line);
    pts = new ArrayList<Point>();
    for (int i = 0; i < 10; i++) {
      pts.add(new Point(i * .02 + 0.2, i * .02 + 0.2, 100));
    }
    line = new Line(pts);
    line.setTessellate(true);
    lines.add(line);
    Geometry geo = new MultiLine(lines);
    assertEquals(2, geo.getNumParts());
    assertEquals(20, geo.getNumPoints());
    assertTrue(geo.is3D());
    Geodetic2DBounds bounds = geo.getBoundingBox();
    assertTrue(bounds instanceof Geodetic3DBounds);
    // bounding box of MultiLine must contain bounding box for each of its lines
    assertTrue(bounds.contains(line.getBoundingBox()));

    // (0� 14' 24" E, 0� 14' 24" N) @ 0m
    final Geodetic2DPoint cp = geo.getCenter();
    System.out.println("multiline center=" + cp);
    assertEquals(0.24, cp.getLatitudeAsDegrees(), EPSILON);
    assertEquals(0.24, cp.getLongitudeAsDegrees(), EPSILON);

    List<Point> points = geo.getPoints(); // all 20 points
    assertEquals(20, points.size());
    for (int i = 0; i < 10; i++) {
      assertEquals(pts.get(i), points.get(i + 10));
    }

    List<Geometry> geometries = new ArrayList<Geometry>();
    geometries.add(pts.get(0));
    geometries.add(line);
    geo = new GeometryBag(geometries);
    assertEquals(2, geo.getNumParts());
    assertTrue(geo.is3D());
  }
예제 #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));
  }
예제 #3
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());
  }