示例#1
0
  @Test
  public void toGeometry_Shape_Poly() {
    Shape shape = new Polygon(XPOINTS, YPOINTS, NPOINTS);
    Geometry geom = JTS.toGeometry(shape);
    assertTrue(geom instanceof LinearRing);

    Coordinate[] coords = geom.getCoordinates();
    assertEquals(NPOINTS + 1, coords.length);

    CoordList list = new CoordList(coords);
    Coordinate c = new Coordinate();
    for (int i = 0; i < NPOINTS; i++) {
      c.x = XPOINTS[i];
      c.y = YPOINTS[i];
      assertTrue(list.contains(c));
    }
  }
示例#2
0
  @Test
  public void toGeometry_Shape_Line() {
    GeneralPath path = new GeneralPath();

    path.moveTo(XPOINTS[0], YPOINTS[0]);
    for (int i = 1; i < NPOINTS; i++) {
      path.lineTo(XPOINTS[i], YPOINTS[i]);
    }

    Geometry geom = JTS.toGeometry(path);
    assertTrue(geom instanceof LineString);

    Coordinate[] coords = geom.getCoordinates();
    assertEquals(NPOINTS, coords.length);

    CoordList list = new CoordList(coords);
    Coordinate c = new Coordinate();
    for (int i = 0; i < NPOINTS; i++) {
      c.x = XPOINTS[i];
      c.y = YPOINTS[i];
      assertTrue(list.contains(c));
    }
  }