case POINT: case CIRCLE: return geoshape.getPoint(); case BOX: if (position == 0)
@Override public void serialize(Geoshape value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException { switch(value.getType()) { case POINT: jgen.writeStartObject(); jgen.writeFieldName(FIELD_TYPE); jgen.writeString(Type.POINT.toString()); jgen.writeFieldName(FIELD_COORDINATES); jgen.writeStartArray(); jgen.writeNumber(value.getPoint().getLongitude()); jgen.writeNumber(value.getPoint().getLatitude()); jgen.writeEndArray(); jgen.writeEndObject(); break; default: jgen.writeRawValue(toGeoJson(value)); break; } }
final double distance = Geoshape.point(0.0, 0.0).getPoint().distance(Geoshape.point(offset, offset).getPoint()) + 20; assertCount(5, tx.query().has("location", Geo.INTERSECT, Geoshape.circle(0.0, 0.0, distance)).has("text", Text.CONTAINS, words[0]).vertices()); assertCount(5, tx.query().has("boundary", Geo.INTERSECT, Geoshape.circle(0.0, 0.0, distance)).has("text", Text.CONTAINS, words[0]).vertices());
@SuppressWarnings("unchecked") private static Object convertGeoshape(Geoshape geoshape, Mapping mapping) { if (geoshape.getType() == Geoshape.Type.POINT && Mapping.PREFIX_TREE != mapping) { final Geoshape.Point p = geoshape.getPoint(); return new double[]{p.getLongitude(), p.getLatitude()}; } else if (geoshape.getType() == Geoshape.Type.BOX) { final Rectangle box = geoshape.getShape().getBoundingBox(); final Map<String,Object> map = new HashMap<>(); map.put("type", "envelope"); map.put("coordinates", new double[][] {{box.getMinX(),box.getMaxY()},{box.getMaxX(),box.getMinY()}}); return map; } else if (geoshape.getType() == Geoshape.Type.CIRCLE) { try { final Map<String,Object> map = geoshape.toMap(); map.put("radius", map.get("radius") + ((Map<String, String>) map.remove("properties")).get("radius_units")); return map; } catch (final IOException e) { throw new IllegalArgumentException("Invalid geoshape: " + geoshape, e); } } else { try { return geoshape.toMap(); } catch (final IOException e) { throw new IllegalArgumentException("Invalid geoshape: " + geoshape, e); } } }
switch (shape.getType()) { case CIRCLE: final Geoshape.Point center = shape.getPoint(); query = compat.geoDistance(key, center.getLatitude(), center.getLongitude(), shape.getRadius()); break; case BOX: final Geoshape.Point southwest = shape.getPoint(0); final Geoshape.Point northeast = shape.getPoint(1); query = compat.geoBoundingBox(key, southwest.getLatitude(), southwest.getLongitude(), northeast.getLatitude(), northeast.getLongitude()); case POLYGON: final List<List<Double>> points = IntStream.range(0, shape.size()) .mapToObj(i -> ImmutableList.of(shape.getPoint(i).getLongitude(), shape.getPoint(i).getLatitude())) .collect(Collectors.toList()); query = compat.geoPolygon(key, points); switch (shape.getType()) { case CIRCLE: final Geoshape.Point center = shape.getPoint(); geo = ImmutableMap.of(ES_TYPE_KEY, "circle", ES_GEO_COORDS_KEY, ImmutableList.of(center.getLongitude(), center.getLatitude()), break; case BOX: final Geoshape.Point southwest = shape.getPoint(0); final Geoshape.Point northeast = shape.getPoint(1); geo = ImmutableMap.of(ES_TYPE_KEY, "envelope",
final Geoshape geo = (Geoshape)value; if (geo.getType() == Geoshape.Type.CIRCLE && (predicate == Geo.INTERSECT || map == Mapping.DEFAULT)) { final Geoshape.Point center = geo.getPoint(); return ("{!geofilt sfield=" + key + " pt=" + center.getLatitude() + "," + center.getLongitude() + " d=" + geo.getRadius() + "} distErrPct=0"); //distance in kilometers } else if (geo.getType() == Geoshape.Type.BOX && (predicate == Geo.INTERSECT || map == Mapping.DEFAULT)) { final Geoshape.Point southwest = geo.getPoint(0); final Geoshape.Point northeast = geo.getPoint(1); return (key + ":[" + southwest.getLatitude() + "," + southwest.getLongitude() + " TO " + northeast.getLatitude() + "," + northeast.getLongitude() + "]");