Ejemplo n.º 1
0
        public Object parseXMLObject(XMLObject xo) throws XMLParseException {

          KMLCoordinates coordinates = (KMLCoordinates) xo.getChild(KMLCoordinates.class);
          boolean closed = xo.getAttribute(CLOSED, false);

          if ((!closed && coordinates.length < 3) || (closed && coordinates.length < 4))
            throw new XMLParseException(
                "Insufficient points in polygon '" + xo.getId() + "' to define a polygon in 2D");

          NewPolygon2D polygon = new NewPolygon2D();
          polygon.moveTo(new Point2D.Double(coordinates.x[0], coordinates.y[0]));
          int length = coordinates.length;
          if (closed) length--;
          for (int i = 1; i < length; i++)
            polygon.lineTo(new Point2D.Double(coordinates.x[i], coordinates.y[i]));
          polygon.lineTo(new Point2D.Double(coordinates.x[0], coordinates.y[0]));
          //            polygon.closePath();

          polygon.setFillValue(xo.getAttribute(FILL_VALUE, 0.0));

          return polygon;
        }
Ejemplo n.º 2
0
  public static void main(String[] args) {
    NewPolygon2D polygon = new NewPolygon2D();
    polygon.moveTo(new Point2D.Double(-10, -10));
    polygon.lineTo(new Point2D.Double(-10, 50));
    polygon.lineTo(new Point2D.Double(10, 50));
    polygon.lineTo(new Point2D.Double(10, -10));
    polygon.lineTo(new Point2D.Double(-10, -10));
    //        polygon.closePath();
    System.out.println(polygon);
    System.out.println("");
    //        System.exit(-1);

    Point2D pt = new Point2D.Double(0, 0);
    System.out.println("polygon contains " + pt + ": " + polygon.contains(pt));
    pt = new Point2D.Double(100, 100);
    System.out.println("polygon contains " + pt + ": " + polygon.contains(pt));
    System.out.println("");

    Rectangle2D boundingBox =
        new Rectangle2D.Double(0, 0, 100, 100); // defines lower-left corner and width/height
    System.out.println(boundingBox);
    NewPolygon2D myClip = polygon.clip(boundingBox);
    System.out.println(myClip);
  }