Package org.geomajas.puregwt.client.spatial

Examples of org.geomajas.puregwt.client.spatial.Polygon


  }

  private Path toPath(MultiPolygon multiPolygon) {
    Path path = toPath((Polygon) multiPolygon.getGeometryN(0));
    for (int g = 1; g < multiPolygon.getNumGeometries(); g++) {
      Polygon polygon = (Polygon) multiPolygon.getGeometryN(g);

      LinearRing exteriorRing = polygon.getExteriorRing();
      path.moveTo((int) exteriorRing.getCoordinate().getX(), (int) exteriorRing.getCoordinate().getY());
      for (int i = 1; i < exteriorRing.getNumPoints() - 1; i++) {
        Coordinate coordinate = exteriorRing.getCoordinateN(i);
        path.lineTo((int) coordinate.getX(), (int) coordinate.getY());
      }
      path.close();

      for (int i = 0; i < polygon.getNumInteriorRing(); i++) {
        LinearRing interiorRing = polygon.getInteriorRingN(i);
        path.moveTo((int) interiorRing.getCoordinate().getX(), (int) interiorRing.getCoordinate().getY());
        for (int j = 1; j < interiorRing.getNumPoints() - 1; j++) {
          Coordinate coordinate = interiorRing.getCoordinateN(j);
          path.lineTo((int) coordinate.getX(), (int) coordinate.getY());
        }
View Full Code Here


        for (int i = 0; i < coordinates.length; i++) {
          coordinates[i] = worldToScreen(geometry.getCoordinates()[i]);
        }
        return factory.createLineString(coordinates);
      } else if (geometry instanceof Polygon) {
        Polygon polygon = (Polygon) geometry;
        LinearRing shell = (LinearRing) worldToScreen(polygon.getExteriorRing());
        LinearRing[] holes = new LinearRing[polygon.getNumInteriorRing()];
        for (int n = 0; n < polygon.getNumInteriorRing(); n++) {
          holes[n] = (LinearRing) worldToScreen(polygon.getInteriorRingN(n));
        }
        return factory.createPolygon(shell, holes);
      } else if (geometry instanceof MultiPoint) {
        Point[] points = new Point[geometry.getNumGeometries()];
        for (int n = 0; n < geometry.getNumGeometries(); n++) {
View Full Code Here

        for (int i = 0; i < coordinates.length; i++) {
          coordinates[i] = screenToWorld(geometry.getCoordinates()[i]);
        }
        return factory.createLineString(coordinates);
      } else if (geometry instanceof Polygon) {
        Polygon polygon = (Polygon) geometry;
        LinearRing shell = (LinearRing) screenToWorld(polygon.getExteriorRing());
        LinearRing[] holes = new LinearRing[polygon.getNumInteriorRing()];
        for (int n = 0; n < polygon.getNumInteriorRing(); n++) {
          holes[n] = (LinearRing) screenToWorld(polygon.getInteriorRingN(n));
        }
        return factory.createPolygon(shell, holes);
      } else if (geometry instanceof MultiPoint) {
        Point[] points = new Point[geometry.getNumGeometries()];
        for (int n = 0; n < geometry.getNumGeometries(); n++) {
View Full Code Here

    } else if (geometry instanceof LineString) {
      dto = new Geometry(Geometry.LINE_STRING, 0, 0);
      dto.setCoordinates(geometry.getCoordinates());
    } else if (geometry instanceof Polygon) {
      dto = new Geometry(Geometry.POLYGON, 0, 0);
      Polygon polygon = (Polygon) geometry;
      Geometry[] geometries = new Geometry[polygon.getNumInteriorRing() + 1];
      for (int i = 0; i < geometries.length; i++) {
        if (i == 0) {
          geometries[i] = toDto(polygon.getExteriorRing());
        } else {
          geometries[i] = toDto(polygon.getInteriorRingN(i - 1));
        }
      }
      dto.setGeometries(geometries);
    } else if (geometry instanceof MultiPoint) {
      dto = new Geometry(Geometry.MULTI_POINT, 0, 0);
View Full Code Here

  public void testTransformPolygon() {
    LinearRing shell = factory.createLinearRing(new Coordinate[] { new Coordinate(-10, -10), new Coordinate(10, 0),
        new Coordinate(-10, 10), new Coordinate(-10, -10) });
    LinearRing hole = factory.createLinearRing(new Coordinate[] { new Coordinate(-5, -5), new Coordinate(5, 0),
        new Coordinate(-5, 5), new Coordinate(-5, -5) });
    Polygon polygon = factory.createPolygon(shell, new LinearRing[] { hole });

    // World to screen:
    Polygon result = (Polygon) viewPort.transform(polygon, RenderSpace.WORLD, RenderSpace.SCREEN);
    Coordinate c = result.getExteriorRing().getCoordinates()[0];
    Assert.assertEquals((MAP_WIDTH / 2) - (viewPort.getScale() * 10), c.getX(), DELTA);
    Assert.assertEquals((MAP_HEIGHT / 2) + (viewPort.getScale() * 10), c.getY(), DELTA);
    c = result.getExteriorRing().getCoordinates()[1];
    Assert.assertEquals((MAP_WIDTH / 2) + (viewPort.getScale() * 10), c.getX(), DELTA);
    Assert.assertEquals((MAP_HEIGHT / 2), c.getY(), DELTA);
    c = result.getInteriorRingN(0).getCoordinates()[2];
    Assert.assertEquals((MAP_WIDTH / 2) - (viewPort.getScale() * 5), c.getX(), DELTA);
    Assert.assertEquals((MAP_HEIGHT / 2) - (viewPort.getScale() * 5), c.getY(), DELTA);

    // Screen to world:
    result = (Polygon) viewPort.transform(result, RenderSpace.SCREEN, RenderSpace.WORLD);
    c = result.getExteriorRing().getCoordinates()[0];
    Assert.assertEquals(-10.0, c.getX(), DELTA);
    Assert.assertEquals(-10.0, c.getY(), DELTA);
    c = result.getExteriorRing().getCoordinates()[1];
    Assert.assertEquals(10, c.getX(), DELTA);
    Assert.assertEquals(0, c.getY(), DELTA);
    c = result.getInteriorRingN(0).getCoordinates()[2];
    Assert.assertEquals(-5.0, c.getX(), DELTA);
    Assert.assertEquals(5.0, c.getY(), DELTA);
  }
View Full Code Here

  public void testTransformMultiPolygon() {
    LinearRing shell = factory.createLinearRing(new Coordinate[] { new Coordinate(-10, -10), new Coordinate(10, 0),
        new Coordinate(-10, 10), new Coordinate(-10, -10) });
    LinearRing hole = factory.createLinearRing(new Coordinate[] { new Coordinate(-5, -5), new Coordinate(5, 0),
        new Coordinate(-5, 5), new Coordinate(-5, -5) });
    Polygon polygon = factory.createPolygon(shell, new LinearRing[] { hole });
    MultiPolygon mp = factory.createMultiPolygon(new Polygon[] { polygon });

    // World to screen:
    Geometry result = viewPort.transform(mp, RenderSpace.WORLD, RenderSpace.SCREEN);
    Coordinate c = result.getGeometryN(0).getGeometryN(0).getCoordinates()[0];
View Full Code Here

TOP

Related Classes of org.geomajas.puregwt.client.spatial.Polygon

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.