Example usage for org.apache.lucene.geo Rectangle fromPointDistance

List of usage examples for org.apache.lucene.geo Rectangle fromPointDistance

Introduction

In this page you can find the example usage for org.apache.lucene.geo Rectangle fromPointDistance.

Prototype

public static Rectangle fromPointDistance(final double centerLat, final double centerLon,
        final double radiusMeters) 

Source Link

Document

Compute Bounding Box for a circle using WGS-84 parameters

Usage

From source file:org.elasticsearch.common.geo.GeoDistanceTests.java

License:Apache License

public void testDistanceCheck() {
    // Note, is within is an approximation, so, even though 0.52 is outside 50mi, we still get "true"
    double radius = DistanceUnit.convert(50, DistanceUnit.MILES, DistanceUnit.METERS);
    Rectangle box = Rectangle.fromPointDistance(0, 0, radius);
    assertThat(GeoUtils.rectangleContainsPoint(box, 0.5, 0.5), equalTo(true));
    assertThat(GeoUtils.rectangleContainsPoint(box, 0.52, 0.52), equalTo(true));
    assertThat(GeoUtils.rectangleContainsPoint(box, 1, 1), equalTo(false));

    radius = DistanceUnit.convert(200, DistanceUnit.MILES, DistanceUnit.METERS);
    box = Rectangle.fromPointDistance(0, 179, radius);
    assertThat(GeoUtils.rectangleContainsPoint(box, 0, -179), equalTo(true));
    assertThat(GeoUtils.rectangleContainsPoint(box, 0, -178), equalTo(false));
}

From source file:org.elasticsearch.index.search.geo.LegacyGeoDistanceRangeQuery.java

License:Apache License

public LegacyGeoDistanceRangeQuery(GeoPoint point, Double lowerVal, Double upperVal, boolean includeLower,
        boolean includeUpper, GeoDistance geoDistance,
        LegacyGeoPointFieldMapper.LegacyGeoPointFieldType fieldType, IndexGeoPointFieldData indexFieldData,
        String optimizeBbox, QueryShardContext context) {
    this.lat = point.lat();
    this.lon = point.lon();
    this.geoDistance = geoDistance;
    this.indexFieldData = indexFieldData;

    if (lowerVal != null) {
        double f = lowerVal.doubleValue();
        long i = NumericUtils.doubleToSortableLong(f);
        inclusiveLowerPoint = NumericUtils.sortableLongToDouble(includeLower ? i : (i + 1L));
    } else {//w  w w .  j ava 2  s .  com
        inclusiveLowerPoint = Double.NEGATIVE_INFINITY;
    }
    if (upperVal != null) {
        double f = upperVal.doubleValue();
        long i = NumericUtils.doubleToSortableLong(f);
        inclusiveUpperPoint = NumericUtils.sortableLongToDouble(includeUpper ? i : (i - 1L));
    } else {
        inclusiveUpperPoint = Double.POSITIVE_INFINITY;
        // we disable bounding box in this case, since the upper point is all and we create bounding box up to the
        // upper point it will effectively include all
        // TODO we can create a bounding box up to from and "not" it
        optimizeBbox = null;
    }

    if (optimizeBbox != null && !"none".equals(optimizeBbox)) {
        bbox = Rectangle.fromPointDistance(lat, lon, inclusiveUpperPoint);
        if ("memory".equals(optimizeBbox)) {
            boundingBoxFilter = null;
        } else if ("indexed".equals(optimizeBbox)) {
            boundingBoxFilter = LegacyIndexedGeoBoundingBoxQuery.create(bbox, fieldType, context);
        } else {
            throw new IllegalArgumentException(
                    "type [" + optimizeBbox + "] for bounding box optimization not supported");
        }
    } else {
        bbox = null;
        boundingBoxFilter = null;
    }
}