/**
  * Overrides {@linkplain GridFeatureBuilder#setAttributes(GridElement, Map)} to assign a
  * sequential integer id value to each grid element feature as it is constructed.
  *
  * @param el the element from which the new feature is being constructed
  * @param attributes a {@code Map} with the single key "id"
  */
 @Override
 public void setAttributes(GridElement ge, Map<String, Object> attributes) {
   PolygonElement pe = (PolygonElement) ge;
   attributes.put("id", id);
   attributes.put("centerX", pe.getCenter().x);
   attributes.put("centerY", pe.getCenter().y);
 }
Beispiel #2
0
  @Test
  public void toDenseGeometry() {
    PolygonElement oblong = new OblongImpl(0, 0, WIDTH, HEIGHT, null);

    final int density = 10;
    final double maxSpacing = Math.min(WIDTH, HEIGHT) / density;

    Geometry polygon = oblong.toDenseGeometry(maxSpacing);
    assertNotNull(polygon);
    assertTrue(polygon instanceof Polygon);
    assertTrue(polygon.getCoordinates().length - 1 >= 2 * (WIDTH + HEIGHT) * density);
  }
Beispiel #3
0
  @Test
  public void toGeometry() {
    PolygonElement oblong = new OblongImpl(MINX, MINY, WIDTH, HEIGHT, null);
    Geometry polygon = oblong.toGeometry();
    assertNotNull(polygon);
    assertTrue(polygon instanceof Polygon);

    Set<Coordinate> polyCoords = new HashSet<Coordinate>(Arrays.asList(polygon.getCoordinates()));
    for (Coordinate c : oblong.getVertices()) {
      assertTrue(polyCoords.contains(c));
    }
  }
Beispiel #4
0
  @Test
  public void getVertices() {
    PolygonElement oblong = new OblongImpl(MINX, MINY, WIDTH, HEIGHT, null);
    Coordinate[] expected = {
      new Coordinate(MINX, MINY),
      new Coordinate(MINX, MINY + HEIGHT),
      new Coordinate(MINX + WIDTH, MINY + HEIGHT),
      new Coordinate(MINX + WIDTH, MINY),
    };

    Coordinate[] actual = oblong.getVertices();
    assertEquals(expected.length, actual.length);
    for (int i = 0; i < expected.length; i++) {
      assertCoordinate(expected[i], actual[i]);
    }
  }
Beispiel #5
0
 @Test
 public void getCenter() {
   PolygonElement oblong = new OblongImpl(MINX, MINY, WIDTH, HEIGHT, null);
   Coordinate expected = new Coordinate(WIDTH / 2 + MINX, HEIGHT / 2 + MINY);
   assertCoordinate(expected, oblong.getCenter());
 }
Beispiel #6
0
 @Test
 public void getBounds() {
   PolygonElement oblong = new OblongImpl(MINX, MINY, WIDTH, HEIGHT, null);
   assertEnvelope(new Envelope(-10, WIDTH - 10, -5, HEIGHT - 5), oblong.getBounds());
 }
Beispiel #7
0
 @Test
 public void getArea() {
   PolygonElement oblong = new OblongImpl(MINX, MINY, WIDTH, HEIGHT, null);
   double expected = WIDTH * HEIGHT;
   assertEquals(expected, oblong.getArea(), TOL);
 }