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);
}
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);
}
Aggregations