Search in sources :

Example 81 with GeoPoint

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;
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) Rectangle(org.locationtech.spatial4j.shape.Rectangle) LatLonPoint(org.apache.lucene.document.LatLonPoint) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 82 with GeoPoint

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;
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) LatLonPoint(org.apache.lucene.document.LatLonPoint) Point(org.locationtech.spatial4j.shape.Point) GeoPoint(org.elasticsearch.common.geo.GeoPoint) DistanceUnit(org.elasticsearch.common.unit.DistanceUnit) LatLonPoint(org.apache.lucene.document.LatLonPoint) Point(org.locationtech.spatial4j.shape.Point) GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 83 with GeoPoint

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());
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) ArrayList(java.util.ArrayList)

Example 84 with GeoPoint

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));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoBounds(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 85 with GeoPoint

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));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoBounds(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

GeoPoint (org.elasticsearch.common.geo.GeoPoint)122 SearchResponse (org.elasticsearch.action.search.SearchResponse)40 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)27 ArrayList (java.util.ArrayList)20 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)15 XContentParser (org.elasticsearch.common.xcontent.XContentParser)9 GeoBounds (org.elasticsearch.search.aggregations.metrics.geobounds.GeoBounds)9 Range (org.elasticsearch.search.aggregations.bucket.range.Range)8 GeoCentroid (org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid)8 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)7 Version (org.elasticsearch.Version)7 Bucket (org.elasticsearch.search.aggregations.bucket.range.Range.Bucket)7 Settings (org.elasticsearch.common.settings.Settings)6 MultiGeoPointValues (org.elasticsearch.index.fielddata.MultiGeoPointValues)6 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)5 ParsingException (org.elasticsearch.common.ParsingException)5 SearchHit (org.elasticsearch.search.SearchHit)5 Test (org.testng.annotations.Test)5 HashSet (java.util.HashSet)4 DistanceUnit (org.elasticsearch.common.unit.DistanceUnit)4