Search in sources :

Example 41 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class GeoUtilsTests method testNormalizePointHuge.

public void testNormalizePointHuge() {
    assertNormalizedPoint(new GeoPoint(-18000000000091.0, -36000000000181.0), new GeoPoint(-089.0, -001.0));
    assertNormalizedPoint(new GeoPoint(-18000000000090.0, -36000000000180.0), new GeoPoint(-090.0, +180.0));
    assertNormalizedPoint(new GeoPoint(-18000000000089.0, -36000000000179.0), new GeoPoint(-089.0, -179.0));
    assertNormalizedPoint(new GeoPoint(-18000000000088.0, -36000000000178.0), new GeoPoint(-088.0, -178.0));
    assertNormalizedPoint(new GeoPoint(-18000000000001.0, -36000000000001.0), new GeoPoint(-001.0, -001.0));
    assertNormalizedPoint(new GeoPoint(+18000000000000.0, +18000000000000.0), new GeoPoint(+000.0, +000.0));
    assertNormalizedPoint(new GeoPoint(+18000000000001.0, +36000000000001.0), new GeoPoint(+001.0, +001.0));
    assertNormalizedPoint(new GeoPoint(+18000000000002.0, +36000000000002.0), new GeoPoint(+002.0, +002.0));
    assertNormalizedPoint(new GeoPoint(+18000000000088.0, +36000000000178.0), new GeoPoint(+088.0, +178.0));
    assertNormalizedPoint(new GeoPoint(+18000000000089.0, +36000000000179.0), new GeoPoint(+089.0, +179.0));
    assertNormalizedPoint(new GeoPoint(+18000000000090.0, +36000000000180.0), new GeoPoint(+090.0, +180.0));
    assertNormalizedPoint(new GeoPoint(+18000000000091.0, +36000000000181.0), new GeoPoint(+089.0, +001.0));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 42 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class GeoUtilsTests method testNormalizePointEdgeCases.

public void testNormalizePointEdgeCases() {
    assertNormalizedPoint(new GeoPoint(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY), new GeoPoint(Double.NaN, Double.NaN));
    assertNormalizedPoint(new GeoPoint(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), new GeoPoint(Double.NaN, Double.NaN));
    assertNormalizedPoint(new GeoPoint(Double.NaN, Double.NaN), new GeoPoint(Double.NaN, Double.NaN));
    assertThat(0.0, not(equalTo(-0.0)));
    assertNormalizedPoint(new GeoPoint(-0.0, -0.0), new GeoPoint(0.0, 0.0));
    assertNormalizedPoint(new GeoPoint(0.0, 0.0), new GeoPoint(0.0, 0.0));
    assertNormalizedPoint(new GeoPoint(-180.0, -360.0), new GeoPoint(0.0, 180.0));
    assertNormalizedPoint(new GeoPoint(180.0, 360.0), new GeoPoint(0.0, 180.0));
    assertNormalizedPoint(new GeoPoint(-90.0, -180.0), new GeoPoint(-90.0, -180.0));
    assertNormalizedPoint(new GeoPoint(90.0, 180.0), new GeoPoint(90.0, 180.0));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint)

Example 43 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class GeoUtilsTests method testParseGeoPoint.

public void testParseGeoPoint() throws IOException {
    for (int i = 0; i < 100; i++) {
        double lat = randomDouble() * 180 - 90 + randomIntBetween(-1000, 1000) * 180;
        double lon = randomDouble() * 360 - 180 + randomIntBetween(-1000, 1000) * 360;
        XContentBuilder json = jsonBuilder().startObject().field("lat", lat).field("lon", lon).endObject();
        XContentParser parser = createParser(json);
        parser.nextToken();
        GeoPoint point = GeoUtils.parseGeoPoint(parser);
        assertThat(point, equalTo(new GeoPoint(lat, lon)));
        json = jsonBuilder().startObject().field("lat", String.valueOf(lat)).field("lon", String.valueOf(lon)).endObject();
        parser = createParser(json);
        parser.nextToken();
        point = GeoUtils.parseGeoPoint(parser);
        assertThat(point, equalTo(new GeoPoint(lat, lon)));
        json = jsonBuilder().startObject().startArray("foo").value(lon).value(lat).endArray().endObject();
        parser = createParser(json);
        while (parser.currentToken() != Token.START_ARRAY) {
            parser.nextToken();
        }
        point = GeoUtils.parseGeoPoint(parser);
        assertThat(point, equalTo(new GeoPoint(lat, lon)));
        json = jsonBuilder().startObject().field("foo", lat + "," + lon).endObject();
        parser = createParser(json);
        while (parser.currentToken() != Token.VALUE_STRING) {
            parser.nextToken();
        }
        point = GeoUtils.parseGeoPoint(parser);
        assertThat(point, equalTo(new GeoPoint(lat, lon)));
    }
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoPoint(org.elasticsearch.common.geo.GeoPoint) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 44 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project crate by crate.

the class GeoPointColumnReference method setNextDocId.

@Override
public void setNextDocId(int docId) {
    super.setNextDocId(docId);
    values.setDocument(docId);
    switch(values.count()) {
        case 0:
            value = null;
            break;
        case 1:
            GeoPoint gp = values.valueAt(0);
            value = new Double[] { gp.lon(), gp.lat() };
            break;
        default:
            throw new GroupByOnArrayUnsupportedException(columnName);
    }
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GroupByOnArrayUnsupportedException(io.crate.exceptions.GroupByOnArrayUnsupportedException)

Example 45 with GeoPoint

use of org.elasticsearch.common.geo.GeoPoint in project elasticsearch by elastic.

the class MissingValueIT method testGeoCentroid.

public void testGeoCentroid() {
    SearchResponse response = client().prepareSearch("idx").addAggregation(geoCentroid("centroid").field("location").missing("2,1")).get();
    assertSearchResponse(response);
    GeoCentroid centroid = response.getAggregations().get("centroid");
    GeoPoint point = new GeoPoint(1.5, 1.5);
    assertThat(point.lat(), closeTo(centroid.centroid().lat(), 1E-5));
    assertThat(point.lon(), closeTo(centroid.centroid().lon(), 1E-5));
}
Also used : GeoPoint(org.elasticsearch.common.geo.GeoPoint) GeoCentroid(org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroid) 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