Package org.elasticsearch.common.geo

Examples of org.elasticsearch.common.geo.GeoPoint


    return extend(bounds.topLeft(), bounds.bottomRight());
  }

  private GeoBoundingBox extend(GeoPoint topLeft, GeoPoint bottomRight) {
    return contains(topLeft) && contains(bottomRight) ? this : new GeoBoundingBox(
      new GeoPoint(Math.max(topLeft().getLat(), topLeft.getLat()), Math.min(topLeft().getLon(), topLeft.getLon())),
      new GeoPoint(Math.min(bottomRight().getLat(), bottomRight.getLat()), Math.max(bottomRight().getLon(), bottomRight.getLon())));
  }
View Full Code Here


      new GeoCluster(1, SAN_DIEGO, new GeoBoundingBox(SAN_DIEGO))));

    builder.add(LAS_VEGAS);
    assertThat("Cluster after adding Las Vegas", builder.build(), hasItems(
      new GeoCluster(2, DENVER, new GeoBoundingBox(DENVER)),
      new GeoCluster(2, new GeoPoint(34.4500, -116.1500), new GeoBoundingBox(SAN_DIEGO).extend(LAS_VEGAS))));
  }
View Full Code Here

    assertThat("Cluster after adding Denver again", builder.build(), hasItems(
      new GeoCluster(2, DENVER, new GeoBoundingBox(DENVER))));

    builder.add(SAN_DIEGO);
    assertThat("Cluster after adding San Diego", builder.build(), hasItems(
      new GeoCluster(3, new GeoPoint(37.4400, -108.9567), new GeoBoundingBox(DENVER).extend(SAN_DIEGO))));

    builder.add(LAS_VEGAS);
    assertThat("Cluster after adding Las Vegas", builder.build(), hasItems(
      new GeoCluster(4, new GeoPoint(37.1000, -110.5100), new GeoBoundingBox(DENVER).extend(SAN_DIEGO).extend(LAS_VEGAS))));
  }
View Full Code Here

    assertThat("Top left corner after adding the first point", cluster.bounds().topLeft(), closeTo(DENVER));
    assertThat("Bottom right corner after adding the first point", cluster.bounds().bottomRight(), closeTo(DENVER));

    cluster.add(LAS_VEGAS);
    assertThat("Cluster size after adding a second point", cluster.size(), equalTo(2));
    assertThat("Center after adding a second point", cluster.center(), closeTo(new GeoPoint(37.915, -110.02)));
    assertThat("Top left corner after adding a second point", cluster.bounds().topLeft(), closeTo(new GeoPoint(DENVER.getLat(), LAS_VEGAS.getLon())));
    assertThat("Bottom right corner after adding a second point", cluster.bounds().bottomRight(), closeTo(new GeoPoint(LAS_VEGAS.getLat(), DENVER.getLon())));

    cluster.add(SAN_DIEGO);
    assertThat("Cluster size after adding a third point", cluster.size(), equalTo(3));
    assertThat("Center after adding a third point", cluster.center(), closeTo(new GeoPoint(36.217, -112.39)));
    assertThat("Top left corner after adding a third point", cluster.bounds().topLeft(), closeTo(new GeoPoint(DENVER.getLat(), SAN_DIEGO.getLon())));
    assertThat("Bottom right corner after adding a third point", cluster.bounds().bottomRight(), closeTo(new GeoPoint(SAN_DIEGO.getLat(), DENVER.getLon())));
  }
View Full Code Here

  @Test
  public void testMerge() {
    GeoCluster cluster = new GeoCluster(1, LAS_VEGAS, new GeoBoundingBox(LAS_VEGAS));
    GeoCluster merged = cluster.merge(new GeoCluster(2, SAN_DIEGO, new GeoBoundingBox(SAN_DIEGO)));
    assertThat(merged.size(), equalTo(3));
    assertThat(merged.center(), closeTo(new GeoPoint(33.9067, -116.4767)));
    assertThat(merged.bounds(), equalTo(new GeoBoundingBox(LAS_VEGAS).extend(SAN_DIEGO)));
  }
View Full Code Here

    bounds = bounds.extend(point);
  }

  public GeoCluster merge(GeoCluster that) {
    int size = this.size + that.size();
    GeoPoint center = mean(this.center, size - that.size(), that.center(), that.size());
    GeoBoundingBox bounds = this.bounds.extend(that.bounds());
    return new GeoCluster(size, center, bounds);
  }
View Full Code Here

  }

  private static GeoPoint mean(GeoPoint left, int leftWeight, GeoPoint right, int rightWeight) {
    double lat = (left.getLat() * leftWeight + right.getLat() * rightWeight) / (leftWeight + rightWeight);
    double lon = (left.getLon() * leftWeight + right.getLon() * rightWeight) / (leftWeight + rightWeight);
    return new GeoPoint(lat, lon);
  }
View Full Code Here

    return bounds;
  }

  public static GeoCluster readFrom(StreamInput in) throws IOException {
    int size = in.readVInt();
    GeoPoint center = GeoPoints.readFrom(in);
    GeoBoundingBox bounds = size > 1
      ? GeoBoundingBox.readFrom(in)
      : new GeoBoundingBox(center, center);
    return new GeoCluster(size, center, bounds);
  }
View Full Code Here

  @Test
  public void testReadFromWriteTo() throws IOException {
    BytesStreamOutput out = new BytesStreamOutput();
    GeoPoints.writeTo(LAS_VEGAS, out);
    BytesStreamInput in = new BytesStreamInput(out.bytes());
    GeoPoint point = GeoPoints.readFrom(in);
    assertThat("Latitude", point.lat(), equalTo(LAS_VEGAS.lat()));
    assertThat("Longitude", point.lon(), equalTo(LAS_VEGAS.lon()));
  }
View Full Code Here

      new GeoCluster(1, SAN_DIEGO, new GeoBoundingBox(SAN_DIEGO))));

    clusters.add(new GeoCluster(LAS_VEGAS));
    assertThat("Cluster after adding Las Vegas", reducer.reduce(clusters), hasItems(
      new GeoCluster(2, DENVER, new GeoBoundingBox(DENVER)),
      new GeoCluster(2, new GeoPoint(34.4500, -116.1500), new GeoBoundingBox(SAN_DIEGO).extend(LAS_VEGAS))));
  }
View Full Code Here

TOP

Related Classes of org.elasticsearch.common.geo.GeoPoint

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.