use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.
the class GeoBoundingBoxQueryBuilderTests method doCreateTestQueryBuilder.
@Override
protected GeoBoundingBoxQueryBuilder doCreateTestQueryBuilder() {
GeoBoundingBoxQueryBuilder builder = new GeoBoundingBoxQueryBuilder(GEO_POINT_FIELD_NAME);
Rectangle box = RandomShapeGenerator.xRandomRectangle(random(), RandomShapeGenerator.xRandomPoint(random()));
if (randomBoolean()) {
// check the top-left/bottom-right combination of setters
int path = randomIntBetween(0, 2);
switch(path) {
case 0:
builder.setCorners(new GeoPoint(box.getMaxY(), box.getMinX()), new GeoPoint(box.getMinY(), box.getMaxX()));
break;
case 1:
builder.setCorners(GeohashUtils.encodeLatLon(box.getMaxY(), box.getMinX()), GeohashUtils.encodeLatLon(box.getMinY(), box.getMaxX()));
break;
default:
builder.setCorners(box.getMaxY(), box.getMinX(), box.getMinY(), box.getMaxX());
}
} else {
// check the bottom-left/ top-right combination of setters
if (randomBoolean()) {
builder.setCornersOGC(new GeoPoint(box.getMinY(), box.getMinX()), new GeoPoint(box.getMaxY(), box.getMaxX()));
} else {
builder.setCornersOGC(GeohashUtils.encodeLatLon(box.getMinY(), box.getMinX()), GeohashUtils.encodeLatLon(box.getMaxY(), box.getMaxX()));
}
}
if (randomBoolean()) {
builder.setValidationMethod(randomFrom(GeoValidationMethod.values()));
}
if (randomBoolean()) {
builder.ignoreUnmapped(randomBoolean());
}
builder.type(randomFrom(GeoExecType.values()));
return builder;
}
use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.
the class GeoDistanceQueryBuilderTests method doCreateTestQueryBuilder.
@Override
protected GeoDistanceQueryBuilder doCreateTestQueryBuilder() {
GeoDistanceQueryBuilder qb = new GeoDistanceQueryBuilder(GEO_POINT_FIELD_NAME);
String distance = "" + randomDouble();
if (randomBoolean()) {
DistanceUnit unit = randomFrom(DistanceUnit.values());
distance = distance + unit.toString();
}
int selector = randomIntBetween(0, 2);
switch(selector) {
case 0:
qb.distance(randomDouble(), randomFrom(DistanceUnit.values()));
break;
case 1:
qb.distance(distance, randomFrom(DistanceUnit.values()));
break;
case 2:
qb.distance(distance);
break;
}
Point p = RandomShapeGenerator.xRandomPoint(random());
qb.point(new GeoPoint(p.getY(), p.getX()));
if (randomBoolean()) {
qb.setValidationMethod(randomFrom(GeoValidationMethod.values()));
}
if (randomBoolean()) {
qb.geoDistance(randomFrom(GeoDistance.values()));
}
if (randomBoolean()) {
qb.ignoreUnmapped(randomBoolean());
}
return qb;
}
use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.
the class GeoPolygonQueryBuilderTests method testInvalidOpenPolygon.
public void testInvalidOpenPolygon() {
List<GeoPoint> points = new ArrayList<>();
points.add(new GeoPoint(0, 90));
points.add(new GeoPoint(90, 90));
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new GeoPolygonQueryBuilder(GEO_POINT_FIELD_NAME, points));
assertEquals("too few points defined for geo_polygon query", e.getMessage());
}
use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.
the class GeoBoundsIT method testSingleValuedFieldWithZeroLon.
public void testSingleValuedFieldWithZeroLon() throws Exception {
SearchResponse response = client().prepareSearch(IDX_ZERO_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
assertSearchResponse(response);
GeoBounds geoBounds = response.getAggregations().get(aggName);
assertThat(geoBounds, notNullValue());
assertThat(geoBounds.getName(), equalTo(aggName));
GeoPoint topLeft = geoBounds.topLeft();
GeoPoint bottomRight = geoBounds.bottomRight();
assertThat(topLeft.lat(), closeTo(1.0, GEOHASH_TOLERANCE));
assertThat(topLeft.lon(), closeTo(0.0, GEOHASH_TOLERANCE));
assertThat(bottomRight.lat(), closeTo(1.0, GEOHASH_TOLERANCE));
assertThat(bottomRight.lon(), closeTo(0.0, GEOHASH_TOLERANCE));
}
use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.
the class GeoBoundsIT method testSingleValuedFieldNearDateLine.
public void testSingleValuedFieldNearDateLine() throws Exception {
SearchResponse response = client().prepareSearch(DATELINE_IDX_NAME).addAggregation(geoBounds(aggName).field(SINGLE_VALUED_FIELD_NAME).wrapLongitude(false)).execute().actionGet();
assertSearchResponse(response);
GeoPoint geoValuesTopLeft = new GeoPoint(38, -179);
GeoPoint geoValuesBottomRight = new GeoPoint(-24, 178);
GeoBounds geoBounds = response.getAggregations().get(aggName);
assertThat(geoBounds, notNullValue());
assertThat(geoBounds.getName(), equalTo(aggName));
GeoPoint topLeft = geoBounds.topLeft();
GeoPoint bottomRight = geoBounds.bottomRight();
assertThat(topLeft.lat(), closeTo(geoValuesTopLeft.lat(), GEOHASH_TOLERANCE));
assertThat(topLeft.lon(), closeTo(geoValuesTopLeft.lon(), GEOHASH_TOLERANCE));
assertThat(bottomRight.lat(), closeTo(geoValuesBottomRight.lat(), GEOHASH_TOLERANCE));
assertThat(bottomRight.lon(), closeTo(geoValuesBottomRight.lon(), GEOHASH_TOLERANCE));
}
Aggregations