Package org.geomajas.gwt.client.spatial.geometry

Examples of org.geomajas.gwt.client.spatial.geometry.Polygon


  }

  @Test
  public void testLineStringMiddleIndex() {
    GeometryOperation op = new RemoveRingOperation(1);
    Polygon result = (Polygon) op.execute(polygon);
    Assert.assertEquals(polygon.getNumInteriorRing() - 1, result.getNumInteriorRing());
    Assert.assertEquals(12.0, result.getInteriorRingN(0).getCoordinate().getX(), TOLERANCE);
  }
View Full Code Here


  /**
   * Execute the operation! When the geometry is not a Polygon, null is returned.
   */
  public Geometry execute(Geometry geometry) {
    if (geometry instanceof Polygon) {
      Polygon polygon = (Polygon) geometry;
      if (geometry.isEmpty()) {
        return null;
      } else {
        LinearRing[] interiorRings = new LinearRing[polygon.getNumInteriorRing() + 1];
        int count = 0;
        for (int n = 0; n < interiorRings.length; n++) {
          if (n == index) {
            interiorRings[n] = ring;
          } else {
            interiorRings[n] = polygon.getInteriorRingN(count);
          }
        }
        return geometry.getGeometryFactory().createPolygon(polygon.getExteriorRing(), interiorRings);
      }
    }
    return null;
  }
View Full Code Here

  /**
   * Execute the operation! When the geometry is not a Polygon, null is returned.
   */
  public Geometry execute(Geometry geometry) {
    if (geometry instanceof Polygon) {
      Polygon polygon = (Polygon) geometry;
      if (geometry.isEmpty()) {
        return geometry.getGeometryFactory().createPolygon(ring, null);
      } else {
        LinearRing[] interiorRings = new LinearRing[polygon.getNumInteriorRing() + 1];
        for (int n = 0; n < polygon.getNumInteriorRing(); n++) {
          interiorRings[n] = polygon.getInteriorRingN(n);
        }
        interiorRings[interiorRings.length - 1] = ring;
        return geometry.getGeometryFactory().createPolygon(polygon.getExteriorRing(), interiorRings);
      }
    }
    return null;
  }
View Full Code Here

   * Execute the operation! When the geometry is not a Polygon, null is returned. When the polygon does not have any
   * interior rings, null is returned.
   */
  public Geometry execute(Geometry geometry) {
    if (geometry instanceof Polygon) {
      Polygon polygon = (Polygon) geometry;

      // No rings? return null:
      if (polygon.getNumInteriorRing() == 0) {
        return null;
      }

      // Correct the index if necessary:
      if (ringIndex < 0) {
        ringIndex = 0;
      } else if (ringIndex >= polygon.getNumInteriorRing()) {
        ringIndex = polygon.getNumInteriorRing() - 1;
      }

      // Create the new array of interior rings:
      LinearRing[] interiorRings = new LinearRing[polygon.getNumInteriorRing() - 1];
      int count = 0;
      for (int n = 0; n < polygon.getNumInteriorRing(); n++) {
        if (n != ringIndex) {
          interiorRings[count++] = polygon.getInteriorRingN(n);
        }
      }
      return geometry.getGeometryFactory().createPolygon(polygon.getExteriorRing(), interiorRings);
    }
    return null;
  }
View Full Code Here

  @Test
  public void testPolygon() {
    Feature feature = new Feature();
    feature.setGeometry((Polygon) polygon.clone());
    op.execute(feature);
    Polygon p = (Polygon) feature.getGeometry();
    LinearRing r = p.getInteriorRingN(index.getInteriorRingIndex());
    Assert.assertEquals(60.0, r.getCoordinateN(0).getX(), DELTA);
    op.undo(feature);
    Assert.assertEquals(polygon.toWkt(), feature.getGeometry().toWkt());
  }
View Full Code Here

  public void testMultiPolygon() {
    Feature feature = new Feature();
    feature.setGeometry((MultiPolygon) multiPolygon.clone());
    op.execute(feature);
    MultiPolygon m = (MultiPolygon) feature.getGeometry();
    Polygon p = (Polygon) m.getGeometryN(index.getGeometryIndex());
    LinearRing r = p.getInteriorRingN(index.getInteriorRingIndex());
    Assert.assertEquals(60.0, r.getCoordinateN(0).getX(), DELTA);
    op.undo(feature);
    Assert.assertEquals(multiPolygon.toWkt(), feature.getGeometry().toWkt());
  }
View Full Code Here

  @Test
  public void testPolygon() {
    Feature feature = new Feature();
    feature.setGeometry((Polygon) polygon.clone());
    op.execute(feature);
    Polygon p = (Polygon) feature.getGeometry();
    LinearRing r = p.getInteriorRingN(index.getInteriorRingIndex());
    Assert.assertEquals(20.0, r.getCoordinateN(index.getCoordinateIndex()).getX(), DELTA);
    op.undo(feature);
    Assert.assertEquals(polygon.toWkt(), feature.getGeometry().toWkt());
  }
View Full Code Here

  public void testMultiPolygon() {
    Feature feature = new Feature();
    feature.setGeometry((MultiPolygon) multiPolygon.clone());
    op.execute(feature);
    MultiPolygon m = (MultiPolygon) feature.getGeometry();
    Polygon p = (Polygon) m.getGeometryN(index.getGeometryIndex());
    LinearRing r = p.getInteriorRingN(index.getInteriorRingIndex());
    Assert.assertEquals(20.0, r.getCoordinateN(index.getCoordinateIndex()).getX(), DELTA);
    op.undo(feature);
    Assert.assertEquals(multiPolygon.toWkt(), feature.getGeometry().toWkt());
  }
View Full Code Here

  @Test
  public void testPolygon() {
    Feature feature = new Feature();
    feature.setGeometry((Polygon) polygon.clone());
    op.execute(feature);
    Polygon p = (Polygon) feature.getGeometry();
    LinearRing r = p.getInteriorRingN(index.getInteriorRingIndex());
    Assert.assertEquals(50.0, r.getCoordinateN(r.getNumPoints() - 2).getX(), DELTA);
    op.undo(feature);
    Assert.assertEquals(polygon.toWkt(), feature.getGeometry().toWkt());
  }
View Full Code Here

  public void testMultiPolygon() {
    Feature feature = new Feature();
    feature.setGeometry((MultiPolygon) multiPolygon.clone());
    op.execute(feature);
    MultiPolygon m = (MultiPolygon) feature.getGeometry();
    Polygon p = (Polygon) m.getGeometryN(index.getGeometryIndex());
    LinearRing r = p.getInteriorRingN(index.getInteriorRingIndex());
    Assert.assertEquals(50.0, r.getCoordinateN(r.getNumPoints() - 2).getX(), DELTA);
    op.undo(feature);
    Assert.assertEquals(multiPolygon.toWkt(), feature.getGeometry().toWkt());
  }
View Full Code Here

TOP

Related Classes of org.geomajas.gwt.client.spatial.geometry.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.