private void handleGeoBoundsAggregation(List<String> headers, List<List<String>> lines, GeoBounds geoBoundsAggregation) { String geoBoundAggName = geoBoundsAggregation.getName(); headers.add(geoBoundAggName+".topLeft.lon"); headers.add(geoBoundAggName+".topLeft.lat"); headers.add(geoBoundAggName+".bottomRight.lon"); headers.add(geoBoundAggName+".bottomRight.lat"); List<String> line = lines.get(this.currentLineIndex); line.add(String.valueOf(geoBoundsAggregation.topLeft().getLon())); line.add(String.valueOf(geoBoundsAggregation.topLeft().getLat())); line.add(String.valueOf(geoBoundsAggregation.bottomRight().getLon())); line.add(String.valueOf(geoBoundsAggregation.bottomRight().getLat())); lines.add(line); }
private void handleGeoBoundsAggregation(List<String> headers, List<List<Object>> lines, GeoBounds geoBoundsAggregation) { String geoBoundAggName = geoBoundsAggregation.getName(); headers.add(geoBoundAggName + ".topLeft.lon"); headers.add(geoBoundAggName + ".topLeft.lat"); headers.add(geoBoundAggName + ".bottomRight.lon"); headers.add(geoBoundAggName + ".bottomRight.lat"); List<Object> line = lines.get(this.currentLineIndex); line.add(String.valueOf(geoBoundsAggregation.topLeft().getLon())); line.add(String.valueOf(geoBoundsAggregation.topLeft().getLat())); line.add(String.valueOf(geoBoundsAggregation.bottomRight().getLon())); line.add(String.valueOf(geoBoundsAggregation.bottomRight().getLat())); lines.add(line); }
public GeoPoint(GeoPoint template) { this(template.getLat(), template.getLon()); }
/** * Adds corners in OGC standard bbox/ envelop format. * * @param bottomLeft bottom left corner of bounding box. * @param topRight top right corner of bounding box. */ public GeoBoundingBoxQueryBuilder setCornersOGC(GeoPoint bottomLeft, GeoPoint topRight) { return setCorners(topRight.getLat(), bottomLeft.getLon(), bottomLeft.getLat(), topRight.getLon()); }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); builder.startObject(CONTEXT_VALUE); builder.field("lat", geoPoint.getLat()); builder.field("lon", geoPoint.getLon()); builder.endObject(); builder.field(CONTEXT_BOOST, boost); builder.field(CONTEXT_NEIGHBOURS, neighbours); builder.field(CONTEXT_PRECISION, precision); builder.endObject(); return builder; }
@Override public InternalGeoCentroid doReduce(List<InternalAggregation> aggregations, ReduceContext reduceContext) { double lonSum = Double.NaN; double latSum = Double.NaN; int totalCount = 0; for (InternalAggregation aggregation : aggregations) { InternalGeoCentroid centroidAgg = (InternalGeoCentroid) aggregation; if (centroidAgg.count > 0) { totalCount += centroidAgg.count; if (Double.isNaN(lonSum)) { lonSum = centroidAgg.count * centroidAgg.centroid.getLon(); latSum = centroidAgg.count * centroidAgg.centroid.getLat(); } else { lonSum += (centroidAgg.count * centroidAgg.centroid.getLon()); latSum += (centroidAgg.count * centroidAgg.centroid.getLat()); } } } final GeoPoint result = (Double.isNaN(lonSum)) ? null : new GeoPoint(latSum/totalCount, lonSum/totalCount); return new InternalGeoCentroid(name, result, totalCount, pipelineAggregators(), getMetaData()); }
@Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { if (topLeft != null) { builder.startObject(BOUNDS_FIELD.getPreferredName()); builder.startObject(TOP_LEFT_FIELD.getPreferredName()); builder.field(LAT_FIELD.getPreferredName(), topLeft.getLat()); builder.field(LON_FIELD.getPreferredName(), topLeft.getLon()); builder.endObject(); builder.startObject(BOTTOM_RIGHT_FIELD.getPreferredName()); builder.field(LAT_FIELD.getPreferredName(), bottomRight.getLat()); builder.field(LON_FIELD.getPreferredName(), bottomRight.getLon()); builder.endObject(); builder.endObject(); } return builder; }
private QueryValidationException checkLatLon() { if (GeoValidationMethod.isIgnoreMalformed(validationMethod)) { return null; } QueryValidationException validationException = null; // For everything post 2.0, validate latitude and longitude unless validation was explicitly turned off if (GeoUtils.isValidLatitude(center.getLat()) == false) { validationException = addValidationError("center point latitude is invalid: " + center.getLat(), validationException); } if (GeoUtils.isValidLongitude(center.getLon()) == false) { validationException = addValidationError("center point longitude is invalid: " + center.getLon(), validationException); } return validationException; }
GeoPoint point = queryContext.getGeoPoint(); final Collection<String> locations = new HashSet<>(); String geoHash = stringEncode(point.getLon(), point.getLat(), minPrecision); locations.add(geoHash); if (queryContext.getNeighbours().isEmpty() && geoHash.length() == this.precision) {
@Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NAME); builder.startObject(fieldName); builder.array(TOP_LEFT_FIELD.getPreferredName(), topLeft.getLon(), topLeft.getLat()); builder.array(BOTTOM_RIGHT_FIELD.getPreferredName(), bottomRight.getLon(), bottomRight.getLat()); builder.endObject(); builder.field(VALIDATION_METHOD_FIELD.getPreferredName(), validationMethod); builder.field(TYPE_FIELD.getPreferredName(), type); builder.field(IGNORE_UNMAPPED_FIELD.getPreferredName(), ignoreUnmapped); printBoostAndQueryName(builder); builder.endObject(); }
QueryValidationException checkLatLon() { if (GeoValidationMethod.isIgnoreMalformed(validationMethod)) { return null; } QueryValidationException validationException = null; // For everything post 2.0 validate latitude and longitude unless validation was explicitly turned off if (GeoUtils.isValidLatitude(topLeft.getLat()) == false) { validationException = addValidationError("top latitude is invalid: " + topLeft.getLat(), validationException); } if (GeoUtils.isValidLongitude(topLeft.getLon()) == false) { validationException = addValidationError("left longitude is invalid: " + topLeft.getLon(), validationException); } if (GeoUtils.isValidLatitude(bottomRight.getLat()) == false) { validationException = addValidationError("bottom latitude is invalid: " + bottomRight.getLat(), validationException); } if (GeoUtils.isValidLongitude(bottomRight.getLon()) == false) { validationException = addValidationError("right longitude is invalid: " + bottomRight.getLon(), validationException); } return validationException; }
geohashes.add(stringEncode(spare.getLon(), spare.getLat(), precision));
@Override public boolean advanceExact(int docId) throws IOException { if (geoValues.advanceExact(docId)) { resize(geoValues.docValueCount()); for (int i = 0; i < docValueCount(); ++i) { GeoPoint target = geoValues.nextValue(); values[i] = GeoHashUtils.longEncode(target.getLon(), target.getLat(), precision); } sort(); return true; } else { return false; } } }
Query query = LatLonPoint.newBoxQuery(fieldType.name(), luceneBottomRight.getLat(), luceneTopLeft.getLat(), luceneTopLeft.getLon(), luceneBottomRight.getLon()); if (fieldType.hasDocValues()) { Query dvQuery = LatLonDocValuesField.newSlowBoxQuery(fieldType.name(), luceneBottomRight.getLat(), luceneTopLeft.getLat(), luceneTopLeft.getLon(), luceneBottomRight.getLon()); query = new IndexOrDocValuesQuery(query, dvQuery);
if (TOP_LEFT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { GeoUtils.parseGeoPoint(parser, sparse); top = sparse.getLat(); left = sparse.getLon(); } else if (BOTTOM_RIGHT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { GeoUtils.parseGeoPoint(parser, sparse); bottom = sparse.getLat(); right = sparse.getLon(); } else if (TOP_RIGHT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { GeoUtils.parseGeoPoint(parser, sparse); top = sparse.getLat(); right = sparse.getLon(); } else if (BOTTOM_LEFT_FIELD.match(currentFieldName, parser.getDeprecationHandler())) { GeoUtils.parseGeoPoint(parser, sparse); bottom = sparse.getLat(); left = sparse.getLon(); } else {
GeoPoint value = values.nextValue(); pt[0] = pt[0] + (value.getLon() - pt[0]) / ++prevCounts; pt[1] = pt[1] + (value.getLat() - pt[1]) / prevCounts;
public XContentBuilder value(GeoPoint value) throws IOException { if (value == null) { return nullValue(); } return latlon(value.getLat(), value.getLon()); }