Ejemplo n.º 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());
  }
Ejemplo n.º 2
0
 private static Feature addFeature(Geometry g) {
   Feature f = new Feature();
   f.setName(Integer.toString(++id));
   /*
   String type = g.getClass().getName();
   int ind = type.lastIndexOf('.');
   if (ind > 0) type = type.substring(ind + 1);
   */
   f.setDescription(g.toString());
   f.setGeometry(g);
   return f;
 }
Ejemplo n.º 3
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;
  }