Search in sources :

Example 1 with GeoPoint

use of org.vertexium.type.GeoPoint in project vertexium by visallo.

the class ElasticsearchGraphQueryIterable method getAverageGeoPointFromBuckets.

private static GeoPoint getAverageGeoPointFromBuckets(List<MultiBucketsAggregation.Bucket> buckets) {
    List<GeoPoint> geoPoints = new ArrayList<>();
    for (MultiBucketsAggregation.Bucket b : buckets) {
        GeoHashGrid.Bucket gb = (GeoHashGrid.Bucket) b;
        org.elasticsearch.common.geo.GeoPoint gp = (org.elasticsearch.common.geo.GeoPoint) gb.getKey();
        geoPoints.add(new GeoPoint(gp.getLat(), gp.getLon()));
    }
    return GeoPoint.calculateCenter(geoPoints);
}
Also used : GeoPoint(org.vertexium.type.GeoPoint) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) InternalGeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid) GeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid)

Example 2 with GeoPoint

use of org.vertexium.type.GeoPoint in project vertexium by visallo.

the class ElasticsearchGraphQueryIterable method reduceGeohashResults.

private static GeohashResult reduceGeohashResults(ElasticsearchSearchQueryBase query, List<Aggregation> aggs) {
    Map<Object, List<MultiBucketsAggregation.Bucket>> bucketsByKey = new HashMap<>();
    for (Aggregation agg : aggs) {
        if (agg instanceof GeoHashGrid) {
            GeoHashGrid h = (GeoHashGrid) agg;
            for (GeoHashGrid.Bucket b : h.getBuckets()) {
                List<MultiBucketsAggregation.Bucket> existingBucket = bucketsByKey.computeIfAbsent(b.getKey(), k -> new ArrayList<>());
                existingBucket.add(b);
            }
        } else {
            throw new VertexiumException("Aggregation is not a geohash: " + agg.getClass().getName());
        }
    }
    return new MultiBucketsAggregationReducer<GeohashResult, GeohashBucket>() {

        @Override
        protected GeohashBucket createBucket(final Object key, long count, Map<String, AggregationResult> nestedResults, List<MultiBucketsAggregation.Bucket> buckets) {
            GeoPoint geoPoint = getAverageGeoPointFromBuckets(buckets);
            return new GeohashBucket(key.toString(), count, geoPoint, nestedResults) {

                @Override
                public GeoRect getGeoCell() {
                    org.elasticsearch.common.geo.GeoPoint northWest = new org.elasticsearch.common.geo.GeoPoint();
                    org.elasticsearch.common.geo.GeoPoint southEast = new org.elasticsearch.common.geo.GeoPoint();
                    GeohashUtils.decodeCell(key.toString(), northWest, southEast);
                    return new GeoRect(new GeoPoint(northWest.getLat(), northWest.getLon()), new GeoPoint(southEast.getLat(), southEast.getLon()));
                }
            };
        }

        @Override
        protected GeohashResult bucketsToResults(List<GeohashBucket> buckets) {
            return new GeohashResult(buckets);
        }
    }.reduce(query, bucketsByKey);
}
Also used : GeoRect(org.vertexium.type.GeoRect) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) Aggregation(org.elasticsearch.search.aggregations.Aggregation) GeoPoint(org.vertexium.type.GeoPoint) VertexiumException(org.vertexium.VertexiumException) MultiBucketsAggregation(org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation) InternalGeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid) GeoHashGrid(org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid)

Aggregations

MultiBucketsAggregation (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)2 GeoHashGrid (org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGrid)2 InternalGeoHashGrid (org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid)2 GeoPoint (org.vertexium.type.GeoPoint)2 Aggregation (org.elasticsearch.search.aggregations.Aggregation)1 VertexiumException (org.vertexium.VertexiumException)1 GeoRect (org.vertexium.type.GeoRect)1