Esempio n. 1
0
 @Test
 public void testNullLineCompare() {
   List<Point> pts = createPoints();
   Line line = new Line(pts);
   Line other = null;
   assertFalse(line.equals(other));
 }
Esempio n. 2
0
  /** Construct mixed dimension MultiLine (2d + 3d Lines) which downgrades to 2d. */
  @Test
  public void testMixedMultiLine() {
    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, 500));
    }
    Line line = new Line(pts);
    line.setAltitudeMode(AltitudeModeEnumType.absolute);
    line.setTessellate(true);
    assertTrue(line.is3D());
    lines.add(line);

    pts = new ArrayList<Point>();
    for (int i = 0; i < 10; i++) {
      pts.add(new Point(i * .03 + 0.3, i * .03 + 0.3)); // 2-d points
    }
    line = new Line(pts);
    line.setTessellate(false);
    lines.add(line);
    MultiLine geo = new MultiLine(lines);
    assertEquals(2, geo.getNumParts());
    assertEquals(20, geo.getNumPoints());
    assertFalse(geo.is3D());
  }
Esempio n. 3
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());
  }
Esempio n. 4
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());
  }
Esempio n. 5
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. 6
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. 7
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. 8
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());
  }
Esempio n. 9
0
  /**
   * Create array of features with all possible MultiGeometry geometries: MultiPoint, MultiLine,
   * MultiLinearRings, MultiPolygons, GeometryBag
   *
   * @return
   */
  protected static List<Feature> getMultiGeometries() {
    List<Feature> feats = new ArrayList<Feature>();

    List<Line> lines = new ArrayList<Line>();
    List<Point> pts = new ArrayList<Point>(10);
    for (int i = 0; i < 10; i++) {
      pts.add(new Point(i * .01, i * .01));
    }

    Geometry g = new MultiPoint(pts);
    feats.add(addFeature(g)); // MultiPoint

    Geodetic2DPoint center = g.getCenter();
    GeometryBag bag = new GeometryBag();
    bag.add(new Point(center));
    bag.addAll(pts);
    feats.add(addFeature(bag)); // GeometryBag with all points

    Line line = new Line(pts);
    line.setTessellate(true);
    lines.add(line);
    pts = new ArrayList<Point>(10);
    for (int i = 0; i < 10; i++) {
      pts.add(new Point(i * .01 + 0.1, i * .01 + 0.1));
    }
    line = new Line(pts);
    line.setTessellate(true);
    lines.add(line);
    g = new MultiLine(lines);
    feats.add(addFeature(g)); // MultiLine

    List<LinearRing> rings = new ArrayList<LinearRing>(5);
    pts = new ArrayList<Point>();
    pts.add(new Point(.10, .20));
    pts.add(new Point(.10, .10));
    pts.add(new Point(.20, .10));
    pts.add(new Point(.20, .20));
    pts.add(pts.get(0)); // add first as last
    LinearRing ring = new LinearRing(pts);
    rings.add(ring);
    List<Point> pts2 = new ArrayList<Point>(5);
    pts2.add(new Point(.05, .25));
    pts2.add(new Point(.05, .05));
    pts2.add(new Point(.25, .05));
    pts2.add(new Point(.25, .25));
    pts2.add(pts2.get(0)); // add first as last
    rings.add(new LinearRing(pts2));
    g = new MultiLinearRings(rings);
    feats.add(addFeature(g)); // MultiLinearRings w/2 rings

    pts = new ArrayList<Point>(5);
    pts.add(new Point(.10, .10));
    pts.add(new Point(.10, -.10));
    pts.add(new Point(-.10, -.10));
    pts.add(new Point(-.10, .10));
    pts.add(pts.get(0)); // add first as last
    LinearRing outer = new LinearRing(pts);
    pts = new ArrayList<Point>(5);
    pts.add(new Point(.05, .05));
    pts.add(new Point(.05, -.05));
    pts.add(new Point(-.05, -.05));
    pts.add(new Point(-.05, .05));
    pts.add(pts.get(0)); // add first as last
    List<LinearRing> innerRings = Collections.singletonList(new LinearRing(pts));
    Polygon p = new Polygon(outer, innerRings);
    g = new MultiPolygons(Arrays.asList(new Polygon(ring), p));
    feats.add(addFeature(g)); // MultiPolygons with 2 polygons

    Circle circle = new Circle(pts.get(0).getCenter(), 50);
    g = new GeometryBag(Arrays.asList((Geometry) pts.get(0), circle));
    feats.add(addFeature(g)); // GeometryBag with point and Circle

    return feats;
  }