Example usage for org.springframework.data.elasticsearch.core.geo GeoPoint getLat

List of usage examples for org.springframework.data.elasticsearch.core.geo GeoPoint getLat

Introduction

In this page you can find the example usage for org.springframework.data.elasticsearch.core.geo GeoPoint getLat.

Prototype

public double getLat() 

Source Link

Usage

From source file:com.github.vanroy.springdata.jest.CriteriaFilterProcessor.java

private void twoParameterBBox(GeoBoundingBoxQueryBuilder filter, Object[] values) {
    Assert.isTrue(isType(values, GeoPoint.class) || isType(values, String.class),
            " both elements of boundedBy filter must be type of GeoPoint or String(format lat,lon or geohash)");
    if (values[0] instanceof GeoPoint) {
        GeoPoint topLeft = (GeoPoint) values[0];
        GeoPoint bottomRight = (GeoPoint) values[1];
        filter.topLeft(topLeft.getLat(), topLeft.getLon());
        filter.bottomRight(bottomRight.getLat(), bottomRight.getLon());
    } else {/*from ww  w .  java 2  s.com*/
        String topLeft = (String) values[0];
        String bottomRight = (String) values[1];
        filter.topLeft(topLeft);
        filter.bottomRight(bottomRight);
    }
}

From source file:com.github.vanroy.springdata.jest.CriteriaFilterProcessor.java

private QueryBuilder processCriteriaEntry(OperationKey key, Object value, String fieldName) {
    if (value == null) {
        return null;
    }/*w  w  w. j  a v a2 s.c  o  m*/
    QueryBuilder filter = null;

    switch (key) {
    case WITHIN: {
        GeoDistanceQueryBuilder geoDistanceQueryBuilder = QueryBuilders.geoDistanceQuery(fieldName);

        Assert.isTrue(value instanceof Object[],
                "Value of a geo distance filter should be an array of two values.");
        Object[] valArray = (Object[]) value;
        Assert.noNullElements(valArray, "Geo distance filter takes 2 not null elements array as parameter.");
        Assert.isTrue(valArray.length == 2, "Geo distance filter takes a 2-elements array as parameter.");
        Assert.isTrue(
                valArray[0] instanceof GeoPoint || valArray[0] instanceof String
                        || valArray[0] instanceof Point,
                "First element of a geo distance filter must be a GeoPoint, a Point or a String");
        Assert.isTrue(valArray[1] instanceof String || valArray[1] instanceof Distance,
                "Second element of a geo distance filter must be a String or a Distance");

        StringBuilder dist = new StringBuilder();

        if (valArray[1] instanceof Distance) {
            extractDistanceString((Distance) valArray[1], dist);
        } else {
            dist.append((String) valArray[1]);
        }

        if (valArray[0] instanceof GeoPoint) {
            GeoPoint loc = (GeoPoint) valArray[0];
            geoDistanceQueryBuilder.lat(loc.getLat()).lon(loc.getLon()).distance(dist.toString())
                    .geoDistance(GeoDistance.PLANE);
        } else if (valArray[0] instanceof Point) {
            GeoPoint loc = GeoPoint.fromPoint((Point) valArray[0]);
            geoDistanceQueryBuilder.lat(loc.getLat()).lon(loc.getLon()).distance(dist.toString())
                    .geoDistance(GeoDistance.PLANE);
        } else {
            String loc = (String) valArray[0];
            if (loc.contains(",")) {
                String c[] = loc.split(",");
                geoDistanceQueryBuilder.lat(Double.parseDouble(c[0])).lon(Double.parseDouble(c[1]))
                        .distance(dist.toString()).geoDistance(GeoDistance.PLANE);
            } else {
                geoDistanceQueryBuilder.geohash(loc).distance(dist.toString()).geoDistance(GeoDistance.PLANE);
            }
        }
        filter = geoDistanceQueryBuilder;

        break;
    }

    case BBOX: {
        filter = QueryBuilders.geoBoundingBoxQuery(fieldName);

        Assert.isTrue(value instanceof Object[],
                "Value of a boundedBy filter should be an array of one or two values.");
        Object[] valArray = (Object[]) value;
        Assert.noNullElements(valArray, "Geo boundedBy filter takes a not null element array as parameter.");

        if (valArray.length == 1) {
            //GeoEnvelop
            oneParameterBBox((GeoBoundingBoxQueryBuilder) filter, valArray[0]);
        } else if (valArray.length == 2) {
            //2x GeoPoint
            //2x String
            twoParameterBBox((GeoBoundingBoxQueryBuilder) filter, valArray);
        } else {
            //error
            Assert.isTrue(false,
                    "Geo distance filter takes a 1-elements array(GeoBox) or 2-elements array(GeoPoints or Strings(format lat,lon or geohash)).");
        }
        break;
    }
    }

    return filter;
}